Sha256: 2b94fef5e5eefe0a703a22cd56d488a1292ae4cd39f7636c330182bb2ac69d9d

Contents?: true

Size: 1 KB

Versions: 1

Compression:

Stored size: 1 KB

Contents

require "mystique/version"

require "callable"
require "string_plus"

require "mystique/undefined"
require "mystique/presenter"

module Mystique
  module_function

  def present(object, with: nil, context: nil, &block)
    presenter_class = case with
                      when nil
                        begin
                          StringPlus.constantize("#{object.class}Presenter")
                        rescue NameError => e
                          return object
                        end
                      when Symbol, String
                        StringPlus.constantize("#{with.capitalize}Presenter")
                      else
                        with
                      end
    presenter_class.present(object, context, &block)
  end

  def present_collection(collection, context: nil, &block)
    return to_enum(:present_collection, collection, context: context, &block) unless block_given?

    collection.each do |element|
      block.call present(element, context: context)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mystique-0.5.5 lib/mystique.rb