Class: EscortMission::Responder

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

Overview

Uses the given escort’s controller to respond to the current request. This could involve rendering a conventional template or returning a serialized output of the model.

Direct Known Subclasses

ActionPack::ApiResponder

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(escort) ⇒ Responder

Returns a new instance of Responder.



28
29
30
31
# File 'lib/escort_mission.rb', line 28

def initialize(escort)
  @escort     = escort
  @controller = escort.controller
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args) ⇒ Object

Passes the given method to the escort to fetch the records, and then calls #display to respond to the controller request.



41
42
43
44
45
# File 'lib/escort_mission.rb', line 41

def method_missing(method_name, *args)
  records = @escort.send(method_name, *args)
  display(records)
  records
end

Instance Attribute Details

#controllerObject (readonly)

Returns the value of attribute controller.



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

def controller
  @controller
end

#escortObject (readonly)

Returns the value of attribute escort.



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

def escort
  @escort
end

Instance Method Details

#display(records) ⇒ Object

Override this to provide controller-specific details for responding to the controller request in a certain way.

Raises:

  • (NotImplementedError)


35
36
37
# File 'lib/escort_mission.rb', line 35

def display(records)
  raise NotImplementedError
end