instiki/vendor/rails/activemodel/lib/active_model/state_machine/state.rb
Jacques Distler 4e14ccc74d Instiki 0.16.3: Rails 2.3.0
Instiki now runs on the Rails 2.3.0 Candidate Release.
Among other improvements, this means that it now 
automagically selects between WEBrick and Mongrel.

Just run

    ./instiki --daemon
2009-02-04 14:26:08 -06:00

48 lines
1,008 B
Ruby

module ActiveModel
module StateMachine
class State
attr_reader :name, :options
def initialize(name, options = {})
@name = name
if machine = options.delete(:machine)
machine.klass.define_state_query_method(name)
end
update(options)
end
def ==(state)
if state.is_a? Symbol
name == state
else
name == state.name
end
end
def call_action(action, record)
action = @options[action]
case action
when Symbol, String
record.send(action)
when Proc
action.call(record)
end
end
def display_name
@display_name ||= name.to_s.gsub(/_/, ' ').capitalize
end
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