Class: Ibrain::Graphql::ResolversGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Ibrain::Graphql::ResolversGenerator
- Includes:
- Core
- Defined in:
- lib/generators/ibrain/graphql/resolvers_generator.rb
Overview
TODO: What other options should be supported?
Direct Known Subclasses
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.
-
#resolver_name ⇒ Object
readonly
Returns the value of attribute resolver_name.
Instance Method Summary collapse
- #create_resolver_file ⇒ Object
-
#initialize(args, *options) ⇒ ResolversGenerator
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) ⇒ ResolversGenerator
:nodoc:
23 24 25 26 27 28 29 |
# File 'lib/generators/ibrain/graphql/resolvers_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/resolvers_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/resolvers_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/resolvers_generator.rb', line 31 def model_name @model_name end |
#resolver_name ⇒ Object (readonly)
Returns the value of attribute resolver_name.
31 32 33 |
# File 'lib/generators/ibrain/graphql/resolvers_generator.rb', line 31 def resolver_name @resolver_name end |
Instance Method Details
#create_resolver_file ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/generators/ibrain/graphql/resolvers_generator.rb', line 33 def create_resolver_file if @behavior == :revoke log :gsub, "#{[:directory]}/types/query_type.rb" else create_resolver_root_type end if [:model].present? system("bundle exec rails generate ibrain:graphql:object #{[:model].underscore}") end template "resolvers.erb", "#{[:directory]}/resolvers/#{file_name}.rb" template "aggregate.erb", "#{[:directory]}/resolvers/#{file_name}_aggregate.rb" return unless ::Ibrain::Config.is_auto_append_mutation in_root do gsub_file "#{[:directory]}/types/query_type.rb", / \# TODO: Add Resolvers as fields\s*\n/m, "" inject_into_file "#{[:directory]}/types/query_type.rb", "\n field :#{field_name}, resolver: Resolvers::#{resolver_name}\n field :#{field_name}_aggregate, resolver: Resolvers::#{resolver_name}Aggregate \n ", before: "end\nend", verbose: true, force: true end end |