Class: Oraora::Meta::Column

Inherits:
Object
  • Object
show all
Defined in:
lib/oraora/meta/column.rb

Constant Summary collapse

CHAR_USED_MAP =
{ 'B' => 'BYTE', 'C' => 'CHAR' }

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(schema, relation, name, attributes = {}) ⇒ Column

Returns a new instance of Column.



7
8
9
10
11
12
# File 'lib/oraora/meta/column.rb', line 7

def initialize(schema, relation, name, attributes = {})
  @schema = schema
  @relation = relation
  @name = name
  attributes.each { |k, v| instance_variable_set("@#{k}".to_sym, v) }
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



5
6
7
# File 'lib/oraora/meta/column.rb', line 5

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/oraora/meta/column.rb', line 5

def name
  @name
end

Instance Method Details

#describe(options = {}) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/oraora/meta/column.rb', line 14

def describe(options = {})
  "    Column \#{@schema}.\#{@relation}.\#{@name}\n    Id:           \#{@id}\n    Type:         \#{display_type}\n  HERE\nend\n".reset_indentation

#display_typeObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/oraora/meta/column.rb', line 26

def display_type
  case @type
    when 'NUMBER'
      case
        when !@precision && !@scale then "NUMBER"
        when !@precision && @scale == 0 then "INTEGER"
        when @scale == 0 then "NUMBER(#{@precision})"
        else "NUMBER(#{@precision},#{@scale})"
      end
    when 'CHAR', 'NCHAR'
      @char_length == 1 ? 'CHAR' : "CHAR(#{@char_length} #{@char_used})"
    when 'VARCHAR', 'VARCHAR2', 'NVARCHAR2'
      "#{@type}(#{@char_length} #{CHAR_USED_MAP[@char_used]})"
    else
      @type
  end
end

#list(options = {}, filter = nil) ⇒ Object

Raises:



22
23
24
# File 'lib/oraora/meta/column.rb', line 22

def list(options = {}, filter = nil)
  raise NotApplicable, "Nothing to list for column"
end