Class: MiniApi::Responder

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

Instance Method Summary collapse

Constructor Details

#initialize(controller, resource, options = {}) ⇒ Responder

Returns a new instance of Responder.



9
10
11
12
13
# File 'lib/mini_api/responder.rb', line 9

def initialize(controller, resource, options = {})
  @controller = controller
  @resource = resource
  @options = options
end

Instance Method Details

#default_responderObject



34
35
36
# File 'lib/mini_api/responder.rb', line 34

def default_responder
  DefaultResponder.new(@controller, @resource, @options)
end

#model_responderObject



30
31
32
# File 'lib/mini_api/responder.rb', line 30

def model_responder
  ModelResponder.new(@controller, @resource, @options)
end

#relation_responderObject



26
27
28
# File 'lib/mini_api/responder.rb', line 26

def relation_responder
  RelationResponder.new(@controller, @resource, @options)
end

#respondObject



15
16
17
18
19
20
21
22
23
24
# File 'lib/mini_api/responder.rb', line 15

def respond
  case @resource
  when ActiveRecord::Relation
    relation_responder.respond
  when ActiveRecord::Base, ActiveModel::Model
    model_responder.respond
  else
    default_responder.respond
  end
end