Module: ActiveGraph::Shared::Property

Extended by:
ActiveSupport::Concern
Includes:
MassAssignment, TypecastedAttributes, ActiveModel::Dirty
Included in:
Node::Property, Relationship::Property
Defined in:
lib/active_graph/shared/property.rb

Defined Under Namespace

Modules: ClassMethods Classes: MultiparameterAssignmentError, UndefinedPropertyError

Constant Summary collapse

NEO4J_DRIVER_DATA_TYPES =

This list should not be statically created. All types which have converters should by type casted

[Hash, ActiveSupport::Duration, Neo4j::Driver::Types::Point,
Neo4j::Driver::Types::OffsetTime, Neo4j::Driver::Types::LocalTime, Neo4j::Driver::Types::LocalDateTime]

Constants included from Attributes

Attributes::ATTRIBUTES_METHOD_PATTERNS, Attributes::DEPRECATED_OBJECT_METHODS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from TypecastedAttributes

#attribute_before_type_cast

Methods included from Attributes

#==, #attributes, #query_attribute, #write_attribute

Methods included from MassAssignment

#add_undeclared_property, #assign_attributes, #attributes=

Instance Attribute Details

#_persisted_objObject (readonly)

Returns the value of attribute _persisted_obj.



12
13
14
# File 'lib/active_graph/shared/property.rb', line 12

def _persisted_obj
  @_persisted_obj
end

Instance Method Details

#initialize(attributes = nil) ⇒ Object



34
35
36
37
38
39
40
41
42
43
# File 'lib/active_graph/shared/property.rb', line 34

def initialize(attributes = nil)
  @attributes ||= ActiveGraph::AttributeSet.new({}, self.class.attributes.keys)
  attributes = process_attributes(attributes)
  modded_attributes = inject_defaults!(attributes)
  validate_attributes!(modded_attributes)
  writer_method_props = extract_writer_methods!(modded_attributes)
  send_props(writer_method_props)
  self.undeclared_properties = attributes
  @_persisted_obj = nil
end

#inject_defaults!(starting_props) ⇒ Object



47
48
49
50
# File 'lib/active_graph/shared/property.rb', line 47

def inject_defaults!(starting_props)
  return starting_props if self.class.declared_properties.declared_property_defaults.empty?
  self.class.declared_properties.inject_defaults!(self, starting_props || {})
end

#inspectObject



25
26
27
28
29
30
31
32
# File 'lib/active_graph/shared/property.rb', line 25

def inspect
  attribute_descriptions = inspect_attributes.map do |key, value|
    "#{ActiveGraph::ANSI::CYAN}#{key}: #{ActiveGraph::ANSI::CLEAR}#{value.inspect}"
  end.join(', ')

  separator = ' ' unless attribute_descriptions.empty?
  "#<#{ActiveGraph::ANSI::YELLOW}#{self.class.name}#{ActiveGraph::ANSI::CLEAR}#{separator}#{attribute_descriptions}>"
end

#mutations_from_databaseObject

TODO: Set @attribute correctly using class ActiveModel::Attribute, and after that remove mutations_from_database and other ActiveModel::Dirty overrided methods



20
21
22
23
# File 'lib/active_graph/shared/property.rb', line 20

def mutations_from_database
  @mutations_from_database ||=
    defined?(ActiveModel::ForcedMutationTracker) ? ActiveModel::ForcedMutationTracker.new(self) : ActiveModel::NullMutationTracker.instance
end

#read_attribute(name) ⇒ Object Also known as: []



52
53
54
# File 'lib/active_graph/shared/property.rb', line 52

def read_attribute(name)
  respond_to?(name) ? send(name) : nil
end

#reload_properties!(properties) ⇒ Object



62
63
64
65
# File 'lib/active_graph/shared/property.rb', line 62

def reload_properties!(properties)
  @attributes = nil
  convert_and_assign_attributes(properties)
end

#send_props(hash) ⇒ Object



57
58
59
60
# File 'lib/active_graph/shared/property.rb', line 57

def send_props(hash)
  return hash if hash.blank?
  hash.each { |key, value| send("#{key}=", value) }
end

#undeclared_properties=(_) ⇒ Object



45
# File 'lib/active_graph/shared/property.rb', line 45

def undeclared_properties=(_); end