Class: Resubject::Presenter
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Resubject::Presenter
- Extended by:
- Extensions::TemplateMethods
- Defined in:
- lib/resubject/rails.rb,
lib/resubject/presenter.rb
Instance Attribute Summary collapse
-
#context ⇒ Object
(also: #template)
readonly
the HTML helpers context.
Class Method Summary collapse
-
.all(collection, context = nil) ⇒ Array<Presenter>
Builds a collection of presenters given an array of objects.
-
.presents(attribute, *presenters) ⇒ Object
Generates a instance method with the attribute presented.
Instance Method Summary collapse
-
#initialize(model, context = nil) ⇒ Presenter
constructor
Create a new presenter.
-
#present(objects, *presenters) ⇒ Presenter+
Creates a presenter from object or collection of objects.
Methods included from Extensions::TemplateMethods
currency, date_format, percentage, time_ago
Constructor Details
#initialize(model, context = nil) ⇒ Presenter
Create a new presenter
21 22 23 24 |
# File 'lib/resubject/presenter.rb', line 21 def initialize(model, context = nil) @context = context super(model) end |
Instance Attribute Details
#context ⇒ Object (readonly) Also known as: template
the HTML helpers context
8 9 10 |
# File 'lib/resubject/presenter.rb', line 8 def context @context end |
Class Method Details
.all(collection, context = nil) ⇒ Array<Presenter>
Builds a collection of presenters given an array of objects
43 44 45 |
# File 'lib/resubject/presenter.rb', line 43 def self.all(collection, context = nil) collection.map { |c| new(c, context) } end |
.presents(attribute, *presenters) ⇒ Object
Generates a instance method with the attribute presented
81 82 83 84 85 |
# File 'lib/resubject/presenter.rb', line 81 def self.presents(attribute, *presenters) define_method attribute do present to_model.send(attribute), *presenters end end |