Sha256: a9258ad809c79d95b49e4d6f56d81b20cc3f2b089249e819a4b9f52c74d2b24e

Contents?: true

Size: 1.74 KB

Versions: 33

Compression:

Stored size: 1.74 KB

Contents

module Souls
  class Generate < Thor
    desc "manager [MANAGER_NAME]", "Generate GraphQL Mutation Template"
    method_option :mutation, aliases: "--mutation", required: true, desc: "Mutation File Name"
    def manager(class_name)
      create_manager(class_name, options[:mutation])
      Souls::Generate.new.invoke(:manager_rbs, [singularized_class_name], { mutation: options[:mutation] })
      Souls::Generate.new.invoke(:rspec_manager, [singularized_class_name], { mutation: options[:mutation] })
    end

    private

    def create_manager(class_name, mutation)
      singularized_class_name = class_name.underscore.singularize
      file_dir = "./app/graphql/mutations/managers/#{singularized_class_name}_manager"
      FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
      file_path = "#{file_dir}/#{mutation}.rb"
      raise(StandardError, "Already Exist!") if File.exist?(file_path)

      File.open(file_path, "w") do |f|
        f.write(<<~TEXT)
          module Mutations
            module Managers::#{singularized_class_name.camelize}Manager
              class #{mutation.underscore.camelize} < BaseMutation
                description "#{mutation} description"
                ## Edit `argument` and `field`
                argument :argument, String, required: true

                field :response, String, null: false

                def resolve(args)
                  # Define Here
                  { response: "success!" }
                rescue StandardError => e
                  GraphQL::ExecutionError.new(e.message)
                end
              end
            end
          end
        TEXT
      end
      puts(Paint % ["Created file! : %{white_text}", :green, { white_text: [file_path.to_s, :white] }])
      file_path
    end
  end
end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
souls-1.10.3 lib/souls/cli/generate/manager.rb
souls-1.10.2 lib/souls/cli/generate/manager.rb
souls-1.10.1 lib/souls/cli/generate/manager.rb
souls-1.10.0 lib/souls/cli/generate/manager.rb
souls-1.9.17 lib/souls/cli/generate/manager.rb
souls-1.9.16 lib/souls/cli/generate/manager.rb
souls-1.9.15 lib/souls/cli/generate/manager.rb
souls-1.9.14 lib/souls/cli/generate/manager.rb
souls-1.9.12 lib/souls/cli/generate/manager.rb
souls-1.9.11 lib/souls/cli/generate/manager.rb
souls-1.9.10 lib/souls/cli/generate/manager.rb
souls-1.9.9 lib/souls/cli/generate/manager.rb
souls-1.9.8 lib/souls/cli/generate/manager.rb
souls-1.9.7 lib/souls/cli/generate/manager.rb
souls-1.9.6 lib/souls/cli/generate/manager.rb
souls-1.9.5 lib/souls/cli/generate/manager.rb
souls-1.9.4 lib/souls/cli/generate/manager.rb
souls-1.9.3 lib/souls/cli/generate/manager.rb
souls-1.9.2 lib/souls/cli/generate/manager.rb
souls-1.9.1 lib/souls/cli/generate/manager.rb