Class: Hypermodel::Responder

Inherits:
Object
  • Object
show all
Defined in:
lib/hypermodel/responder.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource_name, action, resource, controller) ⇒ Responder

Returns a new instance of Responder.



18
19
20
21
22
# File 'lib/hypermodel/responder.rb', line 18

def initialize(resource_name, action, resource, controller)
  @resource_name = resource_name
  @action        = action
  @resource      = Serializer.new(resource, controller)
end

Class Method Details

.call(*args) ⇒ Object



7
8
9
10
11
12
13
14
15
16
# File 'lib/hypermodel/responder.rb', line 7

def self.call(*args)
  controller    = args[0]
  resource      = args[1].first
  resource_name = controller.params["controller"]
  action        = controller.params["action"]

  responder = new resource_name, action, resource, controller

  controller.render json: responder
end

Instance Method Details

#to_json(*opts) ⇒ Object



24
25
26
# File 'lib/hypermodel/responder.rb', line 24

def to_json(*opts)
  @resource.to_json(*opts)
end