Class: CallResponder

Inherits:
ActionController::Responder
  • Object
show all
Defined in:
lib/call_responder.rb

Constant Summary collapse

RESPONDER_FILE =
"config/responder.yml"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(controller, resources, options = {}) ⇒ CallResponder

Returns a new instance of CallResponder.

Raises:

  • (LoadError)


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

def initialize(controller, resources, options={})
    super
    @controller = controller
    @request = @controller.request
    @format = @controller.formats.first
    @formats = [ :report ]
    raise LoadError.new("You must have the file #{RESPONDER_FILE} with 'url: URL' string") unless File.exists?(RESPONDER_FILE)
    @config = YAML::load(File.open(RESPONDER_FILE))
end

Instance Attribute Details

#controllerObject (readonly)

Returns the value of attribute controller.



3
4
5
# File 'lib/call_responder.rb', line 3

def controller
  @controller
end

#formatObject (readonly)

Returns the value of attribute format.



3
4
5
# File 'lib/call_responder.rb', line 3

def format
  @format
end

#optionsObject (readonly)

Returns the value of attribute options.



3
4
5
# File 'lib/call_responder.rb', line 3

def options
  @options
end

#requestObject (readonly)

Returns the value of attribute request.



3
4
5
# File 'lib/call_responder.rb', line 3

def request
  @request
end

#resourceObject (readonly)

Returns the value of attribute resource.



3
4
5
# File 'lib/call_responder.rb', line 3

def resource
  @resource
end

#resourcesObject (readonly)

Returns the value of attribute resources.



3
4
5
# File 'lib/call_responder.rb', line 3

def resources
  @resources
end

Instance Method Details

#to_formatObject



17
18
19
20
# File 'lib/call_responder.rb', line 17

def to_format
    to_pdf if @format == 'pdf'
    super
end

#to_pdfObject



22
23
24
25
26
27
28
29
30
# File 'lib/call_responder.rb', line 22

def to_pdf
  stream = RestClient.post(@config["url"], 
    { 
      :file => controller.render_to_string(:formats => @formats) 
    }
  )

  controller.send_data( stream, :filename => @request.fullpath.gsub("/","") )
end