lib/state_machine/branch.rb in state_machine-1.1.2 vs lib/state_machine/branch.rb in state_machine-1.2.0

- old
+ new

@@ -138,14 +138,12 @@ # * +first_gear+ -> +parked+ # * +backing_up+ -> +parked+ # # Each edge will be labeled with the name of the event that would cause the # transition. - # - # The collection of edges generated on the graph will be returned. def draw(graph, event, valid_states) - state_requirements.inject([]) do |edges, state_requirement| + state_requirements.each do |state_requirement| # From states determined based on the known valid states from_states = state_requirement[:from].filter(valid_states) # If a to state is not specified, then it's a loopback and each from # state maps back to itself @@ -158,27 +156,30 @@ end # Generate an edge between each from and to state from_states.each do |from_state| from_state = from_state ? from_state.to_s : 'nil' - edges << graph.add_edge(from_state, loopback ? from_state : to_state, :label => event.to_s) + graph.add_edges(from_state, loopback ? from_state : to_state, :label => event.to_s) end - - edges end + + true end protected # Builds a matcher strategy to use for the given options. If neither a # whitelist nor a blacklist option is specified, then an AllMatcher is # built. def build_matcher(options, whitelist_option, blacklist_option) assert_exclusive_keys(options, whitelist_option, blacklist_option) if options.include?(whitelist_option) - WhitelistMatcher.new(options[whitelist_option]) + value = options[whitelist_option] + value.is_a?(Matcher) ? value : WhitelistMatcher.new(options[whitelist_option]) elsif options.include?(blacklist_option) - BlacklistMatcher.new(options[blacklist_option]) + value = options[blacklist_option] + raise ArgumentError, ":#{blacklist_option} option cannot use matchers; use :#{whitelist_option} instead" if value.is_a?(Matcher) + BlacklistMatcher.new(value) else AllMatcher.instance end end