Class: VER::Action

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(receiver = nil, method = nil, args = [], &block) ⇒ Action

Returns a new instance of Action.



3
4
5
6
7
8
9
# File 'lib/ver/action.rb', line 3

def initialize(receiver = nil, method = nil, args = [], &block)
  self.receiver = receiver
  self.method = method || :call
  self.args = args
  self.block = block
  self.last = [self.receiver, self.method, self.args]
end

Instance Attribute Details

#argsObject

Returns the value of attribute args

Returns:

  • (Object)

    the current value of args



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

def args
  @args
end

#blockObject

Returns the value of attribute block

Returns:

  • (Object)

    the current value of block



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

def block
  @block
end

#lastObject

Returns the value of attribute last

Returns:

  • (Object)

    the current value of last



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

def last
  @last
end

#methodObject

Returns the value of attribute method

Returns:

  • (Object)

    the current value of method



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

def method
  @method
end

#receiverObject

Returns the value of attribute receiver

Returns:

  • (Object)

    the current value of receiver



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

def receiver
  @receiver
end

Instance Method Details

#call(widget, *given_args) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/ver/action.rb', line 11

def call(widget, *given_args)
  args = [*self.args, *given_args]

  if receiver = self.receiver
    self.last = [receiver, method, widget.tk_pathname, args]
    receiver.send(method, widget, *args)
  elsif receiver = widget
    if widget.respond_to?(:event)
      self.last = [widget.tk_pathname, method, widget.event, args]
      widget.send(method, widget.event, *args)
    else
      self.last = [widget.tk_pathname, method, widget, args]
      widget.send(method, widget, *args)
    end
  end
rescue => ex
  puts self
  pp ex, ex.backtrace
end

#combine(action) ⇒ Object



31
32
33
34
# File 'lib/ver/action.rb', line 31

def combine(action)
  new_args = [*args, action].compact
  self.class.new(receiver, method, new_args, &block)
end

#to_sObject



36
37
38
39
40
41
# File 'lib/ver/action.rb', line 36

def to_s
  receiver, method, widget, *args = last
  joined = [widget, *args.map{|arg| arg.inspect }].compact.join(' ')

  "%s.%s(%s)" % [receiver, method, joined]
end