Class: SOULs::Generate
- Inherits:
-
Thor
- Object
- Thor
- SOULs::Generate
- 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
- #connection(class_name) ⇒ Object
- #edge(class_name) ⇒ Object
- #job(class_name) ⇒ Object
- #manager(class_name) ⇒ Object
- #mutation(class_name) ⇒ Object
- #query(class_name) ⇒ Object
- #resolver(class_name) ⇒ Object
- #rspec_factory(class_name) ⇒ Object
- #rspec_job(class_name) ⇒ Object
- #rspec_manager(class_name) ⇒ Object
- #rspec_mutation(class_name) ⇒ Object
- #rspec_query(class_name) ⇒ Object
- #rspec_resolver(class_name) ⇒ Object
- #scaffold(class_name) ⇒ Object
- #scaffold_all ⇒ Object
- #type(class_name) ⇒ Object
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(<<~TEXT) class Types::#{singularized_class_name.camelize}Connection < Types::BaseConnection edge_type(Types::#{singularized_class_name.camelize}Edge) end TEXT end SOULs::Painter.create_file(file_path.to_s) file_path end |
#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(<<~TEXT) class Types::#{singularized_class_name.camelize}Edge < Types::BaseEdge node_type(Types::#{singularized_class_name.camelize}Type) end TEXT end SOULs::Painter.create_file(file_path.to_s) file_path end |
#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 [: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: [: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, [:mutation]) SOULs::Generate.new.invoke(:rspec_manager, [singularized_class_name], { mutation: [: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
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 [:mailer] File.open(file_path, "w") do |f| f.write(<<~TEXT) RSpec.describe("#{singularized_class_name.camelize}") do describe "Define #{singularized_class_name.camelize}" do let(:query) do %(query { #{singularized_class_name.camelize(:lower)} { response } } ) end subject(:result) do SOULsApiSchema.execute(query).as_json end it "return #{singularized_class_name.camelize} response" do allow_any_instance_of(::Mailgun::Client).to(receive(:send_message).and_return(true)) a1 = result.dig("data", "#{singularized_class_name.camelize(:lower)}") expect(a1).not_to be_empty expect(a1).to(include("response" => be_a(String))) end end end TEXT end else File.open(file_path, "w") do |f| f.write(<<~TEXT) RSpec.describe("#{singularized_class_name.camelize}") do describe "Define #{singularized_class_name.camelize}" do let(:query) do %(query { #{singularized_class_name.camelize(:lower)} { response } } ) end subject(:result) do SOULsApiSchema.execute(query).as_json end it "return #{singularized_class_name.camelize} response" do a1 = result.dig("data", "#{singularized_class_name.camelize(:lower)}") expect(a1).not_to be_empty expect(a1).to(include("response" => be_a(String))) end end end TEXT end end SOULs::Painter.create_file(file_path.to_s) file_path end |
#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}/#{[:mutation]}_spec.rb" return "RspecManager already exist! #{file_path}" if File.exist?(file_path) File.open(file_path, "w") do |f| f.write(<<~TEXT) RSpec.describe("#{[:mutation].singularize.camelize}") do describe "Define #{[:mutation].singularize.camelize}" do let(:mutation) do %(mutation { #{[:mutation].singularize.camelize(:lower)}(input: { argument: "argument test!" }) { response } } ) end subject(:result) do SOULsApiSchema.execute(mutation).as_json end it "return User response" do begin a1 = result.dig("data", "#{[:mutation].singularize.camelize(:lower)}", "response") raise unless a1.present? rescue StandardError raise(StandardError, result) end expect(a1).to(eq("success!")) end end end TEXT end SOULs::Painter.create_file(file_path.to_s) file_path end |
#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_all ⇒ Object
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 |