Module: RestPack::Serializer::ClassMethods
- Defined in:
- lib/restpack_serializer/serializable.rb
Instance Attribute Summary collapse
-
#key ⇒ Object
Returns the value of attribute key.
-
#model_class ⇒ Object
Returns the value of attribute model_class.
Instance Method Summary collapse
- #array_as_json(models, context = {}) ⇒ Object
- #as_json(model, context = {}) ⇒ Object
- #serialize(models, context = {}) ⇒ Object
Instance Attribute Details
#key ⇒ Object
Returns the value of attribute key.
84 85 86 |
# File 'lib/restpack_serializer/serializable.rb', line 84 def key @key end |
#model_class ⇒ Object
Returns the value of attribute model_class.
84 85 86 |
# File 'lib/restpack_serializer/serializable.rb', line 84 def model_class @model_class end |
Instance Method Details
#array_as_json(models, context = {}) ⇒ Object
86 87 88 |
# File 'lib/restpack_serializer/serializable.rb', line 86 def array_as_json(models, context = {}) new.as_json(models, context) end |
#as_json(model, context = {}) ⇒ Object
90 91 92 |
# File 'lib/restpack_serializer/serializable.rb', line 90 def as_json(model, context = {}) new.as_json(model, context) end |
#serialize(models, context = {}) ⇒ Object
94 95 96 97 98 99 100 |
# File 'lib/restpack_serializer/serializable.rb', line 94 def serialize(models, context = {}) models = [models] unless models.kind_of?(Array) { self.key() => models.map {|model| self.as_json(model, context)} } end |