Module: Graphql::Generators::Core

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/generators/graphql/core.rb', line 9

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



34
35
36
37
38
39
# File 'lib/generators/graphql/core.rb', line 34

def create_dir(dir)
  empty_directory(dir)
  if !options[:skip_keeps]
    create_file("#{dir}/.keep")
  end
end

#insert_root_type(type, name) ⇒ Object



19
20
21
22
23
24
25
26
27
28
# File 'lib/generators/graphql/core.rb', line 19

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 ⇒ Object



41
42
43
44
45
46
47
# File 'lib/generators/graphql/core.rb', line 41

def module_namespacing_when_supported
  if defined?(module_namespacing)
    module_namespacing { yield }
  else
    yield
  end
end

#schema_file_path ⇒ Object



30
31
32
# File 'lib/generators/graphql/core.rb', line 30

def schema_file_path
  "#{options[:directory]}/#{schema_name.underscore}.rb"
end