Class: DbAgile::Core::Schema::SchemaObject
- Inherits:
-
Object
- Object
- DbAgile::Core::Schema::SchemaObject
- Defined in:
- lib/dbagile/core/schema/schema_object.rb
Instance Attribute Summary collapse
-
#parent ⇒ Object
readonly
Parent object.
-
#status ⇒ Object
Object status.
Instance Method Summary collapse
-
#ancestors ⇒ Object
Returns object’s ancestors.
-
#attribute? ⇒ Boolean
Returns true if this object is an attribute, false otherwise.
-
#builder_args ⇒ Object
Returns the arguments to pass to builder handler.
-
#builder_handler ⇒ Object
Returns the builder handler for this object.
-
#candidate_key? ⇒ Boolean
Returns true if this object is a candidate key, false otherwise.
-
#composite? ⇒ Boolean
Returns true if this schema object is composite, false otherwise.
-
#constraint? ⇒ Boolean
Returns true if this object is a constraint, false otherwise.
-
#foreign_key? ⇒ Boolean
Returns true if this object is a foreign key, false otherwise.
-
#index? ⇒ Boolean
Returns true if this object is an index, false otherwise.
-
#logical? ⇒ Boolean
Returns true if this object is a logical object, false otherwise.
-
#outside_dependencies ⇒ Object
Returns outside dependencies only.
-
#outside_dependents ⇒ Object
Returns objects depending on this.
-
#part? ⇒ Boolean
(also: #terminal?)
Convenient method for !composite?.
-
#physical? ⇒ Boolean
Returns true if this object is a physical object, false otherwise.
-
#primary_key? ⇒ Boolean
Returns true if this object is a primary key, false otherwise.
-
#relation_variable ⇒ Object
Returns relation variable of this object, if any.
-
#relvar? ⇒ Boolean
Returns true if this object is a relation variable, false otherwise.
-
#relview? ⇒ Boolean
Returns true if this object is a relation view, false otherwise.
-
#schema ⇒ Object
Returns the main schema instance.
Instance Attribute Details
#parent ⇒ Object
Parent object
7 8 9 |
# File 'lib/dbagile/core/schema/schema_object.rb', line 7 def parent @parent end |
#status ⇒ Object
Object status
10 11 12 |
# File 'lib/dbagile/core/schema/schema_object.rb', line 10 def status @status end |
Instance Method Details
#ancestors ⇒ Object
Returns object’s ancestors
92 93 94 |
# File 'lib/dbagile/core/schema/schema_object.rb', line 92 def ancestors parent.nil? ? [] : [ parent ] + parent.ancestors end |
#attribute? ⇒ Boolean
Returns true if this object is an attribute, false otherwise
48 49 50 |
# File 'lib/dbagile/core/schema/schema_object.rb', line 48 def attribute? self.kind_of?(Schema::Logical::Attribute) end |
#builder_args ⇒ Object
Returns the arguments to pass to builder handler
137 138 139 |
# File 'lib/dbagile/core/schema/schema_object.rb', line 137 def builder_args [] end |
#builder_handler ⇒ Object
Returns the builder handler for this object
131 132 133 134 |
# File 'lib/dbagile/core/schema/schema_object.rb', line 131 def builder_handler unqualified = DbAgile::RubyTools::class_unqualified_name(self.class).to_s unqualified.gsub(/[A-Z]/){|x| "_#{x.downcase}"}[1..-1] end |
#candidate_key? ⇒ Boolean
Returns true if this object is a candidate key, false otherwise
58 59 60 |
# File 'lib/dbagile/core/schema/schema_object.rb', line 58 def candidate_key? self.kind_of?(Schema::Logical::CandidateKey) end |
#composite? ⇒ Boolean
Returns true if this schema object is composite, false otherwise
18 19 20 |
# File 'lib/dbagile/core/schema/schema_object.rb', line 18 def composite? self.kind_of?(Schema::Composite) end |
#constraint? ⇒ Boolean
Returns true if this object is a constraint, false otherwise
53 54 55 |
# File 'lib/dbagile/core/schema/schema_object.rb', line 53 def constraint? self.kind_of?(Schema::Logical::Constraint) end |
#foreign_key? ⇒ Boolean
Returns true if this object is a foreign key, false otherwise
68 69 70 |
# File 'lib/dbagile/core/schema/schema_object.rb', line 68 def foreign_key? self.kind_of?(Schema::Logical::ForeignKey) end |
#index? ⇒ Boolean
Returns true if this object is an index, false otherwise
78 79 80 |
# File 'lib/dbagile/core/schema/schema_object.rb', line 78 def index? self.kind_of?(Schema::Physical::Index) end |
#logical? ⇒ Boolean
Returns true if this object is a logical object, false otherwise
33 34 35 |
# File 'lib/dbagile/core/schema/schema_object.rb', line 33 def logical? relvar? or relview? or attribute? or constraint? end |
#outside_dependencies ⇒ Object
Returns outside dependencies only
97 98 99 100 |
# File 'lib/dbagile/core/schema/schema_object.rb', line 97 def outside_dependencies deps = dependencies deps.delete_if{|d| d.ancestors.include?(self)} end |
#outside_dependents ⇒ Object
Returns objects depending on this
103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/dbagile/core/schema/schema_object.rb', line 103 def outside_dependents selected = [] schema.visit{|part, parent| if part.part? and not(part.ancestors.include?(self)) deps = part.outside_dependencies deps = deps.collect{|d| d.ancestors}.flatten.uniq selected << part if deps.include?(self) end } selected end |
#part? ⇒ Boolean Also known as: terminal?
Convenient method for !composite?
23 24 25 |
# File 'lib/dbagile/core/schema/schema_object.rb', line 23 def part? !composite? end |
#physical? ⇒ Boolean
Returns true if this object is a physical object, false otherwise
73 74 75 |
# File 'lib/dbagile/core/schema/schema_object.rb', line 73 def physical? index? end |
#primary_key? ⇒ Boolean
Returns true if this object is a primary key, false otherwise
63 64 65 |
# File 'lib/dbagile/core/schema/schema_object.rb', line 63 def primary_key? self.candidate_key? and self.primary? end |
#relation_variable ⇒ Object
Returns relation variable of this object, if any
116 117 118 119 120 121 122 123 124 |
# File 'lib/dbagile/core/schema/schema_object.rb', line 116 def relation_variable if self.kind_of?(DbAgile::Core::Schema::Logical::Relvar) self elsif parent parent.relation_variable else raise NoMethodError, "undefined method relation_variable for #{self.class}" end end |
#relvar? ⇒ Boolean
Returns true if this object is a relation variable, false otherwise
43 44 45 |
# File 'lib/dbagile/core/schema/schema_object.rb', line 43 def relvar? self.kind_of?(Schema::Logical::Relvar) end |
#relview? ⇒ Boolean
Returns true if this object is a relation view, false otherwise
38 39 40 |
# File 'lib/dbagile/core/schema/schema_object.rb', line 38 def relview? self.kind_of?(Schema::Logical::Relview) end |
#schema ⇒ Object
Returns the main schema instance
87 88 89 |
# File 'lib/dbagile/core/schema/schema_object.rb', line 87 def schema @schema ||= (parent && parent.schema) end |