lib/neo4j/shared/declared_property.rb in neo4j-5.2.15 vs lib/neo4j/shared/declared_property.rb in neo4j-6.0.0.alpha.1
- old
+ new
@@ -1,18 +1,20 @@
module Neo4j::Shared
# Contains methods related to the management
class DeclaredProperty
class IllegalPropertyError < StandardError; end
+ include Neo4j::Shared::DeclaredProperty::Index
ILLEGAL_PROPS = %w(from_node to_node start_node end_node)
attr_reader :name, :name_string, :name_sym, :options, :magic_typecaster
def initialize(name, options = {})
fail IllegalPropertyError, "#{name} is an illegal property" if ILLEGAL_PROPS.include?(name.to_s)
@name = @name_sym = name
@name_string = name.to_s
@options = options
+ fail_invalid_options!
end
def register
register_magic_properties
end
@@ -27,10 +29,27 @@
def default_value
options[:default]
end
+ def fail_invalid_options!
+ case
+ when index?(:exact) && constraint?(:unique)
+ fail Neo4j::InvalidPropertyOptionsError,
+ "#Uniqueness constraints also provide exact indexes, cannot set both options on property #{name}"
+ end
+ end
+
private
+
+ def option_with_value!(key, value)
+ options[key] = value
+ fail_invalid_options!
+ end
+
+ def option_with_value?(key, value)
+ options[key] == value
+ end
# Tweaks properties
def register_magic_properties
options[:type] ||= Neo4j::Config.timestamp_type if timestamp_prop?