Sha256: 3f3d440038ae6412e194be93426189fc4ad96f558dc5f6b814644d69978b0252

Contents?: true

Size: 982 Bytes

Versions: 27

Compression:

Stored size: 982 Bytes

Contents

module Hanami
  module View
    # Inheriting mechanisms
    #
    # @since 0.1.0
    module Inheritable
      # Register a view subclass
      #
      # @api private
      # @since 0.1.0
      #
      # @example
      #   require 'hanami/view'
      #
      #   class IndexView
      #     include Hanami::View
      #   end
      #
      #   class JsonIndexView < IndexView
      #   end
      def inherited(base)
        subclasses.add base
      end

      # Set of registered subclasses
      #
      # @api private
      # @since 0.1.0
      def subclasses
        @subclasses ||= Set.new
      end

      protected
      # Loading mechanism hook.
      #
      # @api private
      # @since 0.1.0
      #
      # @see Hanami::View.load!
      def load!
        subclasses.freeze
        views.freeze
      end

      # Registered views
      #
      # @api private
      # @since 0.1.0
      def views
        @views ||= [ self ] + subclasses.to_a
      end
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
hanami-view-1.3.3 lib/hanami/view/inheritable.rb
hanami-view-1.3.2 lib/hanami/view/inheritable.rb
hanami-view-1.3.1 lib/hanami/view/inheritable.rb
hanami-view-1.3.0 lib/hanami/view/inheritable.rb
hanami-view-1.2.1 lib/hanami/view/inheritable.rb
hanami-view-1.3.0.beta1 lib/hanami/view/inheritable.rb
hanami-view-1.2.0 lib/hanami/view/inheritable.rb
hanami-view-1.1.2 lib/hanami/view/inheritable.rb
hanami-view-1.2.0.rc2 lib/hanami/view/inheritable.rb
hanami-view-1.2.0.rc1 lib/hanami/view/inheritable.rb
hanami-view-1.2.0.beta2 lib/hanami/view/inheritable.rb
hanami-view-1.2.0.beta1 lib/hanami/view/inheritable.rb
hanami-view-1.1.1 lib/hanami/view/inheritable.rb
hanami-view-1.1.0 lib/hanami/view/inheritable.rb
hanami-view-1.1.0.rc1 lib/hanami/view/inheritable.rb
hanami-view-1.1.0.beta3 lib/hanami/view/inheritable.rb
hanami-view-1.1.0.beta2 lib/hanami/view/inheritable.rb
hanami-view-1.1.0.beta1 lib/hanami/view/inheritable.rb
hanami-view-1.0.1 lib/hanami/view/inheritable.rb
hanami-view-1.0.0 lib/hanami/view/inheritable.rb