Sha256: c6cfc27dd81a7ae9afe6de51481889d2dd2f28c70142b15a2e53c9e848edef74

Contents?: true

Size: 1.17 KB

Versions: 6

Compression:

Stored size: 1.17 KB

Contents

require "dry/inflector"

module WebClient
  module Actions
    # This class renders a given component.
    # First it looks for plugins that override default behavior
    # If they don't exist then it renders the base components
    class Resolver
      extend Voom::Presenters::Pluggable
      include_plugins(:WebClientActions)

      def initialize(comp, action)
        @comp = comp
        @action = action
        initialize_plugins
      end

      def resolve
        return method(:"action_data_#{@action.type}") if respond_to?(:"action_data_#{@action.type}")
        require_relative "#{@action.type}"
        # Delegate the action data to each action class
        # [Type, URL, Options, Params] these are passed into javascript event/action class constructors
        # Only the type need be canonical, the rest is defined between this class and its javascript
        ::WebClient::Actions.const_get(inflector.camelize(@action.type)).new
      end

      private

      def initialize_plugins
        self.class.include_plugins(:WebClientActions, plugins: @comp.send(:_plugins_))
      end

      def inflector
        @inflector ||= Dry::Inflector.new
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
voom-presenters-2.1.2 views/mdc/components/actions/resolver.rb
voom-presenters-2.1.0 views/mdc/components/actions/resolver.rb
voom-presenters-2.0.3 views/mdc/components/actions/resolver.rb
voom-presenters-2.0.2 views/mdc/components/actions/resolver.rb
voom-presenters-2.0.1 views/mdc/components/actions/resolver.rb
voom-presenters-2.0.0 views/mdc/components/actions/resolver.rb