Sha256: d206ad490947e146aec6d34f7d745a0f2c3fce77c3ad889f386c388a3886f231

Contents?: true

Size: 1.44 KB

Versions: 5

Compression:

Stored size: 1.44 KB

Contents

# frozen_string_literal: true

module Chic
  # == Presenting Associations
  #
  # Use `presents` and `formats` declarations to present and format associations and attributes.
  #
  # @example Presenter inferred from type or attribute name
  #   FooPresenter < Chic::Presenter
  #     presents :bar
  #   end
  #
  # @example Presenter declared explicitly
  #   FooPresenter < Chic::Presenter
  #     presents bar: BarPresenter
  #   end
  #
  # @example Association declared using a different value
  #   FooPresenter < Chic::Presenter
  #     presents bar: {
  #                with: BarPresenter,
  #                value: -> { load_bar }
  #              }
  #   end
  #
  # === ActiveRecord::Relation
  #
  # When presenting `ActiveRecord::Relation` associations:
  #
  # @example Don't call relation methods through the presenter
  #   foo.presenter.bars.count
  #
  # @example Do call relation methods directly
  #   foo.bars.count
  #
  # == Formatting Attributes
  #
  # @example Declare presented associations
  #   FooPresenter < Chic::Presenter
  #     presents bar: BarPresenter
  #
  #     formats :title,
  #             with: :nil,
  #             options: {
  #               blank_value: '(No Title)'
  #             }
  #   end
  #
  class Presenter
    include Formats
    include Presents

    attr_reader :object,
                :context

    def initialize(object = nil, context = nil)
      @object = object
      @context = context
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
chic-0.4.0 lib/chic/presenter.rb
chic-0.3.1 lib/chic/presenter.rb
chic-0.3.0 lib/chic/presenter.rb
chic-0.2.0 lib/chic/presenter.rb
chic-0.1.0 lib/chic/presenter.rb