Class: RailsSkills::SkillValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_skills/skill_validator.rb

Constant Summary collapse

FRONTMATTER_REGEX =
/\A---\n(.+?\n)---\n/m
REQUIRED_KEYS =
%w[name description].freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_path) ⇒ SkillValidator

Returns a new instance of SkillValidator.



19
20
21
# File 'lib/rails_skills/skill_validator.rb', line 19

def initialize(file_path)
  @file_path = file_path
end

Class Method Details

.valid?(file_path) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/rails_skills/skill_validator.rb', line 15

def self.valid?(file_path)
  validate(file_path).empty?
end

.validate(file_path) ⇒ Object



11
12
13
# File 'lib/rails_skills/skill_validator.rb', line 11

def self.validate(file_path)
  new(file_path).validate
end

Instance Method Details

#validate ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/rails_skills/skill_validator.rb', line 23

def validate
  errors = []

  content = read_file(errors)
  return errors unless content

  frontmatter_text = extract_frontmatter(content, errors)
  return errors unless frontmatter_text

  data = parse_yaml(frontmatter_text, errors)
  return errors unless data

  validate_required_keys(data, errors)

  errors
end