Module: AlterEgo::MongoidAdapter
- Defined in:
- lib/alter_ego/mongoid_adapter.rb
Class Method Summary collapse
Instance Method Summary collapse
- #state ⇒ Object
-
#state=(identifier) ⇒ Object
Override methods from AlterEgo to store state in @attributes instead of @state.
Class Method Details
.included(klass) ⇒ Object
4 5 6 7 8 9 |
# File 'lib/alter_ego/mongoid_adapter.rb', line 4 def self.included klass klass.field :state klass.after_initialize do |r| r.state = r.state end end |
Instance Method Details
#state ⇒ Object
23 24 25 26 27 28 |
# File 'lib/alter_ego/mongoid_adapter.rb', line 23 def state result = self[:state] || self.class.default_state result = result.to_sym unless result.nil? assert(result.nil? || self.class.states.keys.include?(result)) result end |
#state=(identifier) ⇒ Object
Override methods from AlterEgo to store state in @attributes instead of @state
18 19 20 21 |
# File 'lib/alter_ego/mongoid_adapter.rb', line 18 def state=(identifier) # state needs to always be stored as a string - symbol serialization is strange self[:state] = identifier.to_s unless identifier.nil? end |