Class: RailsCosmos::Generators::OperationGenerator
- Inherits:
-
Rails::Generators::NamedBase
- Object
- Rails::Generators::NamedBase
- RailsCosmos::Generators::OperationGenerator
- Defined in:
- lib/generators/rails_cosmos/operation_generator.rb
Overview
This generator creates a new operation class within the ‘app/operations` directory. Optionally, you can specify a namespace, and it will create a subdirectory based on that namespace.
Example usage:
rails generate operation NAME NAMESPACE
If a namespace is provided, the generated operation will be placed inside a folder corresponding to the namespace within ‘app/operations`. If no namespace is provided, the operation will be created directly within the `app/operations` directory.
This generator also creates a test file for the operation. If RSpec is detected, the test will be placed under ‘spec/operations`, and if MiniTest is detected, it will be placed under `test/operations`. If neither test framework is detected, the test generation will be skipped with a warning.
Arguments:
NAME - The name of the operation (required).
NAMESPACE - The namespace for the operation (optional).
Example:
rails generate rails_cosmos:operation create_user admin
This will generate:
app/operations/admin/create_user.rb
spec/operations/admin/create_user_spec.rb (if RSpec is used)
or
test/operations/admin/create_user_test.rb (if MiniTest is used)
Instance Method Summary collapse
Instance Method Details
#create_operation_file ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/generators/rails_cosmos/operation_generator.rb', line 42 def create_operation_file operation_directory = operation_directory_path operation_file = "#{operation_directory}/#{file_name}.rb" empty_directory operation_directory template "operation_template.rb.tt", operation_file end |
#create_test_file ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'lib/generators/rails_cosmos/operation_generator.rb', line 50 def create_test_file if rspec_installed? create_rspec_test_file elsif minitest_installed? create_minitest_test_file else say_status("warning", "No supported test framework found. Skipping test file generation.", :yellow) end end |