Skip to content

Commit

Permalink
Enables the transition statement to take a hash with multiple start_s…
Browse files Browse the repository at this point in the history
…tate=>end_state pairs. Fixed small typo reg a switched singular/plural case.
  • Loading branch information
Spiralis authored and bryanlarsen committed Jul 8, 2011
1 parent 831dac5 commit acac70c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
7 changes: 4 additions & 3 deletions hobo/lib/hobo/model/lifecycles.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,10 @@ def create(name, options={}, &block)
end

def transition(name, change, options={}, &block)
@lifecycle.def_transition(name,
Array(change.keys.first), change.values.first,
block, options)
change.each do |k,v|
h = {k=>v}
@lifecycle.def_transition(name, Array(h.keys.first), h.values.first, block, options)
end
end

def invariant(&block)
Expand Down
4 changes: 2 additions & 2 deletions hobo/lib/hobo/model/lifecycles/lifecycle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def self.can_#{name}?(user, attributes=nil)
Creator.new(self, name.to_s, on_create, options)
end

def self.def_transition(name, start_state, end_states, on_transition, options)
def self.def_transition(name, start_states, end_state, on_transition, options)
class_eval %{
def #{name}!(user, attributes=nil)
transition(:#{name}, user, attributes)
Expand All @@ -50,7 +50,7 @@ def can_#{name}?(user, attributes=nil)
can_transition?(:#{name}, user)
end
}
Transition.new(self, name.to_s, start_state, end_states, on_transition, options)
Transition.new(self, name.to_s, start_states, end_state, on_transition, options)
end

def self.state_names
Expand Down

0 comments on commit acac70c

Please sign in to comment.