module Mystique

Constants

VERSION

Public Class Methods

present(object, with: nil, context: nil, &block) click to toggle source
# File lib/mystique.rb, line 11
def self.present(object, with: nil, context: nil, &block)
  begin
    presenter_class = PresenterClass.new(object, with).to_class
    presenter_class.for(object, context, &block)
  rescue NameError
    return object
  end
end
present_collection(collection, context: nil, with: nil, &block) click to toggle source
# File lib/mystique.rb, line 20
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

Private Class Methods

presenter_class_for(object, with) click to toggle source
# File lib/mystique.rb, line 35
def self.presenter_class_for(object, with)
  with || Object.send(:const_get, "#{object.class}Presenter")
end