class Purview::Columns::Base

Attributes

name[R]
opts[R]
table[R]

Public Class Methods

new(name, opts={}) click to toggle source
# File lib/purview/columns/base.rb, line 6
def initialize(name, opts={})
  @name = name.to_sym
  @opts = default_opts.merge(opts)
  @table = table_opt
end

Public Instance Methods

default() click to toggle source
# File lib/purview/columns/base.rb, line 12
def default
  opts[:default]
end
default?() click to toggle source
# File lib/purview/columns/base.rb, line 16
def default?
  !!default
end
eql?(other) click to toggle source
# File lib/purview/columns/base.rb, line 20
def eql?(other)
  self.class == other.class &&
    limit == other.limit &&
    name == other.name &&
    nullable == other.nullable &&
    primary_key == other.primary_key &&
    type == other.type
end
hash() click to toggle source
# File lib/purview/columns/base.rb, line 29
def hash
  default.hash +
    limit.hash +
    name.hash +
    nullable.hash +
    primary_key.hash +
    type.hash
end
limit() click to toggle source
# File lib/purview/columns/base.rb, line 38
def limit
  opts[:limit]
end
limit?() click to toggle source
# File lib/purview/columns/base.rb, line 42
def limit?
  !!limit
end
nullable() click to toggle source
# File lib/purview/columns/base.rb, line 46
def nullable
  [nil, true].include?(opts[:nullable])
end
nullable?() click to toggle source
# File lib/purview/columns/base.rb, line 50
def nullable?
  !!nullable
end
parse(value) click to toggle source
# File lib/purview/columns/base.rb, line 54
def parse(value)
  blank = blank?(value)
  raise %{Unexpected blank value for column: "#{name}"} if blank && !nullable?
  blank ? nil : type.parse(value)
end
primary_key() click to toggle source
# File lib/purview/columns/base.rb, line 60
def primary_key
  opts[:primary_key]
end
primary_key?() click to toggle source
# File lib/purview/columns/base.rb, line 64
def primary_key?
  !!primary_key
end
source_name() click to toggle source
# File lib/purview/columns/base.rb, line 68
def source_name
  (opts[:source_name] || name).to_sym
end
table=(value) click to toggle source
# File lib/purview/columns/base.rb, line 72
def table=(value)
  raise Purview::Exceptions::TableAlreadyAssignedForColumn.new(self) if table
  @table = value
end
type() click to toggle source
# File lib/purview/columns/base.rb, line 77
def type
  opts[:type] || Purview::Types::String
end

Private Instance Methods

default_opts() click to toggle source
# File lib/purview/columns/base.rb, line 87
def default_opts
  {}
end
table_opt() click to toggle source
# File lib/purview/columns/base.rb, line 91
def table_opt
  opts[:table]
end