module SchemaPlus::Columns::ActiveRecord::ConnectionAdapters::Column

SchemaPlus::Index adds several methods to Column

Attributes

model[W]

Public Instance Methods

as_json(options=nil) click to toggle source

The default as_jon includes all instance variables. but @model can't be dumped (it contains circular references)

# File lib/schema_plus/columns/active_record/connection_adapters/column.rb, line 44
def as_json(options=nil)
  instance_values.except "model", "adapter"
end
case_sensitive?() click to toggle source

Returns true if the column is in one or more indexes that are case sensitive. Will raise exception if IndexDefinition#case_sensitive? isn't defined, i.e. if schema_plus_pg_indexes hasn't been loaded.

# File lib/schema_plus/columns/active_record/connection_adapters/column.rb, line 38
def case_sensitive?
  indexes.any?{|i| i.case_sensitive?}
end
indexes() click to toggle source

Returns the list of IndexDefinition instances for each index that refers to this column. Returns an empty list if there are no such indexes.

# File lib/schema_plus/columns/active_record/connection_adapters/column.rb, line 15
def indexes
  @indexes ||= @model.indexes.select{|index| index.columns.include? self.name}
end
required_on() click to toggle source

Returns the circumstance in which the column must have a value:

nil     if the column may be null
:save   if the column has no default value
:update otherwise
# File lib/schema_plus/columns/active_record/connection_adapters/column.rb, line 52
def required_on
  if null
    nil
  elsif default.nil?
    :save
  else
    :update
  end
end
unique?() click to toggle source

Returns true if the column is in a unique index. See also unique_scope

# File lib/schema_plus/columns/active_record/connection_adapters/column.rb, line 30
def unique?
  indexes.any?{|i| i.unique}
end
unique_scope() click to toggle source

If the column is in a unique index, returns a list of names of other columns in the index. Returns an empty list if it's a single-column index. Returns nil if the column is not in a unique index.

# File lib/schema_plus/columns/active_record/connection_adapters/column.rb, line 22
def unique_scope
  if index = indexes.select{|i| i.unique}.sort_by{|i| i.columns.size}.first
    index.columns.reject{|name| name == self.name}
  end
end