Class: Statesman::Callback

Inherits:
Object
  • Object
show all
Defined in:
lib/statesman/callback.rb

Direct Known Subclasses

Guard

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = { from: nil, to: nil, callback: nil }) ⇒ Callback

Returns a new instance of Callback.



9
10
11
12
13
14
15
16
17
# File 'lib/statesman/callback.rb', line 9

def initialize(options = { from: nil, to: nil, callback: nil })
  unless options[:callback].respond_to?(:call)
    raise InvalidCallbackError, "No callback passed"
  end

  @from     = options[:from]
  @to       = Array(options[:to])
  @callback = options[:callback]
end

Instance Attribute Details

#callbackObject (readonly)

Returns the value of attribute callback.



7
8
9
# File 'lib/statesman/callback.rb', line 7

def callback
  @callback
end

#fromObject (readonly)

Returns the value of attribute from.



5
6
7
# File 'lib/statesman/callback.rb', line 5

def from
  @from
end

#toObject (readonly)

Returns the value of attribute to.



6
7
8
# File 'lib/statesman/callback.rb', line 6

def to
  @to
end

Instance Method Details

#applies_to?(options = { from: nil, to: nil }) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/statesman/callback.rb', line 23

def applies_to?(options = { from: nil, to: nil })
  matches(options[:from], options[:to])
end

#call(*args) ⇒ Object



19
20
21
# File 'lib/statesman/callback.rb', line 19

def call(*args)
  callback.call(*args)
end