Class: GrapeSerializer
- Inherits:
-
Object
- Object
- GrapeSerializer
- Defined in:
- lib/grape_serializer.rb
Class Attribute Summary collapse
-
.entity_class ⇒ Object
readonly
Returns the value of attribute entity_class.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(params = {}) ⇒ GrapeSerializer
constructor
A new instance of GrapeSerializer.
- #represent(resource, opts = {}) ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ GrapeSerializer
Returns a new instance of GrapeSerializer.
14 15 16 |
# File 'lib/grape_serializer.rb', line 14 def initialize(params = {}) @params = params end |
Class Attribute Details
.entity_class ⇒ Object (readonly)
Returns the value of attribute entity_class.
7 8 9 |
# File 'lib/grape_serializer.rb', line 7 def entity_class @entity_class end |
Class Method Details
.entity(entity_class) ⇒ Object
9 10 11 |
# File 'lib/grape_serializer.rb', line 9 def entity(entity_class) @entity_class ||= entity_class end |
Instance Method Details
#represent(resource, opts = {}) ⇒ Object
18 19 20 21 |
# File 'lib/grape_serializer.rb', line 18 def represent(resource, opts = {}) preload_associations(resource) if defined?(::Rails::Engine) && defined?(::ActiveRecord) && resource.is_a?(ActiveRecord) self.class.entity_class.represent(resource, opts.merge(@params)).as_json end |