Module: Neo4j::Shared::Attributes

Extended by:
ActiveSupport::Concern
Includes:
ActiveModel::AttributeMethods
Included in:
TypecastedAttributes
Defined in:
lib/neo4j/shared/attributes.rb

Overview

Attributes provides a set of class methods for defining an attributes schema and instance methods for reading and writing attributes.

Originally part of ActiveAttr, github.com/cgriego/active_attr

Examples:

Usage

class Person
  include Neo4j::Shared::Attributes
  attribute :name
end

person = Person.new
person.name = "Ben Poweski"

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

DEPRECATED_OBJECT_METHODS =

Methods deprecated on the Object class which can be safely overridden

%w(id type)

Instance Method Summary collapse

Methods included from ActiveSupport::Concern

class_methods

Instance Method Details

#==(other) ⇒ true, false

Performs equality checking on the result of attributes and its type.

Examples:

Compare for equality.

model == other


37
38
39
40
# File 'lib/neo4j/shared/attributes.rb', line 37

def ==(other)
  return false unless other.instance_of? self.class
  attributes == other.attributes
end

#attributesHash{String => Object}

Returns a Hash of all attributes

Examples:

Get attributes

person.attributes # => {"name"=>"Ben Poweski"}


48
49
50
# File 'lib/neo4j/shared/attributes.rb', line 48

def attributes
  attributes_map { |name| send name }
end

#query_attribute(name) ⇒ Object



72
73
74
75
76
77
78
# File 'lib/neo4j/shared/attributes.rb', line 72

def query_attribute(name)
  if respond_to? "#{name}?"
    send "#{name}?"
  else
    fail Neo4j::UnknownAttributeError, "unknown attribute: #{name}"
  end
end

#write_attribute(name, value) ⇒ Object Also known as: []=

Write a single attribute to the model’s attribute hash.

Examples:

Write the attribute with write_attribute

person.write_attribute(:name, "Benjamin")

Write an attribute with bracket syntax

person[:name] = "Benjamin"

Raises:



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

def write_attribute(name, value)
  if respond_to? "#{name}="
    send "#{name}=", value
  else
    fail Neo4j::UnknownAttributeError, "unknown attribute: #{name}"
  end
end