Module: ActiveNode::Core

Extended by:
ActiveSupport::Concern
Included in:
Base
Defined in:
lib/active_node/core.rb

Instance Method Summary collapse

Instance Method Details

#==(comparison_object) ⇒ Object Also known as: eql?

Returns true if comparison_object is the same exact object, or comparison_object is of the same type and self has an ID and it is equal to comparison_object.id.

Note that new records are different from any other record by definition, unless the other record is the receiver itself. Besides, if you fetch existing records with select and leave the ID out, you’re on your own, this predicate will return false.

Note also that destroying a record preserves its ID in the model instance, so deleted models are still comparable.



19
20
21
22
23
24
# File 'lib/active_node/core.rb', line 19

def ==(comparison_object)
  super ||
      comparison_object.instance_of?(self.class) &&
          !id.nil? &&
          comparison_object.id == id
end

#hashObject

Delegates to id in order to allow two records of the same type and id to work with something like:

[ Person.find(1), Person.find(2), Person.find(3) ] & [ Person.find(1), Person.find(4) ] # => [ Person.find(1) ]


29
30
31
32
33
34
35
# File 'lib/active_node/core.rb', line 29

def hash
  if id
    id.hash
  else
    super
  end
end

#initialize(attributes = nil, split_by = :respond_to_writer?) ⇒ Object



5
6
7
8
# File 'lib/active_node/core.rb', line 5

def initialize(attributes = nil, split_by=:respond_to_writer?)
  @association_cache = {}
  super attributes, split_by
end