Class: Entity::Base
- Inherits:
-
Object
- Object
- Entity::Base
- Defined in:
- lib/entity_rb/base.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns the value of attribute attributes.
Class Method Summary collapse
Instance Method Summary collapse
- #fields ⇒ Object
-
#initialize(args = {}) ⇒ Base
constructor
A new instance of Base.
- #set_attributes(args) ⇒ Object
- #to_h ⇒ Object (also: #to_hash)
Constructor Details
#initialize(args = {}) ⇒ Base
Returns a new instance of Base.
5 6 7 8 9 |
# File 'lib/entity_rb/base.rb', line 5 def initialize(args={}) initialize_attributes(args || {}) set_attributes(args) end |
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
3 4 5 |
# File 'lib/entity_rb/base.rb', line 3 def attributes @attributes end |
Class Method Details
.fields ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/entity_rb/base.rb', line 34 def self.fields return @fields if @fields @fields = parent && parent.respond_to?(:fields) ? parent.fields.dup : [] field @fields end |
Instance Method Details
#fields ⇒ Object
42 43 44 |
# File 'lib/entity_rb/base.rb', line 42 def fields self.class.fields end |
#set_attributes(args) ⇒ Object
11 12 |
# File 'lib/entity_rb/base.rb', line 11 def set_attributes(args) end |
#to_h ⇒ Object Also known as: to_hash
24 25 26 27 28 29 30 |
# File 'lib/entity_rb/base.rb', line 24 def to_h {}.tap do |hash| fields.each do |key| hash[key] = send(key) unless send(key).nil? end end end |