Class: GraphqlScaffold::Generators::MutationGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Defined in:
lib/generators/graphql_scaffold/mutation_generator.rb

Instance Method Summary collapse

Instance Method Details

#create_admin_mutation_create_fileObject



20
21
22
23
24
25
26
27
28
29
# File 'lib/generators/graphql_scaffold/mutation_generator.rb', line 20

def create_admin_mutation_create_file
  if File.exist?(@generator_path)
    create_file_path = @generator_path + "/create_#{file_name}.rb"
    if File.exist?(create_file_path)
      p 'Create File already exist'
    else
      template 'mutation_create.haml', create_file_path
    end
  end
end

#create_admin_mutation_delete_fileObject



42
43
44
45
46
47
48
49
50
51
# File 'lib/generators/graphql_scaffold/mutation_generator.rb', line 42

def create_admin_mutation_delete_file
  if File.exist?(@generator_path)
    delete_file_path = @generator_path + "/delete_#{file_name}.rb"
    if File.exist?(delete_file_path)
      p 'Delete File already exist'
    else
      template 'mutation_delete.haml', delete_file_path
    end
  end
end

#create_admin_mutation_foldersObject



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/generators/graphql_scaffold/mutation_generator.rb', line 7

def create_admin_mutation_folders
  admin_mutation_dir_path = 'app/graphql/mutations/admin'
  generator_dir_path = admin_mutation_dir_path + ("/#{@module_name.underscore}" if @module_name.present?).to_s
  @generator_path = generator_dir_path + "/#{file_name}s"

  FileUtils.mkdir_p(admin_mutation_dir_path) unless File.exist?(admin_mutation_dir_path)
  if File.exist?(@generator_path)
    p 'Folder already exist'
  elsif Dir.mkdir(@generator_path)
    p 'Folder created successfully'
  end
end

#create_admin_mutation_update_fileObject



31
32
33
34
35
36
37
38
39
40
# File 'lib/generators/graphql_scaffold/mutation_generator.rb', line 31

def create_admin_mutation_update_file
  if File.exist?(@generator_path)
    update_file_path = @generator_path + "/update_#{file_name}.rb"
    if File.exist?(update_file_path)
      p 'Update File already exist'
    else
      template 'mutation_update.haml', update_file_path
    end
  end
end

#create_mutation_type_fileObject



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/generators/graphql_scaffold/mutation_generator.rb', line 53

def create_mutation_type_file
  mutation_type_dir_path = 'app/graphql/types/admin'
  generator_dir_path = mutation_type_dir_path
  generator_path = generator_dir_path + '/mutation_type.rb'

  FileUtils.mkdir_p(mutation_type_dir_path) unless File.exist?(mutation_type_dir_path)
  FileUtils.mkdir_p(generator_dir_path) unless File.exist?(generator_dir_path)

  if File.exist?(generator_path)
    file = File.open(generator_path)
    file_data = file.read
    new_file_data = file_data.insert(-15, "  has_admin_mutation :#{class_name}\n    ")
    File.write(file, new_file_data)
    p 'Write to query_type.rb successfully'
  else
    template 'mutation_type.haml', generator_path
  end
end

#create_test_fileObject



72
73
74
75
76
77
# File 'lib/generators/graphql_scaffold/mutation_generator.rb', line 72

def create_test_file
  test_dir_path = 'spec/requests/mutations'
  test_file_path = test_dir_path + "/#{file_name}_spec.rb"
  FileUtils.mkdir_p(test_dir_path) unless File.exist?(test_dir_path)
  template 'mutation_test.haml', test_file_path
end