Module: Neo4j::Shared::Property::ClassMethods
- Extended by:
- Forwardable
- Defined in:
- lib/neo4j/shared/property.rb
Constant Summary collapse
- VALID_PROPERTY_OPTIONS =
%w(type default index constraint serializer typecaster).map(&:to_sym)
Instance Method Summary collapse
-
#attributes_nil_hash ⇒ Hash
an extra call to a slow dependency method.
- #build_property(name, options) ⇒ Object
- #declared_properties ⇒ Object
- #extract_association_attributes!(props) ⇒ Object
- #inherit_property(name, attr_def, options = {}) ⇒ Object
-
#property(name, options = {}) ⇒ Object
Defines a property on the class.
- #undef_property(name) ⇒ Object
Instance Method Details
#attributes_nil_hash ⇒ Hash
an extra call to a slow dependency method.
200 201 202 |
# File 'lib/neo4j/shared/property.rb', line 200 def attributes_nil_hash declared_properties.attributes_nil_hash end |
#build_property(name, options) ⇒ Object
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/neo4j/shared/property.rb', line 172 def build_property(name, ) decl_prop = DeclaredProperty.new(name, ).tap do |prop| prop.register declared_properties.register(prop) yield name constraint_or_index(name, ) end # If this class has already been inherited, make sure subclasses inherit property subclasses.each do |klass| klass.inherit_property name, decl_prop.clone, declared_properties[name]. end decl_prop end |
#declared_properties ⇒ Object
194 195 196 |
# File 'lib/neo4j/shared/property.rb', line 194 def declared_properties @_declared_properties ||= DeclaredProperties.new(self) end |
#extract_association_attributes!(props) ⇒ Object
204 205 206 |
# File 'lib/neo4j/shared/property.rb', line 204 def extract_association_attributes!(props) props end |
#inherit_property(name, attr_def, options = {}) ⇒ Object
166 167 168 169 170 |
# File 'lib/neo4j/shared/property.rb', line 166 def inherit_property(name, attr_def, = {}) build_property(name, ) 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.
155 156 157 158 159 160 161 |
# File 'lib/neo4j/shared/property.rb', line 155 def property(name, = {}) invalid_option_keys = .keys.map(&:to_sym) - VALID_PROPERTY_OPTIONS fail ArgumentError, "Invalid options for property `#{name}` on `#{self.name}`: #{invalid_option_keys.join(', ')}" if invalid_option_keys.any? build_property(name, ) do |prop| attribute(prop) end end |
#undef_property(name) ⇒ Object
188 189 190 191 192 |
# File 'lib/neo4j/shared/property.rb', line 188 def undef_property(name) undef_constraint_or_index(name) declared_properties.unregister(name) attribute_methods(name).each { |method| undef_method(method) } end |