Class: Freyja::Base
- Inherits:
-
Object
- Object
- Freyja::Base
- Defined in:
- lib/freyja/base.rb
Instance Attribute Summary collapse
-
#source ⇒ Object
Returns the value of attribute source.
Class Method Summary collapse
- ._attributes ⇒ Object
- ._has_many ⇒ Object
- ._has_one ⇒ Object
- .attributes(*args) ⇒ Object
- .has_many(attribute, translator = nil) ⇒ Object
- .has_one(attribute, translator = nil) ⇒ Object
Instance Method Summary collapse
- #as_json ⇒ Object
-
#initialize(source) ⇒ Base
constructor
A new instance of Base.
Constructor Details
#initialize(source) ⇒ Base
Returns a new instance of Base.
5 6 7 |
# File 'lib/freyja/base.rb', line 5 def initialize(source) self.source = ActiveSupport::HashWithIndifferentAccess.new(source) end |
Instance Attribute Details
#source ⇒ Object
Returns the value of attribute source.
3 4 5 |
# File 'lib/freyja/base.rb', line 3 def source @source end |
Class Method Details
._attributes ⇒ Object
29 30 31 |
# File 'lib/freyja/base.rb', line 29 def self._attributes @attributes || [] end |
._has_many ⇒ Object
37 38 39 |
# File 'lib/freyja/base.rb', line 37 def self._has_many @has_many || [] end |
._has_one ⇒ Object
33 34 35 |
# File 'lib/freyja/base.rb', line 33 def self._has_one @has_one || [] end |
.attributes(*args) ⇒ Object
9 10 11 |
# File 'lib/freyja/base.rb', line 9 def self.attributes(*args) @attributes = args end |
.has_many(attribute, translator = nil) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/freyja/base.rb', line 21 def self.has_many(attribute, translator = nil) @has_many ||= [] @has_many << { attribute: attribute, class: translator, } end |
.has_one(attribute, translator = nil) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/freyja/base.rb', line 13 def self.has_one(attribute, translator = nil) @has_one ||= [] @has_one << { attribute: attribute, class: translator, } end |
Instance Method Details
#as_json ⇒ Object
41 42 43 44 45 46 |
# File 'lib/freyja/base.rb', line 41 def as_json result = translate_attributes result.merge!(translate_has_one) result.merge!(translate_has_many) result end |