Class: Golem::Model::Callback

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

Direct Known Subclasses

Condition

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(callback, options = {}) ⇒ Callback

Returns a new instance of Callback.



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

def initialize(callback, options = {})
  @callback = callback
end

Instance Attribute Details

#callbackObject

Returns the value of attribute callback.



4
5
6
# File 'lib/golem/model/callback.rb', line 4

def callback
  @callback
end

Instance Method Details

#call(obj, *args) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/golem/model/callback.rb', line 10

def call(obj, *args)
  case @callback
  when Proc
    if @callback.arity.abs > 1
      @callback.call(obj, *args)
    else
      @callback.call(obj)
    end
  else
    if obj.method(@callback).arity.abs > 0
      obj.send(@callback, *args)
    else
      obj.send(@callback)
    end
  end
end

#to_sObject



27
28
29
# File 'lib/golem/model/callback.rb', line 27

def to_s
  "#{@callback.inspect}"
end