Class: SOULs::Generate

Inherits:
Thor
  • Object
show all
Defined in:
lib/souls/cli/generate/job.rb,
lib/souls/cli/generate/edge.rb,
lib/souls/cli/generate/type.rb,
lib/souls/cli/generate/index.rb,
lib/souls/cli/generate/query.rb,
lib/souls/cli/generate/manager.rb,
lib/souls/cli/generate/mutation.rb,
lib/souls/cli/generate/resolver.rb,
lib/souls/cli/generate/rspec_job.rb,
lib/souls/cli/generate/connection.rb,
lib/souls/cli/generate/application.rb,
lib/souls/cli/generate/rspec_query.rb,
lib/souls/cli/generate/rspec_factory.rb,
lib/souls/cli/generate/rspec_manager.rb,
lib/souls/cli/generate/rspec_mutation.rb,
lib/souls/cli/generate/rspec_resolver.rb

Instance Method Summary collapse

Instance Method Details

#connection(class_name) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/souls/cli/generate/connection.rb', line 4

def connection(class_name)
  file_dir = "./app/graphql/types/connections/"
  FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
  singularized_class_name = class_name.underscore.singularize
  file_path = "./app/graphql/types/connections/#{singularized_class_name}_connection.rb"
  File.open(file_path, "w") do |f|
    f.write("      class Types::\#{singularized_class_name.camelize}Connection < Types::BaseConnection\n        edge_type(Types::\#{singularized_class_name.camelize}Edge)\n      end\n    TEXT\n  end\n  SOULs::Painter.create_file(file_path.to_s)\n  file_path\nend\n")

#edge(class_name) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/souls/cli/generate/edge.rb', line 4

def edge(class_name)
  file_dir = "./app/graphql/types/edges"
  FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
  singularized_class_name = class_name.underscore.singularize
  file_path = "./app/graphql/types/edges/#{singularized_class_name}_edge.rb"
  File.open(file_path, "w") do |f|
    f.write("      class Types::\#{singularized_class_name.camelize}Edge < Types::BaseEdge\n        node_type(Types::\#{singularized_class_name.camelize}Type)\n      end\n    TEXT\n  end\n  SOULs::Painter.create_file(file_path.to_s)\n  file_path\nend\n")

#job(class_name) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'lib/souls/cli/generate/job.rb', line 5

def job(class_name)
  if options[:mailer]
    create_job_mailer_type(class_name)
    mailgun_mailer(class_name)
  else
    create_job_type(class_name)
    create_job(class_name)
  end
  SOULs::Generate.new.invoke(:rspec_job, [class_name], { mailer: options[:mailer] })
end

#manager(class_name) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'lib/souls/cli/generate/manager.rb', line 5

def manager(class_name)
  singularized_class_name = class_name.underscore.singularize
  current_path = FileUtils.pwd
  unless current_path.split("/").last == "api" || current_path.split("/").last == "souls"
    raise(StandardError, "You Are at Wrong Directory! Please Go to Api Directory!")
  end

  create_manager(class_name, options[:mutation])
  SOULs::Generate.new.invoke(:rspec_manager, [singularized_class_name], { mutation: options[:mutation] })
end

#mutation(class_name) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/souls/cli/generate/mutation.rb', line 4

def mutation(class_name)
  singularized_class_name = class_name.singularize

  Dir.chdir(SOULs.get_api_path.to_s) do
    file_dir = "./app/graphql/mutations/base"
    FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
    file_path = "./app/graphql/mutations/base/#{singularized_class_name}/create_#{singularized_class_name}.rb"
    return "Mutation already exist! #{file_path}" if File.exist?(file_path)

    create_mutation(class_name: singularized_class_name)
    update_mutation(class_name: singularized_class_name)
    delete_mutation(class_name: singularized_class_name)
    destroy_delete_mutation(class_name: singularized_class_name)
  end
end

#query(class_name) ⇒ Object



4
5
6
7
8
9
# File 'lib/souls/cli/generate/query.rb', line 4

def query(class_name)
  file_dir = "./app/graphql/queries/"
  FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
  singularized_class_name = class_name.singularize
  create_individual_query(class_name: singularized_class_name)
end

#resolver(class_name) ⇒ Object

Raises:

  • (StandardError)


4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/souls/cli/generate/resolver.rb', line 4

def resolver(class_name)
  singularized_class_name = class_name.singularize.underscore
  file_path = "./app/graphql/resolvers/#{singularized_class_name}_search.rb"
  raise(StandardError, "Resolver already exist! #{file_path}") if File.exist?(file_path)

  resolver_head(class_name: singularized_class_name)
  resolver_params(class_name: singularized_class_name)
  resolver_after_params(class_name: singularized_class_name)
  resolver_before_end(class_name: singularized_class_name)
  resolver_end(class_name: singularized_class_name)
  SOULs::Painter.create_file(file_path.to_s)
  file_path
end

#rspec_factory(class_name) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/souls/cli/generate/rspec_factory.rb', line 4

def rspec_factory(class_name)
  file_path = "./spec/factories/#{class_name.pluralize}.rb"
  return "RspecFactory already exist! #{file_path}" if File.exist?(file_path)

  singularized_class_name = class_name.singularize
  rspec_factory_head(class_name: singularized_class_name)
  rspec_factory_params(class_name: singularized_class_name)
  rspec_factory_end(class_name: singularized_class_name)
  SOULs::Painter.create_file(file_path.to_s)
  file_path
end

#rspec_job(class_name) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/souls/cli/generate/rspec_job.rb', line 5

def rspec_job(class_name)
  singularized_class_name = class_name.underscore.singularize
  file_dir = "./spec/queries/jobs/"
  FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
  file_path = "#{file_dir}/#{singularized_class_name}_spec.rb"
  return "RspecJob already exist! #{file_path}" if File.exist?(file_path)

  if options[:mailer]
    File.open(file_path, "w") do |f|
      f.write("        RSpec.describe(\"\#{singularized_class_name.camelize}\") do\n          describe \"Define \#{singularized_class_name.camelize}\" do\n\n            let(:query) do\n              %(query {\n                \#{singularized_class_name.camelize(:lower)} {\n                    response\n                  }\n                }\n              )\n            end\n\n            subject(:result) do\n              SOULsApiSchema.execute(query).as_json\n            end\n\n            it \"return \#{singularized_class_name.camelize} response\" do\n              allow_any_instance_of(::Mailgun::Client).to(receive(:send_message).and_return(true))\n              a1 = result.dig(\"data\", \"\#{singularized_class_name.camelize(:lower)}\")\n              expect(a1).not_to be_empty\n              expect(a1).to(include(\"response\" => be_a(String)))\n            end\n          end\n        end\n      TEXT\n    end\n  else\n    File.open(file_path, \"w\") do |f|\n      f.write(<<~TEXT)\n        RSpec.describe(\"\#{singularized_class_name.camelize}\") do\n          describe \"Define \#{singularized_class_name.camelize}\" do\n\n            let(:query) do\n              %(query {\n                \#{singularized_class_name.camelize(:lower)} {\n                    response\n                  }\n                }\n              )\n            end\n\n            subject(:result) do\n              SOULsApiSchema.execute(query).as_json\n            end\n\n            it \"return \#{singularized_class_name.camelize} response\" do\n              a1 = result.dig(\"data\", \"\#{singularized_class_name.camelize(:lower)}\")\n              expect(a1).not_to be_empty\n              expect(a1).to(include(\"response\" => be_a(String)))\n            end\n          end\n        end\n      TEXT\n    end\n  end\n  SOULs::Painter.create_file(file_path.to_s)\n  file_path\nend\n")

#rspec_manager(class_name) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/souls/cli/generate/rspec_manager.rb', line 5

def rspec_manager(class_name)
  singularized_class_name = class_name.underscore.singularize
  file_dir = "./spec/managers/#{singularized_class_name}_manager"
  FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
  file_path = "#{file_dir}/#{options[:mutation]}_spec.rb"
  return "RspecManager already exist! #{file_path}" if File.exist?(file_path)

  File.open(file_path, "w") do |f|
    f.write("      RSpec.describe(\"\#{options[:mutation].singularize.camelize}\") do\n        describe \"Define \#{options[:mutation].singularize.camelize}\" do\n\n          let(:mutation) do\n            %(mutation {\n              \#{options[:mutation].singularize.camelize(:lower)}(input: {\n                argument: \"argument test!\"\n              }) {\n                  response\n                }\n              }\n            )\n          end\n\n          subject(:result) do\n            SOULsApiSchema.execute(mutation).as_json\n          end\n\n          it \"return User response\" do\n            begin\n              a1 = result.dig(\"data\", \"\#{options[:mutation].singularize.camelize(:lower)}\", \"response\")\n              raise unless a1.present?\n            rescue StandardError\n              raise(StandardError, result)\n            end\n            expect(a1).to(eq(\"success!\"))\n          end\n        end\n      end\n    TEXT\n  end\n  SOULs::Painter.create_file(file_path.to_s)\n  file_path\nend\n")

#rspec_mutation(class_name) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/souls/cli/generate/rspec_mutation.rb', line 4

def rspec_mutation(class_name)
  singularized_class_name = class_name.singularize
  file_path = "./spec/mutations/base/#{singularized_class_name}_spec.rb"
  return "RspecMutation already exist! #{file_path}" if File.exist?(file_path)

  rspec_mutation_head(class_name: singularized_class_name)
  rspec_mutation_after_head(class_name: singularized_class_name)
  rspec_mutation_params(class_name: singularized_class_name)
  rspec_mutation_params_response(class_name: singularized_class_name)
  rspec_mutation_end(class_name: singularized_class_name)
  SOULs::Painter.create_file(file_path.to_s)
  file_path
rescue StandardError => e
  raise(StandardError, e)
end

#rspec_query(class_name) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/souls/cli/generate/rspec_query.rb', line 4

def rspec_query(class_name)
  singularized_class_name = class_name.singularize
  file_path = "./spec/queries/#{singularized_class_name}_spec.rb"
  return "RspecQuery already exist! #{file_path}" if File.exist?(file_path)

  rspec_query_head(singularized_class_name)
  rspec_query_after_head(singularized_class_name)
  rspec_query_params(singularized_class_name)
  rspec_query_end(singularized_class_name)
  SOULs::Painter.create_file(file_path.to_s)
  file_path
end

#rspec_resolver(class_name) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/souls/cli/generate/rspec_resolver.rb', line 4

def rspec_resolver(class_name)
  singularized_class_name = class_name.singularize
  file_path = "./spec/resolvers/#{singularized_class_name}_search_spec.rb"
  return "Resolver already exist! #{file_path}" if File.exist?(file_path)

  rspec_resolver_head(singularized_class_name)
  rspec_resolver_after_head(singularized_class_name)
  rspec_resolver_params(singularized_class_name)
  rspec_resolver_end(singularized_class_name)
  SOULs::Painter.create_file(file_path.to_s)
  file_path
end

#scaffold(class_name) ⇒ Object



4
5
6
7
8
# File 'lib/souls/cli/generate/application.rb', line 4

def scaffold(class_name)
  singularized_class_name = class_name.singularize
  run_scaffold(singularized_class_name)
  true
end

#scaffold_allObject



11
12
13
14
15
16
17
# File 'lib/souls/cli/generate/application.rb', line 11

def scaffold_all
  puts(Paint["Let's Go SOULs AUTO CRUD Assist!\n", :cyan])
  SOULs.get_tables.each do |table|
    SOULs::Generate.new.invoke(:scaffold, [table.singularize], {})
  end
  true
end

#type(class_name) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/souls/cli/generate/type.rb', line 4

def type(class_name)
  singularized_class_name = class_name.singularize
  file_path = "./app/graphql/types/#{singularized_class_name}_type.rb"
  return "Type already exist! #{file_path}" if File.exist?(file_path)

  create_type_head(class_name: singularized_class_name)
  create_type_params(class_name: singularized_class_name)
  create_type_end(class_name: singularized_class_name)
  SOULs::Painter.create_file(file_path.to_s)
  file_path
end