Sha256: 175a3af3ec1846f1715f864b595ee222b281cef8fde79384c1be853b4eaef609

Contents?: true

Size: 1.17 KB

Versions: 12

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 Coprl::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

12 entries across 12 versions & 1 rubygems

Version Path
coprl-3.0.0.beta.12 views/mdc/components/actions/resolver.rb
coprl-3.0.0.beta.11 views/mdc/components/actions/resolver.rb
coprl-3.0.0.beta.10 views/mdc/components/actions/resolver.rb
coprl-3.0.0.beta.9 views/mdc/components/actions/resolver.rb
coprl-3.0.0.beta.8 views/mdc/components/actions/resolver.rb
coprl-3.0.0.beta.7 views/mdc/components/actions/resolver.rb
coprl-3.0.0.beta.6 views/mdc/components/actions/resolver.rb
coprl-3.0.0.beta.5 views/mdc/components/actions/resolver.rb
coprl-3.0.0.beta.4 views/mdc/components/actions/resolver.rb
coprl-3.0.0.beta.3 views/mdc/components/actions/resolver.rb
coprl-3.0.0.beta.2 views/mdc/components/actions/resolver.rb
coprl-3.0.0.beta.1 views/mdc/components/actions/resolver.rb