diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2008-12-07 03:05:03 +0100 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2008-12-07 03:05:03 +0100 |
commit | 8f1c229571b4db8dda144bf6eaa193799309e817 (patch) | |
tree | 592710207a614428d5cb809f6e13c8b546b58969 /activemodel/lib | |
parent | 601e40e744f44fe8819be100a8c472ea161d13ab (diff) | |
parent | 9eca588bdfbb41f6b48477025d1cd8eea4a38296 (diff) | |
download | rails-8f1c229571b4db8dda144bf6eaa193799309e817.tar.gz rails-8f1c229571b4db8dda144bf6eaa193799309e817.tar.bz2 rails-8f1c229571b4db8dda144bf6eaa193799309e817.zip |
Merge commit 'mainstream/master'
Conflicts:
actionmailer/lib/action_mailer/base.rb
actionpack/lib/action_controller/base.rb
actionpack/lib/action_controller/mime_type.rb
railties/doc/guides/html/activerecord_validations_callbacks.html
railties/doc/guides/html/caching_with_rails.html
railties/doc/guides/html/command_line.html
railties/doc/guides/html/configuring.html
railties/doc/guides/html/creating_plugins.html
railties/doc/guides/html/finders.html
railties/doc/guides/html/routing_outside_in.html
railties/doc/guides/source/activerecord_validations_callbacks.txt
railties/doc/guides/source/caching_with_rails.txt
railties/doc/guides/source/command_line.txt
railties/doc/guides/source/creating_plugins/acts_as_yaffle.txt
railties/doc/guides/source/creating_plugins/controllers.txt
railties/doc/guides/source/creating_plugins/core_ext.txt
railties/doc/guides/source/creating_plugins/helpers.txt
railties/doc/guides/source/creating_plugins/index.txt
railties/doc/guides/source/creating_plugins/migration_generator.txt
railties/doc/guides/source/creating_plugins/models.txt
railties/doc/guides/source/creating_plugins/odds_and_ends.txt
railties/doc/guides/source/creating_plugins/routes.txt
railties/doc/guides/source/finders.txt
railties/doc/guides/source/routing_outside_in.txt
railties/doc/guides/source/testing_rails_applications.txt
Diffstat (limited to 'activemodel/lib')
4 files changed, 18 insertions, 13 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 diff --git a/activemodel/lib/active_model/state_machine/event.rb b/activemodel/lib/active_model/state_machine/event.rb index 8acde7fd47..3eb656b6d6 100644 --- a/activemodel/lib/active_model/state_machine/event.rb +++ b/activemodel/lib/active_model/state_machine/event.rb @@ -1,3 +1,5 @@ +require 'active_model/state_machine/state_transition' + module ActiveModel module StateMachine class Event diff --git a/activemodel/lib/active_model/state_machine/machine.rb b/activemodel/lib/active_model/state_machine/machine.rb index 170505c0b2..a5ede021b1 100644 --- a/activemodel/lib/active_model/state_machine/machine.rb +++ b/activemodel/lib/active_model/state_machine/machine.rb @@ -1,7 +1,11 @@ +require 'active_model/state_machine/state' +require 'active_model/state_machine/event' + module ActiveModel module StateMachine class Machine - attr_accessor :initial_state, :states, :events, :state_index + attr_writer :initial_state + attr_accessor :states, :events, :state_index attr_reader :klass, :name def initialize(klass, name, options = {}, &block) @@ -71,4 +75,4 @@ module ActiveModel end end end -end
\ No newline at end of file +end diff --git a/activemodel/lib/active_model/state_machine/state.rb b/activemodel/lib/active_model/state_machine/state.rb index 68eb2aa34a..76916b1d86 100644 --- a/activemodel/lib/active_model/state_machine/state.rb +++ b/activemodel/lib/active_model/state_machine/state.rb @@ -5,11 +5,8 @@ module ActiveModel def initialize(name, options = {}) @name = name - machine = options.delete(:machine) - if machine - machine.klass.send(:define_method, "#{name}?") do - current_state.to_s == name.to_s - end + if machine = options.delete(:machine) + machine.klass.define_state_query_method(name) end update(options) end |