Sha256: 5dbbf90bfe81a03812b5076717fadafaaf30c8ff2173ff75eecb198f11671e46

Contents?: true

Size: 1.04 KB

Versions: 160

Compression:

Stored size: 1.04 KB

Contents

module Souls
  class DB < Thor
    desc "create_migration_rbs [CLASS_NAME]", "Generate ActiveRecord Migration's RBS Template"
    def create_migration_rbs(class_name)
      file_path = ""
      Dir.chdir(Souls.get_mother_path.to_s) do
        file_dir = "./sig/api/db/migrate"
        FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
        pluralized_class_name = class_name.underscore.pluralize
        file_path = "#{file_dir}/create_#{pluralized_class_name}.rbs"
        File.open(file_path, "w") do |f|
          f.write(<<~TEXT)
            class Create#{pluralized_class_name.camelize}
              def change: () -> untyped
              def create_table: (:#{pluralized_class_name}) { (untyped) -> untyped } -> untyped
              def add_index: (:#{pluralized_class_name}, *untyped) -> untyped
            end
          TEXT
        end
        puts(Paint % ["Created file! : %{white_text}", :green, { white_text: [file_path.to_s, :white] }])
      end
      file_path
    rescue Thor::Error => e
      raise(Thor::Error, e)
    end
  end
end

Version data entries

160 entries across 160 versions & 1 rubygems

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