Sha256: 0debc80d0f4e35c6f4d630a01089508825bb956d9eba360ddfacec7b120ad188

Contents?: true

Size: 1.79 KB

Versions: 163

Compression:

Stored size: 1.79 KB

Contents

module Souls
  class Generate < Thor
    desc "resolver_rbs [CLASS_NAME]", "Generate GraphQL Resolver RBS from schema.rb"
    def resolver_rbs(class_name)
      singularized_class_name = class_name.underscore.singularize
      file_path = ""
      Dir.chdir(Souls.get_mother_path.to_s) do
        file_dir = "./sig/api/app/graphql/resolvers"
        FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
        file_path = "#{file_dir}/#{singularized_class_name}_search.rbs"
        raise(Thor::Error, "Mutation RBS already exist! #{file_path}") if File.exist?(file_path)

        File.open(file_path, "w") do |f|
          f.write(<<~TEXT)
            class Base
            end
            class #{singularized_class_name.camelize}Search < Base
              include SearchObject
              def self.scope: () ?{ () -> nil } -> [Hash[Symbol, untyped]]
              def self.type: (*untyped) -> String
              def self.option: (:filter, type: untyped, with: :apply_filter) -> String
                              | (:first, type: untyped, with: :apply_first) -> String
                              | (:skip, type: untyped, with: :apply_skip) -> String
              def self.description: (String) -> String
              def self.types: (*untyped) -> String
              def decode_global_key: (String value) -> Integer
              def apply_filter: (untyped scope, untyped value) -> untyped

              class #{singularized_class_name.camelize}Filter
                String: String
                Boolean: Boolean
                Integer: Integer
              end
            end
          TEXT
        end
      end
      puts(Paint % ["Created file! : %{white_text}", :green, { white_text: [file_path.to_s, :white] }])
      file_path
    rescue Thor::Error => e
      raise(Thor::Error, e)
    end
  end
end

Version data entries

163 entries across 163 versions & 1 rubygems

Version Path
souls-1.8.3 lib/souls/cli/generate/resolver_rbs.rb
souls-1.8.2 lib/souls/cli/generate/resolver_rbs.rb
souls-1.8.1 lib/souls/cli/generate/resolver_rbs.rb
souls-1.8.0 lib/souls/cli/generate/resolver_rbs.rb
souls-1.7.38 lib/souls/cli/generate/resolver_rbs.rb
souls-1.7.37 lib/souls/cli/generate/resolver_rbs.rb
souls-1.7.36 lib/souls/cli/generate/resolver_rbs.rb
souls-1.7.34 lib/souls/cli/generate/resolver_rbs.rb
souls-1.7.33 lib/souls/cli/generate/resolver_rbs.rb
souls-1.7.32 lib/souls/cli/generate/resolver_rbs.rb
souls-1.7.31 lib/souls/cli/generate/resolver_rbs.rb
souls-1.7.30 lib/souls/cli/generate/resolver_rbs.rb
souls-1.7.29 lib/souls/cli/generate/resolver_rbs.rb
souls-1.7.28 lib/souls/cli/generate/resolver_rbs.rb
souls-1.7.27 lib/souls/cli/generate/resolver_rbs.rb
souls-1.7.26 lib/souls/cli/generate/resolver_rbs.rb
souls-1.7.25 lib/souls/cli/generate/resolver_rbs.rb
souls-1.7.24 lib/souls/cli/generate/resolver_rbs.rb
souls-1.7.21 lib/souls/cli/generate/resolver_rbs.rb
souls-1.7.20 lib/souls/cli/generate/resolver_rbs.rb