Class: ReleaseHighlights::Validator
- Inherits:
-
Object
- Object
- ReleaseHighlights::Validator
- Defined in:
- lib/release_highlights/validator.rb
Defined Under Namespace
Classes: Entry
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#file ⇒ Object
readonly
Returns the value of attribute file.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(file:) ⇒ Validator
constructor
A new instance of Validator.
- #valid? ⇒ Boolean
Constructor Details
#initialize(file:) ⇒ Validator
Returns a new instance of Validator.
7 8 9 10 |
# File 'lib/release_highlights/validator.rb', line 7 def initialize(file:) @file = file @errors = [] end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
5 6 7 |
# File 'lib/release_highlights/validator.rb', line 5 def errors @errors end |
#file ⇒ Object (readonly)
Returns the value of attribute file.
5 6 7 |
# File 'lib/release_highlights/validator.rb', line 5 def file @file end |
Class Method Details
.error_message ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/release_highlights/validator.rb', line 36 def self. io = StringIO.new @all_errors.each do |errors, file| = "Validation failed for #{file}" line = -> { io.puts "-" * .length } line.call io.puts line.call errors.flatten.each { |error| io.puts "* #{error}" } io.puts end io.string end |
.validate_all! ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/release_highlights/validator.rb', line 24 def self.validate_all! @all_errors = [] ReleaseHighlight.file_paths.each do |file_path| instance = self.new(file: file_path) @all_errors.push([instance.errors, instance.file]) unless instance.valid? end @all_errors.none? end |
Instance Method Details
#valid? ⇒ Boolean
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/release_highlights/validator.rb', line 12 def valid? document = YAML.parse(File.read(file)) document.root.children.each do |entry| entry = ReleaseHighlights::Validator::Entry.new(entry) errors.push(entry.errors.) unless entry.valid? end errors.none? end |