Module: Mystique
- Defined in:
- lib/mystique.rb,
lib/mystique/version.rb,
lib/mystique/presenter.rb,
lib/mystique/undefined.rb,
lib/mystique/null_context.rb
Defined Under Namespace
Modules: NullContext Classes: Presenter, Undefined
Constant Summary collapse
- VERSION =
"0.10.2"
Class Method Summary collapse
- .present(object, with: nil, context: nil, &block) ⇒ Object
- .present_collection(collection, context: nil, with: nil, &block) ⇒ Object
Class Method Details
.present(object, with: nil, context: nil, &block) ⇒ Object
9 10 11 12 13 14 15 16 |
# File 'lib/mystique.rb', line 9 def self.present(object, with: nil, context: nil, &block) begin presenter_class = presenter_class_for(object, with) presenter_class.for(object, context, &block) rescue NameError return object end end |
.present_collection(collection, context: nil, with: nil, &block) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/mystique.rb', line 18 def self.present_collection(collection, context: nil, with: nil, &block) return to_enum(:present_collection, collection, context: context, with: with, &block) unless block_given? collection.each do |element| case block.arity when 2 block.call( present(element, context: context, with: with), element ) else block.call(present(element, context: context, with: with)) end end end |