Class: VER::Action

Inherits:
Struct
  • Object
show all
Defined in:
lib/ver/action.rb

Direct Known Subclasses

Fallback

Constant Summary

Constants inherited from Struct

Struct::CACHE

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Struct

new

Instance Attribute Details

#handlerObject

Returns the value of attribute handler

Returns:

  • (Object)

    the current value of handler



2
3
4
# File 'lib/ver/action.rb', line 2

def handler
  @handler
end

#invocationObject

Returns the value of attribute invocation

Returns:

  • (Object)

    the current value of invocation



2
3
4
# File 'lib/ver/action.rb', line 2

def invocation
  @invocation
end

#modeObject

Returns the value of attribute mode

Returns:

  • (Object)

    the current value of mode



2
3
4
# File 'lib/ver/action.rb', line 2

def mode
  @mode
end

Instance Method Details

#call(widget, *given_args) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/ver/action.rb', line 3

def call(widget, *given_args)
  case handler
  when Symbol
    widget.send(handler).send(*invocation, *given_args)
  when Module
    method, *args = *invocation
    handler.send(method, widget, *args, *given_args)
  when nil
    widget.send(*invocation, *given_args)
  else
    raise ArgumentError
  end
rescue => ex
  VER.error("Exception from %p" % [self])
  VER.error(ex)
end

#combine(action) ⇒ Object



20
21
22
23
# File 'lib/ver/action.rb', line 20

def combine(action)
  invocation = [*self.invocation, action]
  self.class.new(invocation, handler, mode)
end

#to_aObject



45
46
47
# File 'lib/ver/action.rb', line 45

def to_a
  [mode, self]
end

#to_method(widget) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/ver/action.rb', line 29

def to_method(widget)
  case handler
  when Symbol
    method = [*invocation].first
    widget.send(handler).method(method)
  when Module
    method, *args = *invocation
    handler.method(method)
  when nil
    method = [*invocation].first
    widget.method(method)
  else
    raise ArgumentError
  end
end

#to_procObject



25
26
27
# File 'lib/ver/action.rb', line 25

def to_proc
  Proc.new{|widget, *args| call(widget, *args) }
end