class Neo4j::Shared::DeclaredProperty
Contains methods related to the management
Constants
- ILLEGAL_PROPS
Attributes
magic_typecaster[R]
name[R]
name_string[R]
name_sym[R]
options[R]
Public Class Methods
new(name, options = {})
click to toggle source
# File lib/neo4j/shared/declared_property.rb 12 def initialize(name, options = {}) 13 fail IllegalPropertyError, "#{name} is an illegal property" if ILLEGAL_PROPS.include?(name.to_s) 14 fail TypeError, "can't convert #{name.class} into Symbol" unless name.respond_to?(:to_sym) 15 @name = @name_sym = name.to_sym 16 @name_string = name.to_s 17 @options = options 18 fail_invalid_options! 19 end
Public Instance Methods
<=>(other)
click to toggle source
Compare attribute definitions
@example
attribute_definition <=> other
@param [Neo4j::Shared::DeclaredProperty, Object] other The other
attribute definition to compare with.
@return [-1, 0, 1, nil]
# File lib/neo4j/shared/declared_property.rb 30 def <=>(other) 31 return nil unless other.instance_of? self.class 32 return nil if name == other.name && options != other.options 33 self.to_s <=> other.to_s 34 end
[](key)
click to toggle source
# File lib/neo4j/shared/declared_property.rb 50 def [](key) 51 respond_to?(key) ? public_send(key) : nil 52 end
default_value()
click to toggle source
# File lib/neo4j/shared/declared_property.rb 66 def default_value 67 options[:default] 68 end
Also aliased as: default
fail_invalid_options!()
click to toggle source
# File lib/neo4j/shared/declared_property.rb 71 def fail_invalid_options! 72 case 73 when index?(:exact) && constraint?(:unique) 74 fail Neo4j::InvalidPropertyOptionsError, 75 "#Uniqueness constraints also provide exact indexes, cannot set both options on property #{name}" 76 end 77 end
inspect()
click to toggle source
# File lib/neo4j/shared/declared_property.rb 36 def inspect 37 options_description = options.map { |key, value| "#{key.inspect} => #{value.inspect}" }.sort.join(', ') 38 inspected_options = ", #{options_description}" unless options_description.empty? 39 "attribute :#{name}#{inspected_options}" 40 end
register()
click to toggle source
# File lib/neo4j/shared/declared_property.rb 54 def register 55 register_magic_properties 56 end
to_s()
click to toggle source
# File lib/neo4j/shared/declared_property.rb 42 def to_s 43 name.to_s 44 end
to_sym()
click to toggle source
# File lib/neo4j/shared/declared_property.rb 46 def to_sym 47 name 48 end
type()
click to toggle source
# File lib/neo4j/shared/declared_property.rb 58 def type 59 options[:type] 60 end
typecaster()
click to toggle source
# File lib/neo4j/shared/declared_property.rb 62 def typecaster 63 options[:typecaster] 64 end
Private Instance Methods
option_with_value!(key, value)
click to toggle source
# File lib/neo4j/shared/declared_property.rb 81 def option_with_value!(key, value) 82 options[key] = value 83 fail_invalid_options! 84 end
option_with_value?(key, value)
click to toggle source
# File lib/neo4j/shared/declared_property.rb 86 def option_with_value?(key, value) 87 options[key] == value 88 end
register_magic_properties()
click to toggle source
Tweaks properties
# File lib/neo4j/shared/declared_property.rb 91 def register_magic_properties 92 options[:type] ||= Neo4j::Config.timestamp_type if timestamp_prop? 93 94 register_magic_typecaster 95 register_type_converter 96 end
register_magic_typecaster()
click to toggle source
# File lib/neo4j/shared/declared_property.rb 102 def register_magic_typecaster 103 found_typecaster = Neo4j::Shared::TypeConverters.typecaster_for(options[:type]) 104 return unless found_typecaster && found_typecaster.respond_to?(:primitive_type) 105 options[:typecaster] = found_typecaster 106 @magic_typecaster = options[:type] 107 options[:type] = found_typecaster.primitive_type 108 end
register_type_converter()
click to toggle source
# File lib/neo4j/shared/declared_property.rb 110 def register_type_converter 111 converter = options[:serializer] 112 return unless converter 113 options[:type] = converter.convert_type 114 options[:typecaster] = Neo4j::Shared::TypeConverters::ObjectConverter 115 Neo4j::Shared::TypeConverters.register_converter(converter) 116 end
timestamp_prop?()
click to toggle source
# File lib/neo4j/shared/declared_property.rb 98 def timestamp_prop? 99 name.to_sym == :created_at || name.to_sym == :updated_at 100 end