Class: Transfigr::Presenter
- Inherits:
-
Object
- Object
- Transfigr::Presenter
- Defined in:
- lib/transfigr/presenter.rb
Overview
:api: private
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
Class Method Summary collapse
-
.add_format!(format) ⇒ Object
Adds a formatter to the presenter :api: private.
-
.remove_format!(format) ⇒ Object
Removes the formatter method from the presenter :api: private.
Instance Method Summary collapse
-
#initialize(target, options = {}) ⇒ Presenter
constructor
A new instance of Presenter.
-
#method_missing(name, *rest) ⇒ Object
:api: overwritable.
Constructor Details
#initialize(target, options = {}) ⇒ Presenter
Returns a new instance of Presenter.
22 23 24 |
# File 'lib/transfigr/presenter.rb', line 22 def initialize(target, = {}) @target, @options = target, end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *rest) ⇒ Object
:api: overwritable
49 50 51 52 53 54 55 |
# File 'lib/transfigr/presenter.rb', line 49 def method_missing(name, *rest) if name.to_s =~ /^to_/ return target.send(name) if target.respond_to?(name) raise FormatterNotFound, "No active #{name.inspect} format was found" end super end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
20 21 22 |
# File 'lib/transfigr/presenter.rb', line 20 def @options end |
#target ⇒ Object (readonly)
Returns the value of attribute target.
20 21 22 |
# File 'lib/transfigr/presenter.rb', line 20 def target @target end |
Class Method Details
.add_format!(format) ⇒ Object
Adds a formatter to the presenter :api: private
34 35 36 37 38 39 40 |
# File 'lib/transfigr/presenter.rb', line 34 def self.add_format!(format) self.class_eval <<-RUBY def to_#{format} Transfigr.format!(:#{format}, target, options) end RUBY end |
.remove_format!(format) ⇒ Object
Removes the formatter method from the presenter :api: private
44 45 46 |
# File 'lib/transfigr/presenter.rb', line 44 def self.remove_format!(format) undef_method :"to_#{format}" end |