Sha256: 89beda69cfbaa81a8972916fb77ffc3d49bcf3b34d1ce3e622ee12db5a9812a8

Contents?: true

Size: 967 Bytes

Versions: 25

Compression:

Stored size: 967 Bytes

Contents

# frozen_string_literal: true

module Kadmin
  module Presentable
    extend ActiveSupport::Concern

    module ClassMethods
      def presenter_class
        return @presenter_class ||= begin
          self::Presenter
        rescue NameError
          nil
        end
      end

      def presenter_class=(klass)
        @presenter_class = klass
      end
    end

    # Delegates present to a newly instantiated presenter object
    # Checks the including class' presenter_class attribute, with fallback to an inner Presenter class
    # @param [ActiveView::Base] view the view to present in if available; can be supplied to the presenter later
    # @raise [Kadmin::Error] raises an error if no presenter class defined
    def present(view = nil)
      if self.class.presenter_class.nil?
        raise Kadmin::Error, 'cannot present without a presenter_class'
      else
        return self.class.presenter_class.new(self, view: view)
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
kadmin-1.3.0 lib/kadmin/presentable.rb
kadmin-1.2.1 lib/kadmin/presentable.rb
kadmin-1.2.0 lib/kadmin/presentable.rb
kadmin-1.1.1 lib/kadmin/presentable.rb
kadmin-1.1.0 lib/kadmin/presentable.rb
kadmin-1.0.9 lib/kadmin/presentable.rb
kadmin-1.0.8 lib/kadmin/presentable.rb
kadmin-1.0.7 lib/kadmin/presentable.rb
kadmin-1.0.6 lib/kadmin/presentable.rb
kadmin-1.0.5 lib/kadmin/presentable.rb
kadmin-1.0.4 lib/kadmin/presentable.rb
kadmin-1.0.3 lib/kadmin/presentable.rb
kadmin-1.0.2 lib/kadmin/presentable.rb
kadmin-1.0.1 lib/kadmin/presentable.rb
kadmin-1.0.0 lib/kadmin/presentable.rb
kadmin-0.9.5 lib/kadmin/presentable.rb
kadmin-0.9.4 lib/kadmin/presentable.rb
kadmin-0.8.0 lib/kadmin/presentable.rb
kadmin-0.7.5 lib/kadmin/presentable.rb
kadmin-0.7.4 lib/kadmin/presentable.rb