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.
81 82 83 |
# File 'lib/restpack_serializer/serializable.rb', line 81 def key @key end |
#model_class ⇒ Object
Returns the value of attribute model_class.
81 82 83 |
# File 'lib/restpack_serializer/serializable.rb', line 81 def model_class @model_class end |
Instance Method Details
#array_as_json(models, context = {}) ⇒ Object
83 84 85 |
# File 'lib/restpack_serializer/serializable.rb', line 83 def array_as_json(models, context = {}) new.as_json(models, context) end |
#as_json(model, context = {}) ⇒ Object
87 88 89 |
# File 'lib/restpack_serializer/serializable.rb', line 87 def as_json(model, context = {}) new.as_json(model, context) end |
#serialize(models, context = {}) ⇒ Object
91 92 93 94 95 96 97 |
# File 'lib/restpack_serializer/serializable.rb', line 91 def serialize(models, context = {}) models = [models] unless models.kind_of?(Array) { self.key() => models.map {|model| self.as_json(model, context)} } end |