Class: Kix::Serializer
- Inherits:
-
Object
- Object
- Kix::Serializer
- Defined in:
- lib/kix/serializer.rb
Instance Attribute Summary collapse
-
#_object ⇒ Object
readonly
Returns the value of attribute _object.
Class Method Summary collapse
- .attributes(*attrs) ⇒ Object (also: attribute)
- .defined_attributes ⇒ Object
- .inherited(subclass) ⇒ Object
Instance Method Summary collapse
- #as_json(*args) ⇒ Object
-
#initialize(object) ⇒ Serializer
constructor
A new instance of Serializer.
Constructor Details
#initialize(object) ⇒ Serializer
Returns a new instance of Serializer.
7 8 9 |
# File 'lib/kix/serializer.rb', line 7 def initialize(object) @_object = object end |
Instance Attribute Details
#_object ⇒ Object (readonly)
Returns the value of attribute _object.
5 6 7 |
# File 'lib/kix/serializer.rb', line 5 def _object @_object end |
Class Method Details
.attributes(*attrs) ⇒ Object Also known as: attribute
32 33 34 |
# File 'lib/kix/serializer.rb', line 32 def attributes(*attrs) attrs.each { |attr| defined_attributes.push(attr.to_s) } end |
.defined_attributes ⇒ Object
37 38 39 |
# File 'lib/kix/serializer.rb', line 37 def defined_attributes @defined_attributes ||= [] end |
.inherited(subclass) ⇒ Object
28 29 30 |
# File 'lib/kix/serializer.rb', line 28 def inherited(subclass) subclass.attributes(*@defined_attributes) end |
Instance Method Details
#as_json(*args) ⇒ Object
11 12 13 14 15 |
# File 'lib/kix/serializer.rb', line 11 def as_json(*args) self.class.defined_attributes.each_with_object({}) { |attr, h| catch(:skip) { h[attr] = value_for(attr, args).as_json } } end |