Class: DbAgile::Core::Schema::Logical::CandidateKey

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

Instance Attribute Summary

Attributes inherited from Part

#definition, #name

Attributes inherited from SchemaObject

#parent, #status

Instance Method Summary collapse

Methods inherited from Constraint

#candidate_key?, factor, #foreign_key?, #primary_key?

Methods inherited from Part

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

Methods inherited from SchemaObject

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

Constructor Details

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

Instance Method Details

#_semantics_check(clazz, buffer) ⇒ Object

See Also:



41
42
43
44
45
46
47
48
# File 'lib/dbagile/core/schema/logical/constraint/candidate_key.rb', line 41

def _semantics_check(clazz, buffer)
  rv = relation_variable
  unless rv.heading.has_attributes?(definition[:attributes])
    error_code = clazz::InvalidCandidateKey | clazz::NoSuchRelvarAttributes
    buffer.add_error(self, error_code, :relvar_name => rv.name, 
                                       :attributes  => definition[:attributes])
  end
end

#attribute_namesObject

Returns attribute names



17
18
19
# File 'lib/dbagile/core/schema/logical/constraint/candidate_key.rb', line 17

def attribute_names
  definition[:attributes]
end

#dependencies(include_parent = false) ⇒ Object

See Also:



32
33
34
# File 'lib/dbagile/core/schema/logical/constraint/candidate_key.rb', line 32

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

#key_attributesObject

Returns key attributes



22
23
24
25
# File 'lib/dbagile/core/schema/logical/constraint/candidate_key.rb', line 22

def key_attributes
  rv = relation_variable
  definition[:attributes].collect{|k| rv.heading[k]}
end

#primary?Boolean

Is it a primary key?

Returns:

  • (Boolean)


12
13
14
# File 'lib/dbagile/core/schema/logical/constraint/candidate_key.rb', line 12

def primary?
  definition[:type] == :primary_key
end

#to_yaml(opts = {}) ⇒ Object

Delegation pattern on YAML flushing



55
56
57
58
59
60
61
62
63
64
# File 'lib/dbagile/core/schema/logical/constraint/candidate_key.rb', line 55

def to_yaml(opts = {})
  YAML::quick_emit(self, opts){|out|
    defn = definition
    attrs = Schema::Builder::Coercion::unsymbolize_array(definition[:attributes])
    out.map("tag:yaml.org,2002:map", :inline ) do |map|
      map.add('type', definition[:type])
      map.add('attributes', attrs)
    end
  }
end