module Neo4j::Shared::Property::ClassMethods
Public Instance Methods
attributes_nil_hash()
click to toggle source
@return [Hash] A frozen hash of all model properties with nil values. It is used during node loading and prevents an extra call to a slow dependency method.
# File lib/neo4j/shared/property.rb 180 def attributes_nil_hash 181 declared_properties.attributes_nil_hash 182 end
build_property(name, options) { |name| ... }
click to toggle source
# File lib/neo4j/shared/property.rb 159 def build_property(name, options) 160 DeclaredProperty.new(name, options).tap do |prop| 161 prop.register 162 declared_properties.register(prop) 163 yield name 164 constraint_or_index(name, options) 165 end 166 end
declared_properties()
click to toggle source
# File lib/neo4j/shared/property.rb 174 def declared_properties 175 @_declared_properties ||= DeclaredProperties.new(self) 176 end
extract_association_attributes!(props)
click to toggle source
# File lib/neo4j/shared/property.rb 184 def extract_association_attributes!(props) 185 props 186 end
inherit_property(name, attr_def, options = {})
click to toggle source
@param [Symbol] name The property name @param [Neo4j::Shared::AttributeDefinition] attr_def A cloned AttributeDefinition to reuse @param [Hash] options An options hash to use in the new property definition
# File lib/neo4j/shared/property.rb 153 def inherit_property(name, attr_def, options = {}) 154 build_property(name, options) do |prop_name| 155 attributes[prop_name] = attr_def 156 end 157 end
property(name, options = {})
click to toggle source
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.
@example Without type
class Person # declare a property which can have any value property :name end
@example With type and a default value
class Person # declare a property which can have any value property :score, type: Integer, default: 0 end
@example With an index
class Person # declare a property which can have any value property :name, index: :exact end
@example With a constraint
class Person # declare a property which can have any value property :name, constraint: :unique end
# File lib/neo4j/shared/property.rb 144 def property(name, options = {}) 145 build_property(name, options) do |prop| 146 attribute(prop) 147 end 148 end
undef_property(name)
click to toggle source
# File lib/neo4j/shared/property.rb 168 def undef_property(name) 169 undef_constraint_or_index(name) 170 declared_properties.unregister(name) 171 attribute_methods(name).each { |method| undef_method(method) } 172 end
Private Instance Methods
attribute!(name)
click to toggle source
Calls superclass method
# File lib/neo4j/shared/property.rb 190 def attribute!(name) 191 remove_instance_variable('@attribute_methods_generated') if instance_variable_defined?('@attribute_methods_generated') 192 define_attribute_methods([name]) unless attribute_names.include?(name) 193 attributes[name.to_s] = declared_properties[name] 194 define_method("#{name}=") do |value| 195 typecast_value = typecast_attribute(_attribute_typecaster(name), value) 196 send("#{name}_will_change!") unless typecast_value == read_attribute(name) 197 super(value) 198 end 199 end
constraint_or_index(name, options)
click to toggle source
# File lib/neo4j/shared/property.rb 201 def constraint_or_index(name, options) 202 # either constraint or index, do not set both 203 if options[:constraint] 204 fail "unknown constraint type #{options[:constraint]}, only :unique supported" if options[:constraint] != :unique 205 constraint(name, type: :unique) 206 elsif options[:index] 207 fail "unknown index type #{options[:index]}, only :exact supported" if options[:index] != :exact 208 index(name) if options[:index] == :exact 209 end 210 end
undef_constraint_or_index(name)
click to toggle source
# File lib/neo4j/shared/property.rb 212 def undef_constraint_or_index(name) 213 prop = declared_properties[name] 214 return unless prop.index_or_constraint? 215 type = prop.constraint? ? :constraint : :index 216 send(:"drop_#{type}", name) 217 end