Class: Dao::Entity::Base
- Inherits:
-
Object
- Object
- Dao::Entity::Base
- Defined in:
- lib/dao/entity/base.rb
Instance Attribute Summary collapse
-
#initialized_with ⇒ Object
Returns the value of attribute initialized_with.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #==(other) ⇒ Object (also: #eql?)
- #after_initialize ⇒ Object
- #hash ⇒ Object
-
#initialize(attrs = {}) ⇒ Base
constructor
A new instance of Base.
- #persisted? ⇒ Boolean
- #to_key ⇒ Object
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_with ⇒ Object
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
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_initialize ⇒ Object
13 14 15 |
# File 'lib/dao/entity/base.rb', line 13 def after_initialize @initialized_with = [] end |
#hash ⇒ Object
30 31 32 |
# File 'lib/dao/entity/base.rb', line 30 def hash "#{ self.class.name }/#{ identity }".hash end |
#persisted? ⇒ Boolean
21 22 23 |
# File 'lib/dao/entity/base.rb', line 21 def persisted? id.present? if respond_to?(:id) end |
#to_key ⇒ Object
25 26 27 28 |
# File 'lib/dao/entity/base.rb', line 25 def to_key key = respond_to?(:id) && id key ? [key] : nil end |