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
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
#as_json(model, context = {}) ⇒ Object
83 84 85 |
# File 'lib/restpack_serializer/serializable.rb', line 83 def as_json(model, context = {}) new.as_json(model, context) end |
#serialize(models, context = {}) ⇒ Object
87 88 89 90 91 92 93 |
# File 'lib/restpack_serializer/serializable.rb', line 87 def serialize(models, context = {}) models = [models] unless models.kind_of?(Array) { self.key() => models.map {|model| self.as_json(model, context)} } end |