Class: Gaskit::Generators::OperationGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Defined in:
lib/generators/gaskit/operation/operation_generator.rb

Overview

A Rails generator for creating new operation classes that inherit from Gaskit::Operation, Gaskit::Service, or Gaskit::Query, depending on the specified --type option.

This generator supports namespaced operations and places them under app/operations.

Examples:

Generate a base operation

rails generate gaskit:operation CreateUser

Generate a service operation

rails generate gaskit:operation CreateUser --type=service

Generate a query operation

rails generate gaskit:operation FetchUsers --type=query

See Also:

  • for the ERB template used.

Direct Known Subclasses

QueryGenerator, ServiceGenerator

Constant Summary collapse

SUPPORTED_TYPES =
%w[base service query].freeze

Instance Method Summary collapse

Instance Method Details

#create_operation_fileObject



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/generators/gaskit/operation/operation_generator.rb', line 38

def create_operation_file
  validate_type!

  subdir = case options["type"]
           when "service" then "services"
           when "query" then "queries"
           else "operations"
           end

  template "operation.rb.tt", File.join("app", subdir, class_path, "#{file_name}.rb")
end

#validate_type!Object

Raises:



32
33
34
35
36
# File 'lib/generators/gaskit/operation/operation_generator.rb', line 32

def validate_type!
  return if SUPPORTED_TYPES.include?(options["type"])

  raise ArgumentError, "Invalid type: #{options["type"]}. Supported types are: #{SUPPORTED_TYPES.join(", ")}"
end