Class: DbAgile::Core::Schema::Logical::Attribute

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

Instance Attribute Summary

Attributes inherited from Part

#definition, #name

Attributes inherited from SchemaObject

#parent, #status

Instance Method Summary collapse

Methods inherited from Part

#_sanity_check, #dup, #initialize, #look_same_as?, #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:



44
45
46
47
48
# File 'lib/dbagile/core/schema/logical/attribute.rb', line 44

def _semantics_check(clazz, buffer)
  unless default_value.nil? or (domain === default_value)
    buffer.add_error(self, clazz::InvalidDefaultValue)
  end
end

#default_valueObject

Returns default value



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

def default_value
  definition[:default]
end

#dependencies(include_parent = false) ⇒ Object

See Also:



35
36
37
# File 'lib/dbagile/core/schema/logical/attribute.rb', line 35

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

#domainObject

Returns attribute domain



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

def domain
  definition[:domain]
end

#mandatory?Boolean

Returns default value

Returns:

  • (Boolean)


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

def mandatory?
  !(definition[:mandatory] == false)
end

#relvarObject



26
27
28
# File 'lib/dbagile/core/schema/logical/attribute.rb', line 26

def relvar
  parent.parent
end

#to_sObject

Returns a string representation



69
70
71
# File 'lib/dbagile/core/schema/logical/attribute.rb', line 69

def to_s
  "Attribute  #{relvar.name}::#{name} #{definition.inspect}"
end

#to_yaml(opts = {}) ⇒ Object

Delegation pattern on YAML flushing



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

def to_yaml(opts = {})
  YAML::quick_emit(self, opts){|out|
    defn = definition
    out.map("tag:yaml.org,2002:map", :inline ) do |map|
      map.add('domain', defn[:domain].to_s)
      map.add('mandatory', false) unless defn[:mandatory]
      unless defn[:default].nil?
        map.add('default', defn[:default])
      end
    end
  }
end