Module: Middlewares::Decorator::Representable
- Defined in:
- lib/endpoint_flux/tasks/endpoint_flux/generators/endpoint_flux/middlewares/decorator/representable.rb
Class Method Summary collapse
Class Method Details
.decorate(object, options) ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/endpoint_flux/tasks/endpoint_flux/generators/endpoint_flux/middlewares/decorator/representable.rb', line 13 def self.decorate(object, ) decorator = "::Decorators::#{[:decorator].to_s.camelize}".constantize if [:collection?] decorator.for_collection.new(object.to_a).to_hash else decorator.new(object).to_hash end end |
.perform(request, response, options) ⇒ Object
4 5 6 7 8 9 10 11 |
# File 'lib/endpoint_flux/tasks/endpoint_flux/generators/endpoint_flux/middlewares/decorator/representable.rb', line 4 def self.perform(request, response, ) resource_name = [:wrapped_in] || [:decorator] resource = response.body[resource_name] response.body[resource_name] = decorate(resource, ) if resource [request, response] end |