Class: Neo4j::Shared::DeclaredProperty

Inherits:
Object
  • Object
show all
Includes:
Comparable, Index
Defined in:
lib/neo4j/shared/declared_property.rb,
lib/neo4j/shared/declared_property/index.rb

Overview

Contains methods related to the management

Defined Under Namespace

Modules: Index Classes: IllegalPropertyError

Constant Summary collapse

ILLEGAL_PROPS =
%w(from_node to_node start_node end_node)

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Index

#constraint!, #constraint?, #index!, #index?, #index_or_constraint?, #unconstraint!, #unindex!

Constructor Details

#initialize(name, options = {}) ⇒ DeclaredProperty

Returns a new instance of DeclaredProperty.



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/neo4j/shared/declared_property.rb', line 13

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
  @type = options[:type]
  @typecaster = options[:typecaster]
  @default_value = options[:default]
  @options = options
  fail_invalid_options!
end

Instance Attribute Details

#default_valueObject (readonly) Also known as: default

Returns the value of attribute default_value.



10
11
12
# File 'lib/neo4j/shared/declared_property.rb', line 10

def default_value
  @default_value
end

#magic_typecasterObject (readonly)

Returns the value of attribute magic_typecaster.



10
11
12
# File 'lib/neo4j/shared/declared_property.rb', line 10

def magic_typecaster
  @magic_typecaster
end

#nameObject (readonly)

Returns the value of attribute name.



10
11
12
# File 'lib/neo4j/shared/declared_property.rb', line 10

def name
  @name
end

#name_stringObject (readonly)

Returns the value of attribute name_string.



10
11
12
# File 'lib/neo4j/shared/declared_property.rb', line 10

def name_string
  @name_string
end

#name_symObject (readonly)

Returns the value of attribute name_sym.



10
11
12
# File 'lib/neo4j/shared/declared_property.rb', line 10

def name_sym
  @name_sym
end

#optionsObject (readonly)

Returns the value of attribute options.



10
11
12
# File 'lib/neo4j/shared/declared_property.rb', line 10

def options
  @options
end

#typeObject (readonly)

Returns the value of attribute type.



10
11
12
# File 'lib/neo4j/shared/declared_property.rb', line 10

def type
  @type
end

#typecasterObject (readonly)

Returns the value of attribute typecaster.



10
11
12
# File 'lib/neo4j/shared/declared_property.rb', line 10

def typecaster
  @typecaster
end

Instance Method Details

#<=>(other) ⇒ -1, ...

Compare attribute definitions

Examples:

attribute_definition <=> other

Parameters:

Returns:

  • (-1, 0, 1, nil)


34
35
36
37
38
# File 'lib/neo4j/shared/declared_property.rb', line 34

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

#[](key) ⇒ Object



54
55
56
# File 'lib/neo4j/shared/declared_property.rb', line 54

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

#fail_invalid_options!Object



62
63
64
65
66
67
68
# File 'lib/neo4j/shared/declared_property.rb', line 62

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

#inspectObject



40
41
42
43
44
# File 'lib/neo4j/shared/declared_property.rb', line 40

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

#registerObject



58
59
60
# File 'lib/neo4j/shared/declared_property.rb', line 58

def register
  register_magic_properties
end

#to_sObject



46
47
48
# File 'lib/neo4j/shared/declared_property.rb', line 46

def to_s
  name.to_s
end

#to_symObject



50
51
52
# File 'lib/neo4j/shared/declared_property.rb', line 50

def to_sym
  name
end