Sha256: ad44410086187d7eb6b017356cc2de424c8c4527b0d784a8e973f78ffa008324

Contents?: true

Size: 1.71 KB

Versions: 85

Compression:

Stored size: 1.71 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)
      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}/#{options[: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 #{options[:mutation].underscore.camelize} < BaseMutation
                description "#{options[: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] }])
      Souls::Generate.new.invoke(:manager_rbs, [singularized_class_name], { mutation: options[:mutation] })
      Souls::Generate.new.invoke(:rspec_manager, [singularized_class_name], { mutation: options[:mutation] })
      file_path
    rescue Thor::Error => e
      raise(Thor::Error, e)
    end
  end
end

Version data entries

85 entries across 85 versions & 1 rubygems

Version Path
souls-1.3.8 lib/souls/cli/generate/manager.rb
souls-1.3.7 lib/souls/cli/generate/manager.rb
souls-1.3.6 lib/souls/cli/generate/manager.rb
souls-1.3.5 lib/souls/cli/generate/manager.rb
souls-1.3.4 lib/souls/cli/generate/manager.rb
souls-1.3.3 lib/souls/cli/generate/manager.rb
souls-1.3.2 lib/souls/cli/generate/manager.rb
souls-1.3.1 lib/souls/cli/generate/manager.rb
souls-1.3.0 lib/souls/cli/generate/manager.rb
souls-1.2.2 lib/souls/cli/generate/manager.rb
souls-1.2.1 lib/souls/cli/generate/manager.rb
souls-1.2.0 lib/souls/cli/generate/manager.rb
souls-1.1.2 lib/souls/cli/generate/manager.rb
souls-1.1.1 lib/souls/cli/generate/manager.rb
souls-1.1.0 lib/souls/cli/generate/manager.rb
souls-1.0.9 lib/souls/cli/generate/manager.rb
souls-1.0.8 lib/souls/cli/generate/manager.rb
souls-1.0.7 lib/souls/cli/generate/manager.rb
souls-1.0.6 lib/souls/cli/generate/manager.rb
souls-1.0.5 lib/souls/cli/generate/manager.rb