Class: Basket::Base
- Includes:
- FileUtils, HasLogger
- Defined in:
- lib/basket.rb
Constant Summary collapse
- INBOX =
"inbox"
- PENDING =
"pending"
- ARCHIVE =
"archive"
Instance Attribute Summary collapse
-
#inbox ⇒ Object
Returns the value of attribute inbox.
-
#other ⇒ Object
Returns the value of attribute other.
-
#pending ⇒ Object
Returns the value of attribute pending.
-
#root ⇒ Object
Returns the value of attribute root.
Instance Method Summary collapse
-
#initialize(root, opts = {}) ⇒ Base
constructor
A new instance of Base.
- #process(&block) ⇒ Object
Methods included from HasLogger
Constructor Details
#initialize(root, opts = {}) ⇒ Base
Returns a new instance of Base.
59 60 61 62 63 64 65 66 67 |
# File 'lib/basket.rb', line 59 def initialize(root, opts={}) @root = root @inbox = opts.delete(:inbox) || INBOX @pending = opts.delete(:pending) || PENDING @archive = opts.delete(:archive) || ARCHIVE @other = opts.delete(:other) || [] @logdev = opts.delete(:logdev) || "/dev/null" @opts = opts end |
Instance Attribute Details
#inbox ⇒ Object
Returns the value of attribute inbox.
52 53 54 |
# File 'lib/basket.rb', line 52 def inbox @inbox end |
#other ⇒ Object
Returns the value of attribute other.
54 55 56 |
# File 'lib/basket.rb', line 54 def other @other end |
#pending ⇒ Object
Returns the value of attribute pending.
53 54 55 |
# File 'lib/basket.rb', line 53 def pending @pending end |
Instance Method Details
#process(&block) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/basket.rb', line 69 def process(&block) create_directories files = Dir[@root/@inbox/"*"] logger.debug(["#{files.size} files in", @root/@inbox/"*"]) send_args = @opts[:workers] ? [:forkoff!, {:processes => @opts[:workers]}] : [:each] i = 0 files.send(*send_args) do |file| pending_file = @root/@pending/File.basename(file) logger.info [:mv, file, pending_file] mv file, pending_file to_mix = mixin pending_file. { include to_mix } result = block.arity > 1 ? block.call(pending_file, i) : block.call(pending_file) if @opts[:conditional] destination = result ? @root/"success" : @root/"fail" logger.info [:mv, pending_file, destination] mv pending_file, destination elsif @other.size > 0 # don't mv anything else logger.info [:mv, pending_file, @root/@archive] mv pending_file, @root/@archive end i += 1 end end |