Class: Graphql::Generators::MutationGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Graphql::Generators::MutationGenerator
- Includes:
- Core
- Defined in:
- lib/generators/graphql/mutation_generator.rb
Overview
TODO: What other options should be supported?
Instance Attribute Summary collapse
-
#field_name ⇒ Object
readonly
Returns the value of attribute field_name.
-
#file_name ⇒ Object
readonly
Returns the value of attribute file_name.
-
#mutation_name ⇒ Object
readonly
Returns the value of attribute mutation_name.
Instance Method Summary collapse
- #create_mutation_file ⇒ Object
-
#initialize(args, *options) ⇒ MutationGenerator
constructor
:nodoc:.
Methods included from Core
#create_dir, #create_mutation_root_type, #insert_root_type, #schema_file_path
Constructor Details
#initialize(args, *options) ⇒ MutationGenerator
:nodoc:
19 20 21 22 23 24 25 |
# File 'lib/generators/graphql/mutation_generator.rb', line 19 def initialize(args, *) #:nodoc: # Unfreeze name in case it's given as a frozen string args[0] = args[0].dup if args[0].is_a?(String) && args[0].frozen? super assign_names!(name) end |
Instance Attribute Details
#field_name ⇒ Object (readonly)
Returns the value of attribute field_name.
27 28 29 |
# File 'lib/generators/graphql/mutation_generator.rb', line 27 def field_name @field_name end |
#file_name ⇒ Object (readonly)
Returns the value of attribute file_name.
27 28 29 |
# File 'lib/generators/graphql/mutation_generator.rb', line 27 def file_name @file_name end |
#mutation_name ⇒ Object (readonly)
Returns the value of attribute mutation_name.
27 28 29 |
# File 'lib/generators/graphql/mutation_generator.rb', line 27 def mutation_name @mutation_name end |
Instance Method Details
#create_mutation_file ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/generators/graphql/mutation_generator.rb', line 29 def create_mutation_file unless @behavior == :revoke create_mutation_root_type else log :gsub, "#{[:directory]}/types/mutation_type.rb" end template "mutation.erb", "#{[:directory]}/mutations/#{file_name}.rb" sentinel = /class .*MutationType\s*<\s*[^\s]+?\n/m in_root do gsub_file "#{[:directory]}/types/mutation_type.rb", / \# TODO\: Add Mutations as fields\s*\n/m, "" inject_into_file "#{[:directory]}/types/mutation_type.rb", " field :#{field_name}, mutation: Mutations::#{mutation_name}\n", after: sentinel, verbose: false, force: false end end |