Class: Ibrain::Graphql::MutationGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Ibrain::Graphql::MutationGenerator
- Includes:
- Core
- Defined in:
- lib/generators/ibrain/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.
-
#model_name ⇒ Object
readonly
Returns the value of attribute model_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, #create_repository_root_type, #create_resolver_root_type, included, #insert_root_type, #module_namespacing_when_supported, #schema_file_path
Constructor Details
#initialize(args, *options) ⇒ MutationGenerator
:nodoc:
23 24 25 26 27 28 29 |
# File 'lib/generators/ibrain/graphql/mutation_generator.rb', line 23 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.
31 32 33 |
# File 'lib/generators/ibrain/graphql/mutation_generator.rb', line 31 def field_name @field_name end |
#file_name ⇒ Object (readonly)
Returns the value of attribute file_name.
31 32 33 |
# File 'lib/generators/ibrain/graphql/mutation_generator.rb', line 31 def file_name @file_name end |
#model_name ⇒ Object (readonly)
Returns the value of attribute model_name.
31 32 33 |
# File 'lib/generators/ibrain/graphql/mutation_generator.rb', line 31 def model_name @model_name end |
#mutation_name ⇒ Object (readonly)
Returns the value of attribute mutation_name.
31 32 33 |
# File 'lib/generators/ibrain/graphql/mutation_generator.rb', line 31 def mutation_name @mutation_name end |
Instance Method Details
#create_mutation_file ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/generators/ibrain/graphql/mutation_generator.rb', line 33 def create_mutation_file if @behavior == :revoke log :gsub, "#{[:directory]}/types/mutation_type.rb" else create_mutation_root_type end if [:model].present? system("bundle exec rails generate ibrain:graphql:object #{[:model].underscore}") end template "mutation.erb", "#{[:directory]}/mutations/#{file_name}.rb" return unless ::Ibrain::Config.is_auto_append_mutation 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", "\n field :#{field_name}, mutation: Mutations::#{mutation_name} \n ", before: "end\nend", verbose: true, force: true end end |