Module: PgKingdom::OptionsHelper

Defined in:
lib/pgkingdom/options_helper.rb

Overview

Internally used to extend Arrays of column options in tables.

Instance Method Summary collapse

Instance Method Details

#joinString

Joins options for a column.

Returns:

  • (String)

    column options.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/pgkingdom/options_helper.rb', line 6

def join
  options = clone
  numerics = []
  result = options.map do |option|
    case option
    when Numeric
      numerics << option
      nil
    when Hash
      option
        .map { |opt, value| option_to_sql opt, value }
        .join ' '
    else
      option_to_sql option
    end
  end

  result.reject! { |opt| opt.nil? }
  result = result.join(' ')
  numerics.any? ? "(#{numerics.join(', ')}) #{result.lstrip}" : result
end