class Scheman::Schema::Field

Public Class Methods

new(field) click to toggle source
# File lib/scheman/schema.rb, line 77
def initialize(field)
  @field = field
end

Public Instance Methods

==(field) click to toggle source

@note Overridden @return [true, false]

# File lib/scheman/schema.rb, line 83
def ==(field)
  type == field.type && size == field.size && qualifiers == field.qualifiers
end
index() click to toggle source

@return [Hash] Index defined as a field qualifier

# File lib/scheman/schema.rb, line 118
def index
  @field[:qualifiers].find do |qualifier|
    case qualifier[:qualifier][:type]
    when "primary_key"
      break {
        column: name,
        name: nil,
        primary: true,
        type: nil,
      }
    when "unique_key"
      break {
        column: name,
        name: nil,
        primary: nil,
        type: nil,
        unique: true,
      }
    end
  end
end
name() click to toggle source

@return [String]

# File lib/scheman/schema.rb, line 93
def name
  @field[:name]
end
qualifiers() click to toggle source

@return [Array<Hash>] Sorted qualifiers, without index-related types

# File lib/scheman/schema.rb, line 111
def qualifiers
  @qualifiers ||= @field[:qualifiers].reject do |qualifier|
    %w[primary_key unique_key].include?(qualifier[:qualifier][:type])
  end
end
size() click to toggle source

@note Size can be 2 values but not supported yet @return [String, nil]

# File lib/scheman/schema.rb, line 106
def size
  @field[:size]
end
to_hash() click to toggle source

@return [Hash]

# File lib/scheman/schema.rb, line 88
def to_hash
  @field.merge(qualifiers: qualifiers)
end
type() click to toggle source

@return [String] Lower-cased type name @example

"varchar"
# File lib/scheman/schema.rb, line 100
def type
  @field[:type]
end