class JunglePath::DBModel::Column

Attributes

base_type[R]
foreign_key_table_name[R]
name[R]
override_type[R]
sequence[R]
tags[R]
type[R]

Public Class Methods

get_column_def_columns(column_definition, sequence) click to toggle source
# File lib/jungle_path/db_model/column.rb, line 100
def self.get_column_def_columns(column_definition, sequence)
  return audit_key(sequence) if column_definition.length == 1 and column_definition[0] == :audit_key
  return audit_user(sequence) if column_definition.length == 1 and column_definition[0] == :audit_user
  return killable(sequence) if column_definition.length == 1 and column_definition[0] == :killable
  return verification(sequence) if column_definition.length == 1 and column_definition[0] == :verification
  return audit_data(sequence) if column_definition.length == 1 and column_definition[0] == :audit_data
  normal(column_definition, (sequence))
end
new(sequence, name, type, primary_key=false, foreign_key=false, foreign_key_table_name=nil, not_null=false, unique=false, secure=false, alternate_key=false, calculated=false, desc=nil, index=nil, unique_index=nil, default_value=nil, tags=nil, override_type=nil) click to toggle source
# File lib/jungle_path/db_model/column.rb, line 7
def initialize(sequence, name, type, primary_key=false, foreign_key=false, foreign_key_table_name=nil, not_null=false, unique=false, secure=false, alternate_key=false, calculated=false, desc=nil, index=nil, unique_index=nil, default_value=nil, tags=nil, override_type=nil)
  @sequence = sequence
  @name = name
  @type = type
  @override_type = override_type
  @base_type = get_base_type(@type)
  @primary_key = primary_key
  @foreign_key = foreign_key
  @foreign_key_table_name = foreign_key_table_name
  @not_null = not_null
  @unique = unique
  @secure = secure
  @alternate_key = alternate_key
  @calculated = calculated
  @desc = desc
  @index = index
  @unique_index = unique_index
  @default_value = default_value
  @tags = tags
  @is_audit_column = audit_column_names.include? name
end

Private Class Methods

audit_data(sequence) click to toggle source
# File lib/jungle_path/db_model/column.rb, line 179
def self.audit_data(sequence)
  columns = [
    normal([:audit_data, :json], sequence)[0]]
end
audit_key(sequence) click to toggle source
# File lib/jungle_path/db_model/column.rb, line 149
def self.audit_key(sequence)
  columns = [
    normal([:created_at, :timestamp], sequence)[0],
    normal([:created_by_key_id, :foreign_key, :key], sequence+1)[0],
    normal([:updated_at, :timestamp], sequence+2)[0],
    normal([:updated_by_key_id, :foreign_key, :key], sequence+3)[0]]
end
audit_user(sequence) click to toggle source
# File lib/jungle_path/db_model/column.rb, line 157
def self.audit_user(sequence)
  columns = [
    normal([:created_at, :timestamp], sequence)[0],
    normal([:created_by_user_id, :foreign_key, :user], sequence+1)[0],
    normal([:updated_at, :timestamp], sequence+2)[0],
    normal([:updated_by_user_id, :foreign_key, :user], sequence+3)[0]]
end
killable(sequence) click to toggle source
# File lib/jungle_path/db_model/column.rb, line 165
def self.killable(sequence)
  columns = [
    normal([:active, :boolean], sequence)[0],
    normal([:effective_date, :date], sequence+1)[0],
    normal([:kill_date, :date], sequence+2)[0],
    normal([:kill_by_key_id, :foreign_key, :key], sequence+3)[0],
    normal([:kill_reason, :string], sequence+4)[0]]
end
normal(array, sequence) click to toggle source
# File lib/jungle_path/db_model/column.rb, line 120
def self.normal(array, sequence)
  name = array[0]
  type = array[1]
  #type = :integer if array.include? :primary_key
  #type = :integer if array.include? :foreign_key
  primary_key = array.include? :primary_key
  foreign_key = array.include? :foreign_key
  foreign_key_table_name = array[array.index(:foreign_key) + 1] if foreign_key
  not_null = ((array.include? :not_null) or primary_key)
  unique = array.include? :unique

  contains_unique_index = array.include? :unique_index
  unique_index = array[array.index(:unique_index) + 1] if contains_unique_index

  contains_index = array.include? :index
  index = array[array.index(:index) + 1] if contains_index

  secure = array.include? :secure
  alternate_key = array.include? :alternate_key
  calculated = array.include? :calculated
  desc = array[array.index(:desc) + 1] if array.include? :desc
  override_type = array[array.index(:override_type) + 1] if array.include? :override_type
  default_index = array.index(:default)
  default_value = array[default_index + 1] if default_index and default_index > 0
  tags = array[array.index(:tags) + 1] if array.include? :tags

  columns = [Column.new(sequence, name, type, primary_key, foreign_key, foreign_key_table_name, not_null, unique, secure, alternate_key, calculated, desc, index, unique_index, default_value, tags, override_type)]
end
verification(sequence) click to toggle source
# File lib/jungle_path/db_model/column.rb, line 174
def self.verification(sequence)
  columns = [
    normal([:verification, :json, :tags, [:verification, :approval]], sequence)[0]]
end

Public Instance Methods

alternate_key?() click to toggle source
# File lib/jungle_path/db_model/column.rb, line 33
def alternate_key?
  @alternate_key
end
audit_column_names() click to toggle source
# File lib/jungle_path/db_model/column.rb, line 61
def audit_column_names
   [:created_at, :updated_at, :created_by_key_id, :created_by_user_id, :updated_by_key_id, :updated_by_user_id].to_set
end
calculated=(value) click to toggle source
# File lib/jungle_path/db_model/column.rb, line 49
def calculated=(value)
  @calculated = value
end
calculated?() click to toggle source
# File lib/jungle_path/db_model/column.rb, line 45
def calculated?
  @calculated
end
default_value() click to toggle source
# File lib/jungle_path/db_model/column.rb, line 96
def default_value
  @default_value
end
desc() click to toggle source
# File lib/jungle_path/db_model/column.rb, line 84
def desc
  @desc
end
foreign_key?() click to toggle source
# File lib/jungle_path/db_model/column.rb, line 37
def foreign_key?
  @foreign_key
end
index() click to toggle source
# File lib/jungle_path/db_model/column.rb, line 88
def index
  @index
end
is_audit_column?() click to toggle source
# File lib/jungle_path/db_model/column.rb, line 65
def is_audit_column?
  @is_audit_column
end
not_null?() click to toggle source
# File lib/jungle_path/db_model/column.rb, line 41
def not_null?
  @not_null
end
primary_key?() click to toggle source
# File lib/jungle_path/db_model/column.rb, line 29
def primary_key?
  @primary_key
end
ruby_type() click to toggle source
# File lib/jungle_path/db_model/column.rb, line 69
def ruby_type
  return Integer if @type == :foreign_key
  return Integer if @type == :primary_key
  return String if @type == :string
  return Integer if @type == :integer
  return DateTime if @type == :timestamp
  return DateTime if @type == :timestamp_local
  return TrueClass if @type == :boolean
  return Date if @type == :date
  return String if @type == :json
  return String if @type == :jsonb
  return Float if @type == :float
  nil
end
secure?() click to toggle source
# File lib/jungle_path/db_model/column.rb, line 57
def secure?
  @secure
end
unique?() click to toggle source
# File lib/jungle_path/db_model/column.rb, line 53
def unique?
  @unique
end
unique_index() click to toggle source
# File lib/jungle_path/db_model/column.rb, line 92
def unique_index
  @unique_index
end

Private Instance Methods

get_base_type(type) click to toggle source
# File lib/jungle_path/db_model/column.rb, line 111
def get_base_type(type)
  base_type = type
  if type == :primary_key or type == :foreign_key
    base_type = :integer
  end
  base_type = override_type if override_type
  base_type
end