lib/transitions/machine.rb in transitions-0.0.10 vs lib/transitions/machine.rb in transitions-0.0.11

- old
+ new

@@ -36,10 +36,11 @@ end def update(options = {}, &block) @initial_state = options[:initial] if options.key?(:initial) instance_eval(&block) if block + include_scopes if defined?(ActiveRecord::Base) && @klass < ActiveRecord::Base self end def fire_event(event, record, persist, *args) state_index[record.current_state(@name)].call_action(:exit, record) @@ -89,9 +90,15 @@ @event_fired_callback ||= (@name == :default ? '' : "#{@name}_") + 'event_fired' end def event_failed_callback @event_failed_callback ||= (@name == :default ? '' : "#{@name}_") + 'event_failed' + end + + def include_scopes + @states.each do |state| + @klass.scope state.name.to_sym, @klass.where(:state => state.name.to_s) + end end end end