Sha256: 7a86c36f33314cb0e623fada0b078f522e9f95d7cdfcf6b218dcabbd38e25627

Contents?: true

Size: 1.07 KB

Versions: 4

Compression:

Stored size: 1.07 KB

Contents

module Neo4j::ActiveNode
  module Property
    extend ActiveSupport::Concern

    include ActiveAttr::Attributes
    include ActiveAttr::MassAssignment
    include ActiveAttr::TypecastedAttributes
    include ActiveAttr::AttributeDefaults
    include ActiveModel::Dirty


    def initialize(attributes={}, options={})
      super(attributes, options)
      (@changed_attributes || {}).clear
    end

    def save_properties
      @previously_changed = changes
      @changed_attributes.clear
    end


    module ClassMethods

      def property(name, options={})
        # Magic properties
        options[:type] = DateTime if name.to_sym == :created_at || name.to_sym == :updated_at
        attribute(name, options)
      end

      def attribute!(name, options={})
        super(name, options)
        define_method("#{name}=") do |value|
          typecast_value = typecast_attribute(typecaster_for(self.class._attribute_type(name)), value)
          send("#{name}_will_change!") unless typecast_value == read_attribute(name)
          super(value)
        end
      end

    end
  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
neo4j-3.0.0.alpha.6 lib/neo4j/active_node/property.rb
neo4j-3.0.0.alpha.5 lib/neo4j/active_node/property.rb
neo4j-3.0.0.alpha.4 lib/neo4j/active_node/property.rb
neo4j-3.0.0.alpha.3 lib/neo4j/active_node/property.rb