Class: SmartfoxJruby::SfsWorker::Processor

Inherits:
Object
  • Object
show all
Defined in:
lib/smartfox_jruby/sfs_worker.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#blocksObject

Returns the value of attribute blocks.



11
12
13
# File 'lib/smartfox_jruby/sfs_worker.rb', line 11

def blocks
  @blocks
end

#chainedObject

Returns the value of attribute chained.



9
10
11
# File 'lib/smartfox_jruby/sfs_worker.rb', line 9

def chained
  @chained
end

#currentObject

Returns the value of attribute current.



10
11
12
# File 'lib/smartfox_jruby/sfs_worker.rb', line 10

def current
  @current
end

#nameObject

Returns the value of attribute name.



8
9
10
# File 'lib/smartfox_jruby/sfs_worker.rb', line 8

def name
  @name
end

#optsObject

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

Returns:

  • (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


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

Returns:

  • (Boolean)


45
46
47
# File 'lib/smartfox_jruby/sfs_worker.rb', line 45

def mandatory?
  @opts[:mandatory].nil? || @opts[:mandatory]
end

#to_sObject



58
59
60
# File 'lib/smartfox_jruby/sfs_worker.rb', line 58

def to_s
  "Proc[#{current.try(:name)}] --> #{current.try(:chained)}"
end