From a092f9a502d86e687aecbf3da3ec9ad8254eed52 Mon Sep 17 00:00:00 2001 From: Krzysztof Sakwerda Date: Mon, 24 Oct 2011 12:32:13 +0200 Subject: [PATCH] Making gem working with 1.9.2 --- Rakefile | 2 ++ lib/fsm/builder.rb | 30 ++++++++++++++++++------------ lib/fsm/executable.rb | 12 ++++++------ test/test_helper_ar.rb | 4 ++-- 4 files changed, 28 insertions(+), 20 deletions(-) diff --git a/Rakefile b/Rakefile index a631494..e634792 100644 --- a/Rakefile +++ b/Rakefile @@ -1,3 +1,5 @@ +require 'yaml' + require 'rubygems' require 'rake' diff --git a/lib/fsm/builder.rb b/lib/fsm/builder.rb index f80315f..14902ff 100644 --- a/lib/fsm/builder.rb +++ b/lib/fsm/builder.rb @@ -1,18 +1,24 @@ module FSM # Builder exposes 'only' (well there are some other methods exposed) the methods that are required to build the configuration class Builder - + # Blank Slate - instance_methods.each do |m| - undef_method m unless m == '__send__' || m == '__id__' || m == 'instance_eval' + if RUBY_VERSION < "1.9" + instance_methods.each do |m| + undef_method m unless m == "object_id" || m == "__send__" || m == "__id__" || m == "instance_eval" + end + else + instance_methods.each do |m| + undef_method m unless m == :object_id || m == :__send__ || m == :__id__ || m == :instance_eval + end end - + # Create a new Builder which creates a Machine for the target_class def initialize(target_class) @target_class = target_class @machine = Machine.new(target_class) end - + def process(&block) raise ArgumentError.new('Block expected') unless block_given? self.instance_eval(&block) @@ -20,37 +26,37 @@ def process(&block) @machine.build_state_check_methods @machine end - + private # Add a transition - # * name of the transition + # * name of the transition # * from_name: name of the source state (symbol) # * to_name: name of the target state (symbol) # * options - # + # def transition(name, from_names, to_name, options = {}) Array(from_names).each do |from_name| @machine.transition(name, from_name, to_name, options) end nil # do not expose FSM details end - + def state_attribute(name) raise ArgumentError.new('Invalid attribute name') if name == nil @machine.current_state_attribute_name = name nil # do not expose FSM details end - + def initial(name) @machine.initial_state_name = name nil # do not expose FSM details end - + def state(name, options = {}) @machine.state(name, options) nil # do not expose FSM details end - + def states(*names) names.each do |name| state(name) diff --git a/lib/fsm/executable.rb b/lib/fsm/executable.rb index 9940e12..863265a 100644 --- a/lib/fsm/executable.rb +++ b/lib/fsm/executable.rb @@ -1,28 +1,28 @@ module FSM # # Execute an action specified by either String, Sylbol or Proc. - # Symbol and String represent methods which are called on the target object, Proc will get executed + # Symbol and String represent methods which are called on the target object, Proc will get executed # and receives at least the target as parameter. If others parameters are passed then they'll get forwarded as well. class Executable # Create a new Executable - # if args is true, then arguments are passed on to the target method or the Proc, if false nothing + # if args is true, then arguments are passed on to the target method or the Proc, if false nothing # will get passed def initialize(thing) raise ArgumentError.new("Unknown thing #{thing}") unless thing @thing = thing end - + # execute this executable on the given target def execute(target, *args) case @thing - when String, Symbol: + when String, Symbol if (args.length > 0) target.send(@thing, *args) else target.send(@thing) end - when Proc: - if (args.length > 0) + when Proc + if (args.length > 0) @thing.call(target, *args) else @thing.call(target) diff --git a/test/test_helper_ar.rb b/test/test_helper_ar.rb index f045631..34f790f 100644 --- a/test/test_helper_ar.rb +++ b/test/test_helper_ar.rb @@ -27,5 +27,5 @@ class Order < ActiveRecord::Base end end -ActiveRecord::Base.logger = Logger.new(STDOUT) -ActiveRecord::Base.logger.level = Logger::DEBUG # change to DEBUG if you want to see something :-) +# ActiveRecord::Base.logger = Logger.new(STDOUT) +# ActiveRecord::Base.logger.level = Logger::DEBUG # change to DEBUG if you want to see something :-)