14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/generators/nayati/operation/operation_generator.rb', line 14
def generate_operation
raise "Operation and workflow name must be passed" unless args.size == 2
workflow_name = args.first
operation_name = args.last
workflow_namespace = Nayati::NameBasedConstantable.underscored_name(workflow_name)
operation_namespace = Nayati::NameBasedConstantable.underscored_name(operation_name)
master_worflow = Nayati::MasterWorkflow.new(workflow_name)
raise 'Please generate workflow first' unless master_worflow.exists?
master_operation = Nayati::MasterOperation.new(master_worflow, operation_name)
raise 'Operation already exists' if master_operation.exists?
master_operation.save
workflow_constant_name = Nayati::NameBasedConstantable.name_as_constant(workflow_namespace)
operation_constant_name = Nayati::NameBasedConstantable.name_as_constant(operation_namespace)
operation_file_path = "#{Rails.root}/app/nayati_operations/#{workflow_namespace}_nayati_workflow/#{operation_namespace}_nayati_operation.rb"
copy_file "operation_template.txt", operation_file_path
inject_into_file operation_file_path, " #{workflow_constant_name}NayatiWorkflow", after: 'module'
inject_into_file operation_file_path, "#{operation_constant_name}NayatiOperation ", after: 'class '
end
|