Module: Neo4j::Shared::Property::ClassMethods

Extended by:
Forwardable
Defined in:
lib/neo4j/shared/property.rb

Instance Method Summary collapse

Instance Method Details

#attributes_nil_hashHash

an extra call to a slow dependency method.

Returns:

  • (Hash)

    A frozen hash of all model properties with nil values. It is used during node loading and prevents



180
181
182
# File 'lib/neo4j/shared/property.rb', line 180

def attributes_nil_hash
  declared_properties.attributes_nil_hash
end

#build_property(name, options) ⇒ Object



159
160
161
162
163
164
165
166
# File 'lib/neo4j/shared/property.rb', line 159

def build_property(name, options)
  DeclaredProperty.new(name, options).tap do |prop|
    prop.register
    declared_properties.register(prop)
    yield name
    constraint_or_index(name, options)
  end
end

#declared_propertiesObject



174
175
176
# File 'lib/neo4j/shared/property.rb', line 174

def declared_properties
  @_declared_properties ||= DeclaredProperties.new(self)
end

#extract_association_attributes!(props) ⇒ Object



184
185
186
# File 'lib/neo4j/shared/property.rb', line 184

def extract_association_attributes!(props)
  props
end

#inherit_property(name, attr_def, options = {}) ⇒ Object

Parameters:

  • name (Symbol)

    The property name

  • attr_def (Neo4j::Shared::AttributeDefinition)

    A cloned AttributeDefinition to reuse

  • options (Hash) (defaults to: {})

    An options hash to use in the new property definition



153
154
155
156
157
# File 'lib/neo4j/shared/property.rb', line 153

def inherit_property(name, attr_def, options = {})
  build_property(name, options) do |prop_name|
    attributes[prop_name] = attr_def
  end
end

#property(name, options = {}) ⇒ Object

Defines a property on the class

See active_attr gem for allowed options, e.g which type Notice, in Neo4j you don’t have to declare properties before using them, see the neo4j-core api.

Examples:

Without type

class Person
  # declare a property which can have any value
  property :name
end

With type and a default value

class Person
  # declare a property which can have any value
  property :score, type: Integer, default: 0
end

With an index

class Person
  # declare a property which can have any value
  property :name, index: :exact
end

With a constraint

class Person
  # declare a property which can have any value
  property :name, constraint: :unique
end


144
145
146
147
148
# File 'lib/neo4j/shared/property.rb', line 144

def property(name, options = {})
  build_property(name, options) do |prop|
    attribute(prop)
  end
end

#undef_property(name) ⇒ Object



168
169
170
171
172
# File 'lib/neo4j/shared/property.rb', line 168

def undef_property(name)
  undef_constraint_or_index(name)
  declared_properties.unregister(name)
  attribute_methods(name).each { |method| undef_method(method) }
end