17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/generators/module_component/module_component_generator.rb', line 17
def create_component
path = "modules/#{file_name}/app"
methods_hash = methods.to_h
method = methods_hash['method']
component_name = methods_hash['component_name'] || file_name
if COMPONENT_TYPES.include? method
template_name = method == 'model' ? "#{component_name}.rb" : "#{component_name}_#{method}.rb"
template "app/#{method.pluralize}/#{method}.rb.erb",
File.join(path, method.pluralize.to_s, file_name, 'v0', template_name.to_s), comp_name
if method == 'service'
template "app/#{method.pluralize}/configuration.rb.erb",
File.join(path, method.pluralize.to_s, file_name, 'v0', 'configuration.rb'), comp_name
end
else
$stdout.puts "\n#{method} is not a known generator command."\
"Commands allowed are controller, model, serializer and service\n"
end
end
|