Class: Gritz::Generators::ControllerGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Defined in:
/home/runner/work/gritz/gritz/sources/gritz-rails/lib/generators/gritz/controller/controller_generator.rb

Overview

Generates a controller bound to an application's generated service.

Instance Method Summary collapse

Instance Method Details

#create_controller ⇒ Object

Raises:

  • (Thor::Error)


15
16
17
18
19
20
21
22
23
# File '/home/runner/work/gritz/gritz/sources/gritz-rails/lib/generators/gritz/controller/controller_generator.rb', line 15

def create_controller
  raise Thor::Error, "service must be a Ruby constant name" unless /\A[A-Z]\w*(?:::[A-Z]\w*)*\z/.match?(service_class_name)
  unless actions.all? { |action| /\A[a-z_]\w*\z/.match?(action.underscore) }
    raise Thor::Error, "action must be a Ruby method name"
  end

  template "controller.rb.tt", "app/rpc/#{file_path}_controller.rb"
  append_to_file "config/gritz.rb", "\nregister_controller #{class_name}Controller\n"
end