Class: Graphiti::Schema::Check
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #compatible? ⇒ Boolean
-
#initialize(schema, path) ⇒ Check
constructor
A new instance of Check.
- #message ⇒ Object
- #missing? ⇒ Boolean
- #ok? ⇒ Boolean
- #stale? ⇒ Boolean
- #write! ⇒ Object
Constructor Details
#initialize(schema, path) ⇒ Check
Returns a new instance of Check.
6 7 8 9 10 11 12 |
# File 'lib/graphiti/schema/check.rb', line 6 def initialize(schema, path) @path = path @schema = schema @generated = normalize(schema) @committed = normalize(JSON.parse(File.read(path))) if File.exist?(path) @errors = @committed ? SchemaDiff.new(@committed, @generated).compare : [] end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
4 5 6 |
# File 'lib/graphiti/schema/check.rb', line 4 def errors @errors end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
4 5 6 |
# File 'lib/graphiti/schema/check.rb', line 4 def path @path end |
Instance Method Details
#compatible? ⇒ Boolean
22 23 24 |
# File 'lib/graphiti/schema/check.rb', line 22 def compatible? errors.empty? end |
#message ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/graphiti/schema/check.rb', line 36 def return "Schema is up to date: #{path}" if ok? return "#{}\n\n#{regenerate}" if missing? return "#{}\n\n#{errors.join("\n")}" unless compatible? "Schema file is outdated: #{path}\n\n#{regenerate}" end |
#missing? ⇒ Boolean
14 15 16 |
# File 'lib/graphiti/schema/check.rb', line 14 def missing? @committed.nil? end |
#ok? ⇒ Boolean
26 27 28 |
# File 'lib/graphiti/schema/check.rb', line 26 def ok? !missing? && !stale? && compatible? end |
#stale? ⇒ Boolean
18 19 20 |
# File 'lib/graphiti/schema/check.rb', line 18 def stale? !missing? && @committed != @generated end |
#write! ⇒ Object
30 31 32 33 34 |
# File 'lib/graphiti/schema/check.rb', line 30 def write! FileUtils.mkdir_p(File.dirname(path)) File.write(path, JSON.pretty_generate(@schema)) path end |