Class: TrailblazerGen::OperationGenerator

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

Instance Method Summary collapse

Instance Method Details

#create_operation_filesObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/trailblazer_gen/generators/operation_generator.rb', line 16

def create_operation_files
  @module_name = name

  trailblazer_path = 'app/concepts/'
  module_path = "#{trailblazer_path}#{@module_name.underscore}/"
  operation_path = "#{module_path}operation/"

  operations.each do |operation|
    @single_contract = options[:'single-contract']
    @operation = operation.camelize

    operation_file = "#{operation_path}#{operation.underscore}.rb"
    template 'operation_template.rb', operation_file

    contract_file = if @single_contract
                      "#{module_path}/contract.rb"
                    else
                      "#{module_path}contract/#{operation.underscore}.rb"
                    end
    template 'contract_template.rb', contract_file
  end
end