Sha256: 48f5e35fb9a47381697e46100ff8fe0cbaa8258be2c60e5b254dd7e9bb2d921a

Contents?: true

Size: 1.62 KB

Versions: 24

Compression:

Stored size: 1.62 KB

Contents

module Neo4j::ActiveNode::IdProperty
  # Provides get/set of the Id Property values.
  # Some methods
  module Accessor
    extend ActiveSupport::Concern

    attr_reader :default_property_value

    def default_properties=(properties)
      @default_property_value = properties[default_property_key]
    end

    def default_property(key)
      return nil unless key == default_property_key
      default_property_value
    end

    def default_property_key
      self.class.default_property_key
    end

    def default_properties
      @default_properties ||= Hash.new(nil)
    end

    module ClassMethods
      def default_property_key
        @default_property_key ||= default_properties_keys.first
      end

      # TODO: Move this to the DeclaredPropertyManager
      def default_property(name, &block)
        reset_default_properties(name) if default_properties.respond_to?(:size)
        default_properties[name] = block
      end

      # @return [Hash<Symbol,Proc>]
      def default_properties
        @default_property ||= {}
      end

      def default_properties_keys
        @default_properties_keys ||= default_properties.keys
      end

      def reset_default_properties(name_to_keep)
        default_properties.each_key do |property|
          @default_properties_keys = nil
          undef_method(property) unless property == name_to_keep
        end
        @default_properties_keys = nil
        @default_property = {}
      end

      def default_property_values(instance)
        default_properties.each_with_object({}) do |(key, block), result|
          result[key] = block.call(instance)
        end
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
neo4j-5.2.15 lib/neo4j/active_node/id_property/accessor.rb
neo4j-5.2.14 lib/neo4j/active_node/id_property/accessor.rb
neo4j-5.2.13 lib/neo4j/active_node/id_property/accessor.rb
neo4j-5.2.12 lib/neo4j/active_node/id_property/accessor.rb
neo4j-5.2.11 lib/neo4j/active_node/id_property/accessor.rb
neo4j-5.2.10 lib/neo4j/active_node/id_property/accessor.rb
neo4j-5.2.9 lib/neo4j/active_node/id_property/accessor.rb
neo4j-5.2.8 lib/neo4j/active_node/id_property/accessor.rb
neo4j-5.2.7 lib/neo4j/active_node/id_property/accessor.rb
neo4j-5.2.6 lib/neo4j/active_node/id_property/accessor.rb
neo4j-5.2.5 lib/neo4j/active_node/id_property/accessor.rb
neo4j-5.2.3 lib/neo4j/active_node/id_property/accessor.rb
neo4j-5.2.2 lib/neo4j/active_node/id_property/accessor.rb
neo4j-5.2.1 lib/neo4j/active_node/id_property/accessor.rb
neo4j-5.2.0 lib/neo4j/active_node/id_property/accessor.rb
neo4j-5.1.5 lib/neo4j/active_node/id_property/accessor.rb
neo4j-5.1.4 lib/neo4j/active_node/id_property/accessor.rb
neo4j-5.1.3 lib/neo4j/active_node/id_property/accessor.rb
neo4j-5.1.2 lib/neo4j/active_node/id_property/accessor.rb
neo4j-5.1.1 lib/neo4j/active_node/id_property/accessor.rb