DeclaredProperty

Contains methods related to the management

Constants

  • ILLEGAL_PROPS

Methods

#<=>

Compare attribute definitions

def <=>(other)
  return nil unless other.instance_of? self.class
  return nil if name == other.name && options != other.options
  self.to_s <=> other.to_s
end

#[]

def [](key)
  respond_to?(key) ? public_send(key) : nil
end

#constraint!

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

#default

def default_value
  options[:default]
end

#default_value

def default_value
  options[:default]
end

#fail_invalid_options!

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

#index!

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

#index_or_constraint?

def index_or_constraint?
  index?(:exact) || constraint?(:unique)
end

#initialize

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

#inspect

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
#magic_typecaster

Returns the value of attribute magic_typecaster

def magic_typecaster
  @magic_typecaster
end
#name

Returns the value of attribute name

def name
  @name
end
#name_string

Returns the value of attribute name_string

def name_string
  @name_string
end
#name_sym

Returns the value of attribute name_sym

def name_sym
  @name_sym
end
#options

Returns the value of attribute options

def options
  @options
end

#register

def register
  register_magic_properties
end

#to_s

def to_s
  name.to_s
end

#to_sym

def to_sym
  name
end

#type

def type
  options[:type]
end

#typecaster

def typecaster
  options[:typecaster]
end

#unconstraint!

def unconstraint!(type = :unique)
  options.delete(:constraint) if constraint?(type)
end

#unindex!

def unindex!(type = :exact)
  options.delete(:index) if index?(type)
end