Class: MutationGenerator
- Inherits:
-
Rails::Generators::NamedBase
- Object
- Rails::Generators::NamedBase
- MutationGenerator
show all
- Defined in:
- lib/generators/mutation/mutation_generator.rb
Defined Under Namespace
Classes: GeneratedAttribute
Instance Method Summary
collapse
Instance Method Details
#create_mutation_file ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/generators/mutation/mutation_generator.rb', line 10
def create_mutation_file
mutation_dir_path = 'app/mutations'
generator_path = mutation_dir_path + "/#{file_name}.rb"
Dir.mkdir(mutation_dir_path) unless File.exist?(mutation_dir_path)
set_local_assigns!
template 'mutation.erb', generator_path
spec_mutation_dir_path = 'spec/mutations/'
spec_generator_path = spec_mutation_dir_path + "/#{file_name}_spec.rb"
Dir.mkdir(spec_mutation_dir_path) if Dir.exist?('spec') && !File.exist?(spec_mutation_dir_path)
template 'mutation_spec.erb', spec_generator_path if Dir.exist?('spec')
end
|
#set_local_assigns! ⇒ Object
28
29
30
31
32
33
34
|
# File 'lib/generators/mutation/mutation_generator.rb', line 28
def set_local_assigns!
ins = inputs.clone
attributes = ins.map { |i| GeneratedAttribute.parse(i) }
@required = attributes.select { |a| a.input_type == 'required' }
@optional = attributes.select { |a| a.input_type == 'optional' }
@klass_name = file_name.camelize
end
|