Sha256: 978134fe7f332d8b9125c3c6607c6067e75e298386cea6e32c65e16045492a96

Contents?: true

Size: 1.21 KB

Versions: 81

Compression:

Stored size: 1.21 KB

Contents

module Neo4j
  # This mixin allows storage and update of undeclared properties in the included class
  module UndeclaredProperties
    extend ActiveSupport::Concern

    included do
      attr_accessor :undeclared_properties
    end

    def validate_attributes!(_)
    end

    def read_attribute(name)
      respond_to?(name) ? super(name) : read_undeclared_property(name.to_sym)
    end
    alias [] read_attribute

    def read_undeclared_property(name)
      _persisted_obj ? _persisted_obj.props[name] : (undeclared_properties && undeclared_properties[name])
    end

    def write_attribute(name, value)
      if respond_to? "#{name}="
        super(name, value)
      else
        add_undeclared_property(name, value)
      end
    end
    alias []= write_attribute

    def skip_update?
      super && undeclared_properties.blank?
    end

    def props_for_create
      super.merge(undeclared_properties!)
    end

    def props_for_update
      super.merge(undeclared_properties!)
    end

    def undeclared_properties!
      undeclared_properties || {}
    ensure
      self.undeclared_properties = nil
    end

    def add_undeclared_property(name, value)
      (self.undeclared_properties ||= {})[name] = value
    end
  end
end

Version data entries

81 entries across 81 versions & 2 rubygems

Version Path
neo4j-9.6.2 lib/neo4j/undeclared_properties.rb
activegraph-10.0.0.pre.alpha.11 lib/neo4j/undeclared_properties.rb
activegraph-10.0.0.pre.alpha.10 lib/neo4j/undeclared_properties.rb
activegraph-10.0.0.pre.alpha.9 lib/neo4j/undeclared_properties.rb
activegraph-10.0.0.pre.alpha.8 lib/neo4j/undeclared_properties.rb
activegraph-10.0.0.pre.alpha.7 lib/neo4j/undeclared_properties.rb
activegraph-10.0.0.pre.alpha.6 lib/neo4j/undeclared_properties.rb
neo4j-10.0.0.pre.alpha.5 lib/neo4j/undeclared_properties.rb
neo4j-10.0.0.pre.alpha.4 lib/neo4j/undeclared_properties.rb
neo4j-10.0.0.pre.alpha.3 lib/neo4j/undeclared_properties.rb
neo4j-10.0.0.pre.alpha.2 lib/neo4j/undeclared_properties.rb
neo4j-10.0.0.pre.alpha.1 lib/neo4j/undeclared_properties.rb
neo4j-9.6.1 lib/neo4j/undeclared_properties.rb
neo4j-9.6.0 lib/neo4j/undeclared_properties.rb
neo4j-9.5.3 lib/neo4j/undeclared_properties.rb
neo4j-9.5.2 lib/neo4j/undeclared_properties.rb
neo4j-9.5.0 lib/neo4j/undeclared_properties.rb
neo4j-9.4.0 lib/neo4j/undeclared_properties.rb
neo4j-9.3.0 lib/neo4j/undeclared_properties.rb
neo4j-9.2.4 lib/neo4j/undeclared_properties.rb