Class: Porth::Handler

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(template) ⇒ Handler

Returns a new instance of Handler.



5
6
7
# File 'lib/porth/handler.rb', line 5

def initialize template
  @template = template
end

Instance Attribute Details

#templateObject (readonly)

Returns the value of attribute template.



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

def template
  @template
end

Class Method Details

.call(template) ⇒ Object



17
18
19
# File 'lib/porth/handler.rb', line 17

def self.call template
  new(template).call
end

.formatsObject



21
22
23
# File 'lib/porth/handler.rb', line 21

def self.formats
  @formats ||= {}
end

.register_format(format, mod) ⇒ Object



25
26
27
28
# File 'lib/porth/handler.rb', line 25

def self.register_format format, mod
  formats[format] = mod
  ActionController::Base.send :include, mod::ControllerExtensions
end

Instance Method Details

#callObject



9
10
11
# File 'lib/porth/handler.rb', line 9

def call
  "#{format}.call controller, instance_eval { #{template.source} }"
end

#formatObject



13
14
15
# File 'lib/porth/handler.rb', line 13

def format
  self.class.formats.fetch(template.formats.first) { raise UnknownFormatError }
end