Class: Dao::Entity::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/dao/entity/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs = {}) ⇒ Base

Returns a new instance of Base.



8
9
10
11
# File 'lib/dao/entity/base.rb', line 8

def initialize(attrs = {})
  super
  after_initialize
end

Instance Attribute Details

#initialized_withObject

Returns the value of attribute initialized_with.



6
7
8
# File 'lib/dao/entity/base.rb', line 6

def initialized_with
  @initialized_with
end

Instance Method Details

#<=>(other) ⇒ Object

Raises:

  • (ArgumentError)


38
39
40
41
# File 'lib/dao/entity/base.rb', line 38

def <=>(other)
  raise ArgumentError, "comparison of #{ self.class.name } with #{ other.class.name } failed" unless other.instance_of?(self.class)
  id <=> other.id
end

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



34
35
36
# File 'lib/dao/entity/base.rb', line 34

def ==(other)
  other.instance_of?(self.class) && other.identity == identity
end

#after_initializeObject



13
14
15
# File 'lib/dao/entity/base.rb', line 13

def after_initialize
  @initialized_with = []
end

#hashObject



30
31
32
# File 'lib/dao/entity/base.rb', line 30

def hash
  "#{ self.class.name }/#{ identity }".hash
end

#persisted?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/dao/entity/base.rb', line 21

def persisted?
  id.present? if respond_to?(:id)
end

#to_keyObject



25
26
27
28
# File 'lib/dao/entity/base.rb', line 25

def to_key
  key = respond_to?(:id) && id
  key ? [key] : nil
end