Sha256: aeb33c14d3363c6497aadec6b5bed9fb43e612215270f4001dc1ee1ef64dec91

Contents?: true

Size: 684 Bytes

Versions: 7

Compression:

Stored size: 684 Bytes

Contents

module Stateflow
  module Persistence
    module MongoMapper
      def self.install(base)
        base.before_validation_on_create :ensure_initial_state
        base.send :include, InstanceMethods
      end
      
      module InstanceMethods
        def load_from_persistence
          self.send machine.state_column.to_sym
        end

        def save_to_persistence(new_state)
          self.update_attributes(machine.state_column.to_sym => new_state)
        end
        
        def ensure_initial_state
          send("#{self.machine.state_column.to_s}=", self.current_state.name.to_s) if self.send(self.machine.state_column.to_s).blank?
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
stateflow-0.2.3 lib/stateflow/persistence/mongo_mapper.rb
stateflow-0.2.2 lib/stateflow/persistence/mongo_mapper.rb
stateflow-0.2.1 lib/stateflow/persistence/mongo_mapper.rb
stateflow-0.1.2 lib/stateflow/persistence/mongo_mapper.rb
stateflow-0.1.1 lib/stateflow/persistence/mongo_mapper.rb
stateflow-0.1.0 lib/stateflow/persistence/mongo_mapper.rb
stateflow-0.0.4 lib/stateflow/persistence/mongo_mapper.rb