DeclaredProperty¶
Contains methods related to the management
Constants¶
- ILLEGAL_PROPS
Methods¶
#[]
def [](key) respond_to?(key) ? public_send(key) : nil end
def constraint!(type = :unique) fail Neo4j::InvalidPropertyOptionsError, "Unable to set constraint on indexed property #{name}" if index?(:exact) options[:constraint] = type end
#constraint?
def constraint?(type = :unique) options.key?(:constraint) && options[:constraint] == type end
def default_value options[:default] end
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
def index!(type = :exact) fail Neo4j::InvalidPropertyOptionsError, "Unable to set index on constrainted property #{name}" if constraint?(:unique) options[:index] = type end
#index?
def index?(type = :exact) options.key?(:index) && options[:index] == type end
def index_or_constraint? index?(:exact) || constraint?(:unique) end
def initialize(name, options = {}) fail IllegalPropertyError, "#{name} is an illegal property" if ILLEGAL_PROPS.include?(name.to_s) fail TypeError, "can't convert #{name.class} into Symbol" unless name.respond_to?(:to_sym) @name = @name_sym = name.to_sym @name_string = name.to_s @options = options fail_invalid_options! end
def inspect options_description = options.map { |key, value| "#{key.inspect} => #{value.inspect}" }.sort.join(', ') inspected_options = ", #{options_description}" unless options_description.empty? "attribute :#{name}#{inspected_options}" end
def register register_magic_properties end
def to_s name.to_s end
def to_sym name end
def type options[:type] end
def typecaster options[:typecaster] end
def unconstraint!(type = :unique) options.delete(:constraint) if constraint?(type) end
def unindex!(type = :exact) options.delete(:index) if index?(type) end