Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Making gem working with 1.9.2

  • Loading branch information...
commit a092f9a502d86e687aecbf3da3ec9ad8254eed52 1 parent 1f40a7c
Krzysztof Sakwerda authored
View
2  Rakefile
@@ -1,3 +1,5 @@
+require 'yaml'
+
require 'rubygems'
require 'rake'
View
30 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)
View
12 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)
View
4 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 :-)
Please sign in to comment.
Something went wrong with that request. Please try again.