Sha256: f36ea4a2a76fb25dd1111993f6760bf1d7fe33fbc02b19cd9c2b737e0503c9c6

Contents?: true

Size: 856 Bytes

Versions: 15

Compression:

Stored size: 856 Bytes

Contents

module Screengem
  module Factories
    #
    # Makes actions available to tasks.
    #
    class ActionFactory < BasicObject
      def method_missing(action_name, *args) # rubocop:disable Style/MethodMissingSuper
        action_class_name = raw_action_class_name(action_name).camelize
        action_class = "#{action_scope}::#{action_class_name}".constantize

        action_class.new(*args)
      rescue => e
        ActionError.new(<<~MSG)
          Unable to create action: '#{action_class_name}'.
            Details: #{e.message}
        MSG
      end

      def respond_to_missing?(_action_name, *)
        true
      end

      class ActionError < ::Screengem::Action
        include FactoryCreationError
      end

      private

      def action_scope
        @action_scope ||= ::Screengem.configuration.action_scope
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
screengem-0.9.1 lib/screengem/factories/action_factory.rb
screengem-0.9.0 lib/screengem/factories/action_factory.rb
screengem-0.8.1 lib/screengem/factories/action_factory.rb
screengem-0.8.0 lib/screengem/factories/action_factory.rb
screengem-0.7.3 lib/screengem/factories/action_factory.rb
screengem-0.7.2 lib/screengem/factories/action_factory.rb
screengem-0.7.1 lib/screengem/factories/action_factory.rb
screengem-0.6.0 lib/screengem/factories/action_factory.rb
screengem-0.5.0 lib/screengem/factories/action_factory.rb
screengem-0.4.0 lib/screengem/factories/action_factory.rb
screengem-0.3.0 lib/screengem/factories/action_factory.rb
screengem-0.2.0 lib/screengem/factories/action_factory.rb
screengem-0.1.2 lib/screengem/factories/action_factory.rb
screengem-0.1.1 lib/screengem/factories/action_factory.rb
screengem-0.1.0 lib/screengem/factories/action_factory.rb