Skip to content

Commit

Permalink
Remove create and inline code.
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrmurach committed Jul 12, 2015
1 parent c022703 commit 8bede45
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 36 deletions.
36 changes: 7 additions & 29 deletions lib/finite_machine/transition.rb
Expand Up @@ -28,9 +28,16 @@ class Transition

# Initialize a Transition
#
# @example
# attributes = {parsed_states: {green: :yellow}, silent: true}
# Transition.new(machine, attrbiutes)
#
# @param [StateMachine] machine
#
# @param [Hash] attrs
#
# @return [Transition]
#
# @api public
def initialize(machine, attrs = {})
@machine = machine
Expand All @@ -52,25 +59,6 @@ def cancelled?
@cancelled
end

# Create transition with associated helper methods
#
# @param [FiniteMachine::StateMachine] machine
#
# @param [Hash] attrs
#
# @example
# attributes = {parsed_states: {green: :yellow}, silent: true}
# Transition.create(machine, attrbiutes)
#
# @return [Transition]
#
# @api public
def self.create(machine, attrs = {})
transition = new(machine, attrs)
transition.update_transitions
transition
end

# Decide :to state from available transitions for this event
#
# @return [Symbol]
Expand Down Expand Up @@ -147,16 +135,6 @@ def transition_choice?
end
end

# Add transition to the machine
#
# @return [Transition]
#
# @api private
def update_transitions
machine.transitions.import(name, states)
self
end

# Find latest from state
#
# Note that for the exit hook the call hasn't happened yet so
Expand Down
14 changes: 7 additions & 7 deletions lib/finite_machine/transition_builder.rb
Expand Up @@ -49,16 +49,16 @@ def initialize(machine, attributes = {})
def call(states)
StateParser.new(states).parse do |from, to|
attributes.merge!(parsed_states: { from => to })
transition = Transition.create(machine, attributes)
name = transition.name
transition = Transition.new(machine, attributes)
name = attributes[:name]

if machine.events_chain.exists?(name)
machine.events_chain.add(name, transition)
else
machine.events_chain.add(name, transition)
machine.events_chain.add(name, transition)
machine.transitions.import(name, { from => to })

unless machine.respond_to?(name)
event_definition.apply(name)
end
state_definition.apply({from => to})
state_definition.apply({ from => to })

transition
end
Expand Down

0 comments on commit 8bede45

Please sign in to comment.