Class: SmartfoxJruby::SfsWorker::Processor
- Inherits:
-
Object
- Object
- SmartfoxJruby::SfsWorker::Processor
- Defined in:
- lib/smartfox_jruby/sfs_worker.rb
Instance Attribute Summary collapse
-
#blocks ⇒ Object
Returns the value of attribute blocks.
-
#chained ⇒ Object
Returns the value of attribute chained.
-
#current ⇒ Object
Returns the value of attribute current.
-
#name ⇒ Object
Returns the value of attribute name.
-
#opts ⇒ Object
Returns the value of attribute opts.
Instance Method Summary collapse
- #append(&block) ⇒ Object
- #chain(name, &block) ⇒ Object
- #completed? ⇒ Boolean
- #event(name, data = {}) ⇒ Object
-
#initialize(name, opts = {}, &block) ⇒ Processor
constructor
A new instance of Processor.
- #link ⇒ Object
- #mandatory? ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(name, opts = {}, &block) ⇒ Processor
Returns a new instance of Processor.
13 14 15 16 17 18 19 |
# File 'lib/smartfox_jruby/sfs_worker.rb', line 13 def initialize(name, opts = {}, &block) @blocks = [block] @name = name @current = self @chained = nil @opts = opts end |
Instance Attribute Details
#blocks ⇒ Object
Returns the value of attribute blocks.
11 12 13 |
# File 'lib/smartfox_jruby/sfs_worker.rb', line 11 def blocks @blocks end |
#chained ⇒ Object
Returns the value of attribute chained.
9 10 11 |
# File 'lib/smartfox_jruby/sfs_worker.rb', line 9 def chained @chained end |
#current ⇒ Object
Returns the value of attribute current.
10 11 12 |
# File 'lib/smartfox_jruby/sfs_worker.rb', line 10 def current @current end |
#name ⇒ Object
Returns the value of attribute name.
8 9 10 |
# File 'lib/smartfox_jruby/sfs_worker.rb', line 8 def name @name end |
#opts ⇒ Object
Returns the value of attribute opts.
7 8 9 |
# File 'lib/smartfox_jruby/sfs_worker.rb', line 7 def opts @opts end |
Instance Method Details
#append(&block) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/smartfox_jruby/sfs_worker.rb', line 32 def append(&block) unless link.blank? link.blocks << block else current.blocks << block end self end |
#chain(name, &block) ⇒ Object
21 22 23 24 |
# File 'lib/smartfox_jruby/sfs_worker.rb', line 21 def chain(name, &block) link.chained = Processor.new(name, @opts, &block) self end |
#completed? ⇒ Boolean
41 42 43 |
# File 'lib/smartfox_jruby/sfs_worker.rb', line 41 def completed? current.blank? end |
#event(name, data = {}) ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/smartfox_jruby/sfs_worker.rb', line 49 def event(name, data = {}) if @current.name.to_s == name.to_s @current.blocks.each { |b| b.call(data) } @current = (@current.chained.blank?) ? nil : @current.chained return true end false end |
#link ⇒ Object
26 27 28 29 30 |
# File 'lib/smartfox_jruby/sfs_worker.rb', line 26 def link p = current p = p.chained while (!p.try(:chained).blank?) p end |
#mandatory? ⇒ Boolean
45 46 47 |
# File 'lib/smartfox_jruby/sfs_worker.rb', line 45 def mandatory? @opts[:mandatory].nil? || @opts[:mandatory] end |
#to_s ⇒ Object
58 59 60 |
# File 'lib/smartfox_jruby/sfs_worker.rb', line 58 def to_s "Proc[#{current.try(:name)}] --> #{current.try(:chained)}" end |