aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/lib/active_model/state_machine/state.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activemodel/lib/active_model/state_machine/state.rb')
-rw-r--r--activemodel/lib/active_model/state_machine/state.rb18
1 files changed, 14 insertions, 4 deletions
diff --git a/activemodel/lib/active_model/state_machine/state.rb b/activemodel/lib/active_model/state_machine/state.rb
index 5851a6fb79..68eb2aa34a 100644
--- a/activemodel/lib/active_model/state_machine/state.rb
+++ b/activemodel/lib/active_model/state_machine/state.rb
@@ -3,11 +3,15 @@ module ActiveModel
class State
attr_reader :name, :options
- def initialize(machine, name, options={})
- @machine, @name, @options, @display_name = machine, name, options, options.delete(:display)
- machine.klass.send(:define_method, "#{name}?") do
- current_state.to_s == name.to_s
+ 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
end
+ update(options)
end
def ==(state)
@@ -35,6 +39,12 @@ module ActiveModel
def for_select
[display_name, name.to_s]
end
+
+ def update(options = {})
+ if options.key?(:display) then @display_name = options.delete(:display) end
+ @options = options
+ self
+ end
end
end
end