Sha256: bf1728512f36435172468609f8c8bbeabe87c55c5cd7ad8abbf77603df2b1609

Contents?: true

Size: 710 Bytes

Versions: 5

Compression:

Stored size: 710 Bytes

Contents

# Class every presenter class should inherit from
class BasePresenter
  # Initialize class with object to be presented and the view it is to be presented on
  def initialize(object, template)
    @object = object
    @template = template
  end

  # Same as application helper short date
  def format_date(date)
    date.strftime("%Y-%m-%d")
  end

private
 # Class method to call the object by its class
  def self.presents(name)
    define_method(name) do
      @object
    end
  end

  # Accessor for template methods
  def t
    @template
  end

  # In the event a method called can't be found, default to the template methods
  def method_missing(*args, &block)
    @template.send(*args, &block)
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
myrails-7.0.0 lib/myrails/templates/rails/app/presenters/base.rb
myrails-6.0.0 lib/myrails/templates/rails/app/presenters/base.rb
myrails-5.0.0 lib/myrails/templates/rails/app/presenters/base.rb
myrails-4.0.0 lib/myrails/templates/presenters/base.rb
myrails-3.2.1 lib/myrails/templates/presenters/base.rb