Module: RestPack::Serializer::ClassMethods
- Defined in:
- lib/restpack_serializer/serializable.rb
Instance Attribute Summary collapse
-
#href_prefix ⇒ Object
Returns the value of attribute href_prefix.
-
#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
- #plural_key ⇒ Object
- #serialize(models, context = {}) ⇒ Object
- #singular_key ⇒ Object
Instance Attribute Details
#href_prefix ⇒ Object
Returns the value of attribute href_prefix.
92 93 94 |
# File 'lib/restpack_serializer/serializable.rb', line 92 def href_prefix @href_prefix end |
#key ⇒ Object
Returns the value of attribute key.
92 93 94 |
# File 'lib/restpack_serializer/serializable.rb', line 92 def key @key end |
#model_class ⇒ Object
Returns the value of attribute model_class.
92 93 94 |
# File 'lib/restpack_serializer/serializable.rb', line 92 def model_class @model_class end |
Instance Method Details
#array_as_json(models, context = {}) ⇒ Object
94 95 96 |
# File 'lib/restpack_serializer/serializable.rb', line 94 def array_as_json(models, context = {}) new.as_json(models, context) end |
#as_json(model, context = {}) ⇒ Object
98 99 100 |
# File 'lib/restpack_serializer/serializable.rb', line 98 def as_json(model, context = {}) new.as_json(model, context) end |
#plural_key ⇒ Object
126 127 128 |
# File 'lib/restpack_serializer/serializable.rb', line 126 def plural_key self.key end |
#serialize(models, context = {}) ⇒ Object
102 103 104 105 106 107 108 |
# File 'lib/restpack_serializer/serializable.rb', line 102 def serialize(models, context = {}) models = [models] unless models.kind_of?(Array) { self.key() => models.map {|model| self.as_json(model, context)} } end |
#singular_key ⇒ Object
122 123 124 |
# File 'lib/restpack_serializer/serializable.rb', line 122 def singular_key self.key.to_s.singularize.to_sym end |