Skip to content

Commit

Permalink
Making gem working with 1.9.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Krzysztof Sakwerda committed Oct 24, 2011
1 parent 1f40a7c commit a092f9a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 20 deletions.
2 changes: 2 additions & 0 deletions Rakefile
@@ -1,3 +1,5 @@
require 'yaml'

require 'rubygems'
require 'rake'

Expand Down
30 changes: 18 additions & 12 deletions lib/fsm/builder.rb
@@ -1,56 +1,62 @@
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)
@machine.build_transition_methods
@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)
Expand Down
12 changes: 6 additions & 6 deletions 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)
Expand Down
4 changes: 2 additions & 2 deletions test/test_helper_ar.rb
Expand Up @@ -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 :-)

0 comments on commit a092f9a

Please sign in to comment.