class Oraora::Context

Constants

HIERARCHY
KEYS
RELATION_OBJECT_TYPES

Attributes

level[R]
user[R]

Public Class Methods

new(user = nil, hash = {}) click to toggle source
# File lib/oraora/context.rb, line 17
def initialize(user = nil, hash = {})
  @user = user
  set(hash)
end

Public Instance Methods

dup() click to toggle source
# File lib/oraora/context.rb, line 26
def dup
  su(@user)
end
eql?(other) click to toggle source
# File lib/oraora/context.rb, line 86
def eql?(other)
  key_hash == other.key_hash
end
hash() click to toggle source
# File lib/oraora/context.rb, line 82
def hash
  key_hash.hash
end
key_hash() click to toggle source
# File lib/oraora/context.rb, line 78
def key_hash
  Hash[ KEYS.collect { |key| [key, instance_variable_get("@#{key}")] } ].delete_if { |k, v| v.nil? }
end
prompt() click to toggle source
# File lib/oraora/context.rb, line 65
def prompt
  if @schema
    p = @user == @schema ? '~' : @schema
    level_2 = @object
    p += ".#{level_2}" if level_2
    level_3 = @column || @subprogram
    p += ".#{level_3}" if level_3
  else
    p = '/'
  end
  p
end
root() click to toggle source
# File lib/oraora/context.rb, line 50
def root
  set
end
set(hash = {}) click to toggle source
# File lib/oraora/context.rb, line 30
def set(hash = {})
  KEYS.each { |key| instance_variable_set("@#{key}", nil) }
  @level = nil
  traverse(hash)
end
su(user) click to toggle source
# File lib/oraora/context.rb, line 22
def su(user)
  self.class.new(user, key_hash)
end
traverse(hash) click to toggle source
# File lib/oraora/context.rb, line 36
def traverse(hash)
  while(!hash.empty?) do
    key = HIERARCHY[@level].detect { |k| hash[k] } or raise InvalidKey
    case key
      when :column then raise InvalidKey unless RELATION_OBJECT_TYPES.include?(@object_type)
      when :object then raise InvalidKey unless @object_type = hash.delete(:object_type)
      when :subprogram then raise InvalidKey unless @object_type == :package && @subprogram_type = hash.delete(:subprogram_type)
    end
    @level = key
    instance_variable_set("@#{key}", hash.delete(key))
  end
  self
end
up() click to toggle source
# File lib/oraora/context.rb, line 54
def up
  case @level
    when nil then return self
    when :subprogram then @subprogram_type = nil
    when :object then @object_type = nil
  end
  instance_variable_set("@#{level}", nil)
  @level = HIERARCHY.invert.detect { |k, v| k.include? @level }.last
  self
end