diff options
author | Hongli Lai (Phusion) <hongli@phusion.nl> | 2008-12-03 19:30:35 +0100 |
---|---|---|
committer | Hongli Lai (Phusion) <hongli@phusion.nl> | 2008-12-03 19:30:35 +0100 |
commit | ccb96f2297e8783165cba764e9b5d51e1a15ff87 (patch) | |
tree | 3229e6fdddc42054615514d843c555e341003033 /activemodel/lib/active_model/state_machine.rb | |
parent | fb2325e35855d62abd2c76ce03feaa3ca7992e4f (diff) | |
parent | 761a633a9c0a45d76ef3ed10da97e3696c3ded79 (diff) | |
download | rails-ccb96f2297e8783165cba764e9b5d51e1a15ff87.tar.gz rails-ccb96f2297e8783165cba764e9b5d51e1a15ff87.tar.bz2 rails-ccb96f2297e8783165cba764e9b5d51e1a15ff87.zip |
Merge commit 'origin/master' into savepoints
Conflicts:
activerecord/lib/active_record/fixtures.rb
activerecord/test/cases/defaults_test.rb
Diffstat (limited to 'activemodel/lib/active_model/state_machine.rb')
-rw-r--r-- | activemodel/lib/active_model/state_machine.rb | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/activemodel/lib/active_model/state_machine.rb b/activemodel/lib/active_model/state_machine.rb index 96df6539ae..bce90fd743 100644 --- a/activemodel/lib/active_model/state_machine.rb +++ b/activemodel/lib/active_model/state_machine.rb @@ -1,14 +1,10 @@ -Dir[File.dirname(__FILE__) + "/state_machine/*.rb"].sort.each do |path| - filename = File.basename(path) - require "active_model/state_machine/#{filename}" -end - module ActiveModel module StateMachine class InvalidTransition < Exception end def self.included(base) + require 'active_model/state_machine/machine' base.extend ClassMethods end @@ -35,6 +31,12 @@ module ActiveModel state_machines[name] ||= Machine.new(self, name) block ? state_machines[name].update(options, &block) : state_machines[name] end + + def define_state_query_method(state_name) + name = "#{state_name}?" + undef_method(name) if method_defined?(name) + class_eval "def #{name}; current_state.to_s == %(#{state_name}) end" + end end def current_state(name = nil, new_state = nil, persist = false) @@ -63,4 +65,4 @@ module ActiveModel end end end -end
\ No newline at end of file +end |