Class: DbAgile::Core::Schema::Logical::Constraint

Inherits:
Part show all
Defined in:
lib/dbagile/core/schema/logical/constraint.rb

Direct Known Subclasses

CandidateKey, ForeignKey

Instance Attribute Summary

Attributes inherited from Part

#definition, #name

Attributes inherited from SchemaObject

#parent, #status

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Part

#_sanity_check, #_semantics_check, #dup, #initialize, #look_same_as?, #to_s, #visit

Methods inherited from SchemaObject

#ancestors, #attribute?, #builder_args, #builder_handler, #composite?, #constraint?, #index?, #logical?, #outside_dependencies, #outside_dependents, #part?, #physical?, #relation_variable, #relvar?, #relview?, #schema

Constructor Details

This class inherits a constructor from DbAgile::Core::Schema::Part

Class Method Details

.factor(name, definition) ⇒ Object

Builds a constraint



12
13
14
15
16
17
18
19
20
21
# File 'lib/dbagile/core/schema/logical/constraint.rb', line 12

def self.factor(name, definition)
  case kind = definition[:type]
    when :primary_key, :candidate_key, :key
      Schema::Logical::CandidateKey.new(name, definition)
    when :foreign_key
      Schema::Logical::ForeignKey.new(name, definition)
    else 
      raise ArgumentError, "Unexpected constraint kind #{kind}"
  end
end

Instance Method Details

#candidate_key?Boolean

Returns true if this constraint is a candidate key (including a primary key)

Returns:

  • (Boolean)


29
30
31
# File 'lib/dbagile/core/schema/logical/constraint.rb', line 29

def candidate_key?
  self.kind_of?(Logical::CandidateKey)
end

#dependencies(include_parent = false) ⇒ Object

See Also:



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

def dependencies(include_parent = false)
  include_parent ? [ parent ] : false
end

#foreign_key?Boolean

Returns true if this constraint is a foreign key

Returns:

  • (Boolean)


39
40
41
# File 'lib/dbagile/core/schema/logical/constraint.rb', line 39

def foreign_key?
  self.kind_of?(Logical::ForeignKey)
end

#primary_key?Boolean

Returns true if this constraint is a primary key, false otherwise

Returns:

  • (Boolean)


34
35
36
# File 'lib/dbagile/core/schema/logical/constraint.rb', line 34

def primary_key?
  candidate_key? and primary?
end