Class: Porth::Handler
- Inherits:
-
Object
- Object
- Porth::Handler
- Defined in:
- lib/porth/handler.rb
Instance Attribute Summary collapse
-
#template ⇒ Object
readonly
Returns the value of attribute template.
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
- #format ⇒ Object
-
#initialize(template) ⇒ Handler
constructor
A new instance of Handler.
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
#template ⇒ Object (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 |
.formats ⇒ Object
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
#call ⇒ Object
9 10 11 |
# File 'lib/porth/handler.rb', line 9 def call "#{format}.call controller, instance_eval { #{template.source} }" end |
#format ⇒ Object
13 14 15 |
# File 'lib/porth/handler.rb', line 13 def format self.class.formats.fetch(template.formats.first) { raise UnknownFormatError } end |