Sha256: d5d1cd0cf41aa754a1a2a4dd7b721eea266612a88ea3d031a911cc48adca24d2

Contents?: true

Size: 1.86 KB

Versions: 1

Compression:

Stored size: 1.86 KB

Contents

# frozen_string_literal: true

class DispatchJob < Rails::Generators::Base
  class Publisher < Rails::Generators::Base
    source_root File.expand_path('../templates/publisher', __FILE__)
    argument :handler_name, type: :string, required: true
    argument :publisher_name, type: :string, required: true

    class Rspec < Rails::Generators::Base
      source_root File.expand_path('../templates/publisher', __FILE__)
      argument :handler_name, type: :string, required: true
      argument :publisher_name, type: :string, required: true

      def generate_publisher_spec
        template "publisher_spec.rb.erb", "spec/publishers/#{publisher_name}_spec.rb"
      end
    end

    def generate_publisher
      template "publisher.rb.erb", "app/publishers/#{publisher_name}.rb"
    end

    hook_for :test_framework, in: "dispatch_job:publisher"
  end

  class Handler < Rails::Generators::Base
    source_root File.expand_path('../templates/handler', __FILE__)
    argument :handler_name, type: :string, required: true

    class Rspec < Rails::Generators::Base
      source_root File.expand_path('../templates/handler', __FILE__)
      argument :handler_name, type: :string, required: true

      def generate_handler_spec
        template "handler_spec.rb.erb", "spec/handlers/#{handler_name}_spec.rb"
      end
    end

    def generate_handler
      template "handler.rb.erb", "app/handlers/#{handler_name}.rb"
    end

    hook_for :test_framework, in: "dispatch_job:handler"
  end

  # source_root File.expand_path('../templates', __FILE__)

  class_option :publisher, default: :publisher, hide: true
  class_option :handler, default: :handler, hide: true

  argument :handler_name, type: :string

  hook_for :publisher do |publisher|
    invoke publisher, [handler_name, handler_name.underscore + "_publisher"]
  end

  hook_for :handler do |handler|
    invoke handler, [handler_name]
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dispatch-rider-2.2.0 lib/generators/dispatch_rider/job/dispatch_job_generator.rb