Module: Resubject::Builder
- Defined in:
- lib/resubject/builder.rb
Defined Under Namespace
Classes: InvalidPresenterArgument
Class Method Summary collapse
-
.present(objects, template, *presenters) ⇒ Presenter+
Presents a object or a collection of objects.
-
.present_all(objects, template, *presenters) ⇒ Array<Presenter>
Presents a collection of objects (see .present).
-
.present_one(object, template, *presenters) ⇒ Presenter
Presents a single object (see .present).
Class Method Details
.present(objects, template, *presenters) ⇒ Presenter+
Presents a object or a collection of objects
35 36 37 38 39 40 41 |
# File 'lib/resubject/builder.rb', line 35 def self.present(objects, template, *presenters) if objects.respond_to?(:each) Builder.present_all(objects, template, *presenters) else Builder.present_one(objects, template, *presenters) end end |
.present_all(objects, template, *presenters) ⇒ Array<Presenter>
Presents a collection of objects (see .present)
96 97 98 99 100 |
# File 'lib/resubject/builder.rb', line 96 def self.present_all(objects, template, *presenters) objects.map do |o| Builder.present_one(o, template, *presenters) end end |
.present_one(object, template, *presenters) ⇒ Presenter
Presents a single object (see .present)
66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/resubject/builder.rb', line 66 def self.present_one(object, template, *presenters) return unless object presenters = [Naming.presenter_for(object)] unless presenters.any? unless presenters.all? { |p| p.is_a?(Class) && p.ancestors.include?(Resubject::Presenter) } raise InvalidPresenterArgument, "Expected a presenter in #{presenters.inspect}" end presenters.inject(object) do |presented, klass| klass.new(presented, template) end end |