Sha256: 46dd5e697bd9888b46e9ec6cd5741ea8a80407849d582f857348f747ea63810d

Contents?: true

Size: 1.54 KB

Versions: 7

Compression:

Stored size: 1.54 KB

Contents

# frozen_string_literal: true

require "pakyow/support/extension"

require "pakyow/ui/recordable"

module Pakyow
  class Application
    module Behavior
      module UI
        module Recording
          extend Support::Extension

          # @api private
          def find_ui_presenter_for(presenter_class)
            if is_a?(Plugin)
              # Look for the presenter in the plugin first, falling back to the app.
              #
              ui_presenter_class = parent.ui_presenters.find { |klass|
                klass.ancestors.include?(presenter_class)
              }
            end

            ui_presenter_class ||= @ui_presenters.find { |klass|
              klass.ancestors.include?(presenter_class)
            }
          end

          apply_extension do
            # Create subclasses of each presenter, then make the subclasses recordable.
            # These subclasses will be used when performing a ui presentation instead
            # of the original presenter, but they'll behave identically!
            #
            after "initialize" do
              @ui_presenters = [isolated(:Presenter)].concat(
                state(:presenter)
              ).concat(
                state(:component).map(&:__presenter_class)
              ).map { |presenter_class|
                Class.new(presenter_class) do
                  include Pakyow::UI::Recordable
                end
              }
            end

            class_eval do
              attr_reader :ui_presenters
            end
          end
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
pakyow-ui-1.0.6 lib/pakyow/application/behavior/ui/recording.rb
pakyow-ui-1.0.5 lib/pakyow/application/behavior/ui/recording.rb
pakyow-ui-1.0.4 lib/pakyow/application/behavior/ui/recording.rb
pakyow-ui-1.0.3 lib/pakyow/application/behavior/ui/recording.rb
pakyow-ui-1.0.2 lib/pakyow/application/behavior/ui/recording.rb
pakyow-ui-1.0.1 lib/pakyow/application/behavior/ui/recording.rb
pakyow-ui-1.0.0 lib/pakyow/application/behavior/ui/recording.rb