Sha256: 1a79c9db2beb6f8bb74e8e0866ab6f88e9464283bfc8005ae7648998d6945e9c

Contents?: true

Size: 916 Bytes

Versions: 1

Compression:

Stored size: 916 Bytes

Contents

module StateShifter
  module Definition
    module ActiveRecordIntegrationMethods

      class ::StateShifter::Definition::StatePersistenceAttributeNotPresent < RuntimeError; end 

      def get_current_state
        raise StatePersistenceAttributeNotPresent unless self.attribute_names.include? self.class.persist_attr_name.to_s
        read_attribute self.class.persist_attr_name
      end

      def set_current_state value
        raise StatePersistenceAttributeNotPresent unless self.attribute_names.include? self.class.persist_attr_name.to_s
        update_attribute self.class.persist_attr_name, value
      end

      def write_initial_state
        raise StatePersistenceAttributeNotPresent unless self.attribute_names.include? self.class.persist_attr_name.to_s
        write_attribute self.class.persist_attr_name, self.class.state_machine_definition.initial_state.name.to_sym
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
state_shifter-0.8.0 lib/state_shifter/definition/active_record_integration_methods.rb