Module: PgKingdom::ColumnsHelper
- Defined in:
- lib/pgkingdom/columns_helper.rb
Overview
Internally used to extend Arrays of columns in tables.
Instance Method Summary collapse
-
#add(name, type, opts) ⇒ Array<Hash{Symbol=>(Numeric|Symbol|String|Hash)}>
Adds column definition hash to array.
-
#available?(type) ⇒ Boolean
Checks if provided type is valid PostgreSQL data type.
-
#defined?(name) ⇒ Boolean
Checks if column defined in table.
-
#join ⇒ String
Joins columns for a statement.
Instance Method Details
#add(name, type, opts) ⇒ Array<Hash{Symbol=>(Numeric|Symbol|String|Hash)}>
Adds column definition hash to array.
27 28 29 |
# File 'lib/pgkingdom/columns_helper.rb', line 27 def add(name, type, opts) self << { :name => name, :type => type, :options => opts } end |
#available?(type) ⇒ Boolean
Checks if provided type is valid PostgreSQL data type.
21 22 23 |
# File 'lib/pgkingdom/columns_helper.rb', line 21 def available?(type) PgKingdom.available_data_types.include? type end |
#defined?(name) ⇒ Boolean
Checks if column defined in table.
32 33 34 |
# File 'lib/pgkingdom/columns_helper.rb', line 32 def defined?(name) select { |a| a[:name] == name }.any? end |
#join ⇒ String
Joins columns for a statement.
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/pgkingdom/columns_helper.rb', line 8 def join map do |col| opt_string = "" # Flags = col[:options] .extend OptionsHelper "#{col[:name]} #{col[:type].upcase}#{.join}" end.join(",\n\s\s") end |