Class: ActiveFacts::RMap::Index
- Inherits:
-
Object
- Object
- ActiveFacts::RMap::Index
- Defined in:
- lib/activefacts/rmap/index.rb
Instance Method Summary collapse
-
#abbreviated_column_names(separator = "") ⇒ Object
An array of the names of the columns this index covers, with some lexical truncations.
-
#column_names(separator = "") ⇒ Object
An array of the names of the columns this index covers.
-
#columns ⇒ Object
Return the array of columns in this index.
-
#initialize(uc, on, over, columns, is_primary, is_unique = true) ⇒ Index
constructor
An Index arises from a uniqueness constraint and applies to a table, but because the UC may actually be over an object absorbed into the table, we must record that object also.
-
#is_primary ⇒ Object
Is this index the primary key for this table?.
-
#is_unique ⇒ Object
Is this index unique?.
-
#name ⇒ Object
This name is either the name explicitly assigned (if any) or is constructed to form a unique index name.
-
#on ⇒ Object
The table that the index is on.
-
#over ⇒ Object
If a non-mandatory reference was absorbed, only the non-nil instances are unique.
-
#real_name ⇒ Object
The name that was assigned (perhaps implicitly by NORMA).
-
#to_s ⇒ Object
:nodoc:.
-
#uniqueness_constraint ⇒ Object
The UniquenessConstraint that created this index.
-
#view_name ⇒ Object
The name of a view that can be created to enforce uniqueness over non-null key values.
Constructor Details
#initialize(uc, on, over, columns, is_primary, is_unique = true) ⇒ Index
An Index arises from a uniqueness constraint and applies to a table, but because the UC may actually be over an object absorbed into the table, we must record that object also. We record the columns it’s over, whether it’s primary (for ‘over’), and whether it’s unique (always, at present)
36 37 38 39 |
# File 'lib/activefacts/rmap/index.rb', line 36 def initialize(uc, on, over, columns, is_primary, is_unique = true) #:nodoc: @uniqueness_constraint, @on, @over, @columns, @is_primary, @is_unique = uc, on, over, columns, is_primary, is_unique end |
Instance Method Details
#abbreviated_column_names(separator = "") ⇒ Object
An array of the names of the columns this index covers, with some lexical truncations.
62 63 64 |
# File 'lib/activefacts/rmap/index.rb', line 62 def abbreviated_column_names(separator = "") columns.map{|column| column.name(separator).sub(/^#{over.name}/,'')} end |
#column_names(separator = "") ⇒ Object
An array of the names of the columns this index covers
57 58 59 |
# File 'lib/activefacts/rmap/index.rb', line 57 def column_names(separator = "") columns.map{|column| column.name(separator)} end |
#columns ⇒ Object
Return the array of columns in this index
23 |
# File 'lib/activefacts/rmap/index.rb', line 23 def columns; @columns; end |
#is_primary ⇒ Object
Is this index the primary key for this table?
26 |
# File 'lib/activefacts/rmap/index.rb', line 26 def is_primary; @is_primary; end |
#is_unique ⇒ Object
Is this index unique?
29 |
# File 'lib/activefacts/rmap/index.rb', line 29 def is_unique; @is_unique; end |
#name ⇒ Object
This name is either the name explicitly assigned (if any) or is constructed to form a unique index name.
47 48 49 50 51 52 53 54 |
# File 'lib/activefacts/rmap/index.rb', line 47 def name uc = @uniqueness_constraint r = real_name return r if r && r !~ /^(Ex|In)ternalUniquenessConstraint[0-9]+$/ (uc.is_preferred_identifier ? "PK_" : "IX_") + view_name + (uc.is_preferred_identifier ? "" : "By"+column_names*"") end |
#on ⇒ Object
The table that the index is on
16 |
# File 'lib/activefacts/rmap/index.rb', line 16 def on; @on; end |
#over ⇒ Object
If a non-mandatory reference was absorbed, only the non-nil instances are unique. Return the ObjectType that was absorbed, which might differ from this Index’s table.
20 |
# File 'lib/activefacts/rmap/index.rb', line 20 def over; @over; end |
#real_name ⇒ Object
The name that was assigned (perhaps implicitly by NORMA)
42 43 44 |
# File 'lib/activefacts/rmap/index.rb', line 42 def real_name @uniqueness_constraint.name && @uniqueness_constraint.name != '' ? @uniqueness_constraint.name.gsub(' ','') : nil end |
#to_s ⇒ Object
:nodoc:
71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/activefacts/rmap/index.rb', line 71 def to_s #:nodoc: if @uniqueness_constraint name = @uniqueness_constraint.name preferred = @uniqueness_constraint.is_preferred_identifier ? " (preferred)" : "" else name = "#{@on.name}IsUnique" preferred = !@on.injected_surrogate_role ? " (preferred)" : "" end colnames = @columns.map(&:name)*", " "Index #{name} on #{@on.name} over #{@over.name}(#{colnames})#{preferred}" end |
#uniqueness_constraint ⇒ Object
The UniquenessConstraint that created this index
13 |
# File 'lib/activefacts/rmap/index.rb', line 13 def uniqueness_constraint; @uniqueness_constraint; end |
#view_name ⇒ Object
The name of a view that can be created to enforce uniqueness over non-null key values
67 68 69 |
# File 'lib/activefacts/rmap/index.rb', line 67 def view_name "#{over.name.gsub(' ','')}#{on == over ? "" : "In"+on.name.gsub(' ','')}" end |