Module: Padrino::Response::Respond

Defined in:
lib/padrino-response/respond.rb

Instance Method Summary collapse

Instance Method Details

#respond(*options) ⇒ Object Also known as: resp



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/padrino-response/respond.rb', line 4

def respond(*options)  
  if ::Padrino::Responders.constants.include?("#{controller_name.capitalize}")
    responder = ::Padrino::Responders.const_get("#{controller_name.capitalize}").new        
  elsif options.include?(:responder)
    responder = ::Padrino::Responders.const_get("#{options[:responder]}").new
  else
    responder = Padrino::Responders::Default.new
  end
  
  responder.object = options.shift if !options.first.is_a?(Hash)
  options = options.extract_options!
  responder.object = options.delete(:object) if options.include?(:object)
  responder.object ||= {}
  responder.options[:location] = options.shift if options.first.is_a?(String)             
  responder.options.merge!(options)
  responder.class   = self
  return responder.respond    
end