Skip to content

Commit

Permalink
Fix the default options of model_type and input generators
Browse files Browse the repository at this point in the history
By default, the `model_type` and `input` generators should generate class
and file names suffixed by 'model' or 'input', respectively. They should
allow over-writing the generated class/file name via the `--name` option
for people who want to break from the graphql-ruby generator conventions.

Fixes ajsharp#9
  • Loading branch information
ajsharp committed Jan 28, 2020
1 parent 07aac56 commit 41559b0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/generators/gql/input_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class InputGenerator < Rails::Generators::Base
class_option :namespace, type: :string, default: 'Types::Input'

def generate_input_type
name = options['name'] || model_name
name = options['name'].nil? ? "#{model_name}Input" : options['name']
superclass = options['superclass']

ignore = ['id', 'created_at', 'updated_at']
Expand All @@ -23,7 +23,7 @@ def generate_input_type
end

code = class_with_fields(options['namespace'], name, superclass, fields)
file_name = File.join(root_directory(options['namespace']), "#{name.underscore}_input.rb")
file_name = File.join(root_directory(options['namespace']), "#{name.underscore}.rb")

create_file file_name, code
end
Expand Down
4 changes: 2 additions & 2 deletions lib/generators/gql/model_type_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class ModelTypeGenerator < Rails::Generators::Base
class_option :namespace, type: :string, default: 'Types'

def type
name = options['name'] || model_name
name = options['name'].nil? ? "#{model_name}Type" : options['name']

superclass = options['superclass']

Expand All @@ -22,7 +22,7 @@ def type
end

code = class_with_fields(options['namespace'], name, superclass, fields)
file_name = File.join(root_directory(options['namespace']), "#{name.underscore}_type.rb")
file_name = File.join(root_directory(options['namespace']), "#{name.underscore}.rb")

create_file file_name, code
end
Expand Down

0 comments on commit 41559b0

Please sign in to comment.