Sha256: 7eee5a0ef07ab3ff34af79b7bd9cd506115929b695210595e4ead6914b3f3885

Contents?: true

Size: 871 Bytes

Versions: 18

Compression:

Stored size: 871 Bytes

Contents

module Screengem
  module Factories
    #
    # Knows how to create a Task from a task name.
    #
    class TaskFactory < BasicObject
      include ::Singleton

      def method_missing(task_name, *args) # rubocop:disable Style/MethodMissingSuper
        task_class_name = "#{task_name}_task".camelize
        task_class = "#{task_scope}::#{task_class_name}".constantize

        task_class.new(*args)
      rescue => e
        TaskError.new(<<~MSG)
          Unable to create task: '#{task_class_name}'.
            Details: #{e.message}
        MSG
      end

      def respond_to_missing?(_task_name, *)
        true
      end

      class TaskError < ::Screengem::Task
        include FactoryCreationError

        skip_dampening
      end

      private

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

Version data entries

18 entries across 18 versions & 1 rubygems

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