Exception: DbAgile::SchemaSemanticsError

Inherits:
SchemaError show all
Defined in:
lib/dbagile/core/schema/errors.rb

Overview

Raised when a schema is semantically not correct.

Constant Summary collapse

InvalidLogicalSchema =

Object-specific error tree

0x1000000
InvalidRelvar =
InvalidLogicalSchema  |     0x0100000
InvalidHeading =
InvalidRelvar         |       0x0010000
UnsupportedEmptyHeading =

schema_object=Heading

InvalidHeading        |         0x0001000
InvalidAttribute =
InvalidHeading        |         0x0002000
InvalidDefaultValue =

schema_object=Attribute

InvalidAttribute      |           0x0000100
InvalidConstraints =
InvalidRelvar         |       0x0020000
MissingPrimaryKey =

schema_object=Relvar

InvalidConstraints    |         0x0001000
InvalidConstraint =

schema_object=Constraint

InvalidConstraints    |         0x0002000
InvalidCandidateKey =

schema_object=CandidateKey

InvalidConstraint     |           0x0000100
InvalidForeignKey =

schema_object=ForeignKey

InvalidConstraint     |           0x0000200
InvalidPhysicalSchema =
0x2000000
InvalidIndexes =
InvalidPhysicalSchema |     0x0100000
InvalidIndex =
InvalidIndexes        |       0x0010000
NoSuchRelvar =

General flags

0x0000001
NoSuchRelvarAttributes =

:relvar_name

0x0000002
NoSuchCandidateKey =

:relvar_name, :attributes

0x0000004
AttributeMismatch =

:constraint_name

0x0000008
TargetKeyMismatch =
0x0000010
MESSAGE_KEYS =

User-defined messages

[ 
  InvalidDefaultValue, 
  UnsupportedEmptyHeading, 
  MissingPrimaryKey,
  InvalidConstraint,
  
  InvalidIndex,
  
  NoSuchRelvar,
  NoSuchRelvarAttributes,
  NoSuchCandidateKey,
  AttributeMismatch,
  TargetKeyMismatch
]
MESSAGE_VALUES =
[
  'invalid default value \'#{schema_object.default_value}\' on #{schema_object}',
  'relvar #{schema_object.relation_variable.name} has an empty heading (unsupported so far)',
  'relvar #{schema_object.name} has no primary key',
  'invalid constraint #{schema_object.name} on #{schema_object.relation_variable.name}',
  'invalid index #{schema_object.name}',
  'no such relvar #{args[:relvar_name]}',
  'no such attributes #{args[:attributes].join(\',\')}',
  'no such candidate key #{args[:constraint_name]}',
  'attribute mismatch',
  'target key mismatch'
]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(schema) ⇒ SchemaSemanticsError

Creates an error instance



124
125
126
127
# File 'lib/dbagile/core/schema/errors.rb', line 124

def initialize(schema)
  @schema = schema
  @errors = []
end

Instance Attribute Details

#errorsObject (readonly)

Collected semantical errors



121
122
123
# File 'lib/dbagile/core/schema/errors.rb', line 121

def errors
  @errors
end

#schemaObject (readonly)

Involved schema object



118
119
120
# File 'lib/dbagile/core/schema/errors.rb', line 118

def schema
  @schema
end

Instance Method Details

#add_error(object, error_code, args = {}) ⇒ Object

Adds a semantics error



165
166
167
# File 'lib/dbagile/core/schema/errors.rb', line 165

def add_error(object, error_code, args = {})
  @errors << [object, error_code, args]
end

#empty?Boolean

Is this error empty (no semantics error, then)

Returns:

  • (Boolean)


160
161
162
# File 'lib/dbagile/core/schema/errors.rb', line 160

def empty?
  @errors.empty?
end

#error_messagesObject

Returns an arry of error messages



150
151
152
# File 'lib/dbagile/core/schema/errors.rb', line 150

def error_messages
  errors.collect{|e|error_to_message(*e)}
end

#error_to_message(schema_object, error_code, args = {}) ⇒ Object

Converts an error to a message



130
131
132
133
134
135
136
137
# File 'lib/dbagile/core/schema/errors.rb', line 130

def error_to_message(schema_object, error_code, args = {})
  buffer = []
  MESSAGE_KEYS.each_with_index{|msg_key, index|
    next unless msg_key & error_code == msg_key
    buffer << Kernel.eval('"' + MESSAGE_VALUES[index] + '"', binding)
  }
  buffer.join(', ')
end

#message(long = false) ⇒ Object

Returns a friendly message



140
141
142
143
144
145
146
147
# File 'lib/dbagile/core/schema/errors.rb', line 140

def message(long = false)
  buffer = "Schema #{schema.schema_identifier} contains errors"
  if long
    buffer << ":\n"
    error_messages.each{|m| buffer << "  * " << m << "\n"}
  end
  buffer
end

#sizeObject

Returns number of sub errors



155
156
157
# File 'lib/dbagile/core/schema/errors.rb', line 155

def size
  errors.size
end