Sha256: 29bcf60aae0df9f4c6fd052fe8d838890300fa09fb4c4d587b6d058096ae7f48

Contents?: true

Size: 1.74 KB

Versions: 14

Compression:

Stored size: 1.74 KB

Contents

module Souls
  class Generate < Thor
    desc "job_rbs [CLASS_NAME]", "Generate SOULs Job Mutation RBS Template"
    def job_rbs(class_name)
      file_path = ""
      worker_name = FileUtils.pwd.split("/").last
      Dir.chdir(Souls.get_mother_path.to_s) do
        singularized_class_name = class_name.underscore.singularize
        file_dir = "./sig/#{worker_name}/app/graphql/queries/"
        FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
        file_path = "#{file_dir}#{singularized_class_name}.rbs"
        sig_type_path = "./sig/#{worker_name}/app/graphql/types"
        FileUtils.mkdir_p(sig_type_path) unless Dir.exist?(sig_type_path)
        type_file_path = "#{sig_type_path}/#{singularized_class_name}_type.rbs"
        File.open(file_path, "w") do |f|
          f.write(<<~TEXT)
            module Queries
              class #{singularized_class_name.camelize} < BaseQuery
                def self.description: (String) -> untyped
                def self.field: (:response, String, null: false) -> untyped
                def self.type: (untyped, null: false) -> untyped
              end
            end
          TEXT
        end
        File.open(type_file_path, "w") do |f|
          f.write(<<~TEXT)
            module Types
              class #{singularized_class_name.camelize}Type < BaseObject
                def self.field: (:response, String, null: true) -> untyped
              end
            end
          TEXT
        end
        puts(Paint % ["Created file! : %{white_text}", :green, { white_text: [file_path.to_s, :white] }])
        puts(Paint % ["Created file! : %{white_text}", :green, { white_text: [type_file_path.to_s, :white] }])
      end
      file_path
    rescue Thor::Error => e
      raise(Thor::Error, e)
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
souls-1.8.3 lib/souls/cli/generate/job_rbs.rb
souls-1.8.2 lib/souls/cli/generate/job_rbs.rb
souls-1.8.1 lib/souls/cli/generate/job_rbs.rb
souls-1.8.0 lib/souls/cli/generate/job_rbs.rb
souls-1.7.38 lib/souls/cli/generate/job_rbs.rb
souls-1.7.37 lib/souls/cli/generate/job_rbs.rb
souls-1.7.36 lib/souls/cli/generate/job_rbs.rb
souls-1.7.34 lib/souls/cli/generate/job_rbs.rb
souls-1.7.33 lib/souls/cli/generate/job_rbs.rb
souls-1.7.32 lib/souls/cli/generate/job_rbs.rb
souls-1.7.31 lib/souls/cli/generate/job_rbs.rb
souls-1.7.30 lib/souls/cli/generate/job_rbs.rb
souls-1.7.29 lib/souls/cli/generate/job_rbs.rb
souls-1.7.28 lib/souls/cli/generate/job_rbs.rb