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
- .default(attribute) ⇒ Object
- .defaults ⇒ Object
- .has_many(attribute, translator = nil) ⇒ Object
- .has_one(attribute, translator = nil) ⇒ Object
- .set_default(attribute, value) ⇒ 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
45 46 47 |
# File 'lib/freyja/base.rb', line 45 def self._attributes @attributes || [] end |
._has_many ⇒ Object
53 54 55 |
# File 'lib/freyja/base.rb', line 53 def self._has_many @has_many || [] end |
._has_one ⇒ Object
49 50 51 |
# File 'lib/freyja/base.rb', line 49 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 |
.default(attribute) ⇒ Object
23 24 25 26 27 |
# File 'lib/freyja/base.rb', line 23 def self.default(attribute) make_sure_defaults_is_set defaults[attribute] end |
.defaults ⇒ Object
13 14 15 |
# File 'lib/freyja/base.rb', line 13 def self.defaults @defaults end |
.has_many(attribute, translator = nil) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/freyja/base.rb', line 37 def self.has_many(attribute, translator = nil) @has_many ||= [] @has_many << { attribute: attribute, class: translator, } end |
.has_one(attribute, translator = nil) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/freyja/base.rb', line 29 def self.has_one(attribute, translator = nil) @has_one ||= [] @has_one << { attribute: attribute, class: translator, } end |
.set_default(attribute, value) ⇒ Object
17 18 19 20 21 |
# File 'lib/freyja/base.rb', line 17 def self.set_default(attribute, value) make_sure_defaults_is_set @defaults[attribute] = value end |
Instance Method Details
#as_json ⇒ Object
57 58 59 60 61 62 |
# File 'lib/freyja/base.rb', line 57 def as_json result = translate_attributes result.merge!(translate_has_one) result.merge!(translate_has_many) result end |