Class: Lyra::Schema::Validator
- Inherits:
-
Object
- Object
- Lyra::Schema::Validator
- Defined in:
- lib/lyra/schema/validator.rb
Overview
Validates current schema against stored schema
Instance Attribute Summary collapse
-
#current_schema ⇒ Object
readonly
Returns the value of attribute current_schema.
-
#differences ⇒ Object
readonly
Returns the value of attribute differences.
-
#stored_schema ⇒ Object
readonly
Returns the value of attribute stored_schema.
Instance Method Summary collapse
-
#breaking_changes? ⇒ Boolean
Check if there are breaking changes.
-
#enforce! ⇒ Object
Validate and enforce strict mode if configured.
-
#initialize ⇒ Validator
constructor
A new instance of Validator.
-
#report ⇒ Object
Generate human-readable report.
-
#schema_exists? ⇒ Boolean
Check if stored schema exists.
-
#valid? ⇒ Boolean
Check if schema is valid (no differences).
-
#validate! ⇒ Object
Perform validation.
Constructor Details
#initialize ⇒ Validator
Returns a new instance of Validator.
9 10 11 12 13 14 |
# File 'lib/lyra/schema/validator.rb', line 9 def initialize @current_schema = nil @stored_schema = nil @differences = [] @validated = false end |
Instance Attribute Details
#current_schema ⇒ Object (readonly)
Returns the value of attribute current_schema.
7 8 9 |
# File 'lib/lyra/schema/validator.rb', line 7 def current_schema @current_schema end |
#differences ⇒ Object (readonly)
Returns the value of attribute differences.
7 8 9 |
# File 'lib/lyra/schema/validator.rb', line 7 def differences @differences end |
#stored_schema ⇒ Object (readonly)
Returns the value of attribute stored_schema.
7 8 9 |
# File 'lib/lyra/schema/validator.rb', line 7 def stored_schema @stored_schema end |
Instance Method Details
#breaking_changes? ⇒ Boolean
Check if there are breaking changes
28 29 30 31 |
# File 'lib/lyra/schema/validator.rb', line 28 def breaking_changes? validate! unless @validated @differences.any? { |d| d[:severity] == :breaking } end |
#enforce! ⇒ Object
Validate and enforce strict mode if configured
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/lyra/schema/validator.rb', line 52 def enforce! return true if valid? if Lyra.config.strict_schema raise SchemaValidationError.new(report, @differences) else log_warning false end end |
#report ⇒ Object
Generate human-readable report
34 35 36 37 |
# File 'lib/lyra/schema/validator.rb', line 34 def report validate! unless @validated Diff.format_report(@differences) end |
#schema_exists? ⇒ Boolean
Check if stored schema exists
23 24 25 |
# File 'lib/lyra/schema/validator.rb', line 23 def schema_exists? Store.exists? end |
#valid? ⇒ Boolean
Check if schema is valid (no differences)
17 18 19 20 |
# File 'lib/lyra/schema/validator.rb', line 17 def valid? validate! unless @validated @differences.empty? end |
#validate! ⇒ Object
Perform validation
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/lyra/schema/validator.rb', line 40 def validate! @validated = true @stored_schema = Store.load_current @current_schema = Generator.generate return true if @stored_schema.nil? # No schema yet = valid @differences = Diff.compare(@stored_schema, @current_schema) @differences.empty? end |