Sha256: ac08d4628502d491c483b83bce0f936b1ff06c8b56543c2d9d5ecbe8955de8ef

Contents?: true

Size: 767 Bytes

Versions: 2

Compression:

Stored size: 767 Bytes

Contents

module WebammToRails
  module Sources
    module Migrations
      class IndexDefinition
        class Presenter
          def initialize(table_name:, index:)
            @table_name = table_name
            @index = index
          end

          def render
            base_def = if @index.columns.size == 1
              "add_index :#{@table_name}, :#{@index.columns.first}"
            else
              "add_index :#{@table_name}, %i[#{@index.columns.join(' ')}]"
            end

            base_def += ", unique: true" if @index.unique

            base_def
          end

          private

          def index_name
            base_name = @index.columns.join('_')

            "#{base_name[0..19]}_idx"
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
webamm_to_rails-7.0.1 lib/webamm_to_rails/sources/migrations/index_definition/presenter.rb
webamm_to_rails-7.0.0 lib/webamm_to_rails/sources/migrations/index_definition/presenter.rb