lib/ver/action.rb in ver-2010.02 vs lib/ver/action.rb in ver-2010.08
- old
+ new
@@ -1,43 +1,52 @@
module VER
- class Action < Struct.new(:receiver, :method, :args, :block, :last)
- 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
-
+ class Action < Struct.new(:invocation, :handler, :mode)
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
+ 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
- puts self
- pp ex, ex.backtrace
+ VER.error("Exception from %p" % [self])
+ VER.error(ex)
end
def combine(action)
- new_args = [*args, action].compact
- self.class.new(receiver, method, new_args, &block)
+ invocation = [*self.invocation, action]
+ self.class.new(invocation, handler, mode)
end
- def to_s
- receiver, method, widget, *args = last
- joined = [widget, *args.map{|arg| arg.inspect }].compact.join(' ')
+ def to_proc
+ Proc.new{|widget, *args| call(widget, *args) }
+ end
- "%s.%s(%s)" % [receiver, method, joined]
+ 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
+
+ def to_a
+ [mode, self]
+ end
+ end
+
+ class Fallback < Action
end
end