Module: Ibrain::Graphql::Core
- Included in:
- MutationGenerator, ResolversGenerator, TypeGeneratorBase
- Defined in:
- lib/generators/ibrain/graphql/core.rb
Class Method Summary collapse
Instance Method Summary collapse
- #create_dir(dir) ⇒ Object
- #create_mutation_root_type ⇒ Object
- #create_repository_root_type ⇒ Object
- #create_resolver_root_type ⇒ Object
- #insert_root_type(type, name) ⇒ Object
- #module_namespacing_when_supported(&block) ⇒ Object
- #schema_file_path ⇒ Object
Class Method Details
.included(base) ⇒ Object
8 9 10 11 12 13 14 15 16 |
# File 'lib/generators/ibrain/graphql/core.rb', line 8 def self.included(base) base.send( :class_option, :directory, type: :string, default: "app/graphql", desc: "Directory where generated files should be saved" ) end |
Instance Method Details
#create_dir(dir) ⇒ Object
47 48 49 50 51 52 |
# File 'lib/generators/ibrain/graphql/core.rb', line 47 def create_dir(dir) empty_directory(dir) if ![:skip_keeps] create_file("#{dir}/.keep") end end |
#create_mutation_root_type ⇒ Object
29 30 31 32 |
# File 'lib/generators/ibrain/graphql/core.rb', line 29 def create_mutation_root_type create_dir("#{[:directory]}/mutations") insert_root_type('mutation', 'MutationType') end |
#create_repository_root_type ⇒ Object
39 40 41 |
# File 'lib/generators/ibrain/graphql/core.rb', line 39 def create_repository_root_type create_dir("app/repositories") end |
#create_resolver_root_type ⇒ Object
34 35 36 37 |
# File 'lib/generators/ibrain/graphql/core.rb', line 34 def create_resolver_root_type create_dir("#{[:directory]}/resolvers") insert_root_type('query', 'QueryType') end |
#insert_root_type(type, name) ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/generators/ibrain/graphql/core.rb', line 18 def insert_root_type(type, name) log :add_root_type, type sentinel = /< GraphQL::Schema\s*\n/m in_root do if File.exist?(schema_file_path) inject_into_file schema_file_path, " #{type}(Types::#{name})\n", after: sentinel, verbose: false, force: false end end end |
#module_namespacing_when_supported(&block) ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/generators/ibrain/graphql/core.rb', line 54 def module_namespacing_when_supported(&block) if defined?(module_namespacing) module_namespacing(&block) else yield end end |
#schema_file_path ⇒ Object
43 44 45 |
# File 'lib/generators/ibrain/graphql/core.rb', line 43 def schema_file_path "#{[:directory]}/#{schema_name.underscore}.rb" end |