Class: DbAgile::Core::Schema::SchemaObject

Inherits:
Object
  • Object
show all
Defined in:
lib/dbagile/core/schema/schema_object.rb

Direct Known Subclasses

Composite, Part

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#parentObject

Parent object



7
8
9
# File 'lib/dbagile/core/schema/schema_object.rb', line 7

def parent
  @parent
end

#statusObject

Object status



10
11
12
# File 'lib/dbagile/core/schema/schema_object.rb', line 10

def status
  @status
end

Instance Method Details

#ancestorsObject

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

Returns:

  • (Boolean)


48
49
50
# File 'lib/dbagile/core/schema/schema_object.rb', line 48

def attribute?
  self.kind_of?(Schema::Logical::Attribute)
end

#builder_argsObject

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_handlerObject

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

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


33
34
35
# File 'lib/dbagile/core/schema/schema_object.rb', line 33

def logical?
  relvar? or relview? or attribute? or constraint?
end

#outside_dependenciesObject

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_dependentsObject

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?

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


63
64
65
# File 'lib/dbagile/core/schema/schema_object.rb', line 63

def primary_key?
  self.candidate_key? and self.primary?
end

#relation_variableObject

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

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


38
39
40
# File 'lib/dbagile/core/schema/schema_object.rb', line 38

def relview?
  self.kind_of?(Schema::Logical::Relview)
end

#schemaObject

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