Class: Lazy::Checker
- Inherits:
-
Object
- Object
- Lazy::Checker
- Defined in:
- lib/lazy/check/checker.rb,
lib/lazy/check/reporter.rb,
lib/lazy/check/checked_tag.rb,
lib/lazy/check/checked_url.rb,
lib/lazy/check/checker_url.rb,
lib/lazy/check/checker_case.rb,
lib/lazy/check/checker_code.rb,
lib/lazy/check/checker_test.rb
Defined Under Namespace
Classes: CheckCase, CheckedTag, CheckedUrl, Code, RecipeError, Reporter, Test, Url
Instance Attribute Summary collapse
-
#recipe_path ⇒ Object
readonly
Returns the value of attribute recipe_path.
-
#reporter ⇒ Object
readonly
Returns the value of attribute reporter.
Class Method Summary collapse
Instance Method Summary collapse
-
#base ⇒ Object
- String
-
La base pour l’url.
-
#base? ⇒ Boolean
– Predicate Methods –.
- #check(**options) ⇒ Object
-
#initialize(recipe_path = nil) ⇒ Checker
constructor
A new instance of Checker.
-
#name ⇒ Object
— Données —.
- #no_output? ⇒ Boolean
-
#proceed_check(**options) ⇒ Object
main =.
-
#recipe ⇒ Object
(also: #data)
- Hash
-
Les données de la recette, ou simplement “la recette”.
- #recipe_valid? ⇒ Boolean
Constructor Details
#initialize(recipe_path = nil) ⇒ Checker
Returns a new instance of Checker.
10 11 12 13 14 15 |
# File 'lib/lazy/check/checker.rb', line 10 def initialize(recipe_path = nil) recipe_path ||= File.('.', 'recipe.yaml') File.exist?(recipe_path) || raise(ERRORS[200] % {path: recipe_path}) @recipe_path = recipe_path recipe_valid? end |
Instance Attribute Details
#recipe_path ⇒ Object (readonly)
Returns the value of attribute recipe_path.
6 7 8 |
# File 'lib/lazy/check/checker.rb', line 6 def recipe_path @recipe_path end |
#reporter ⇒ Object (readonly)
Returns the value of attribute reporter.
8 9 10 |
# File 'lib/lazy/check/checker.rb', line 8 def reporter @reporter end |
Class Method Details
.check(xml_code, data_check, **options) ⇒ Object
main =
Pour une utilisation du gem avec :
Lazy::Checker.check(<code XML>, {<donn
… qui produit un rapport.
Les données check doivent être conformes, c’est-à-dire contenir au moins la propriété :tag qui définit une balise à trouver dans le code XML.
29 30 31 32 33 34 |
# File 'lib/lazy/check/checker_code.rb', line 29 def check(xml_code, data_check, **) @xml_code = check_xml_code(xml_code) @data_check = check_data_check(data_check) checker = Lazy::Checker::Code.new(@xml_code) checker.check_against(@data_check, **) end |
Instance Method Details
#base ⇒ Object
- String
-
La base pour l’url
69 70 71 |
# File 'lib/lazy/check/checker.rb', line 69 def base @base ||= recipe[:base] end |
#base? ⇒ Boolean
– Predicate Methods –
44 45 46 |
# File 'lib/lazy/check/checker.rb', line 44 def base? not(base.nil?) end |
#check(**options) ⇒ Object
17 18 19 20 |
# File 'lib/lazy/check/checker.rb', line 17 def check(**) = || {} proceed_check(**) end |
#name ⇒ Object
— Données —
64 65 66 |
# File 'lib/lazy/check/checker.rb', line 64 def name @name ||= recipe[:name] end |
#no_output? ⇒ Boolean
58 59 60 |
# File 'lib/lazy/check/checker.rb', line 58 def no_output? [:output] === false end |
#proceed_check(**options) ⇒ Object
main =
La méthode (silencieuse) qui produit le check (“silencieuse” parce qu’elle ne produit que des raises)
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/lazy/check/checker.rb', line 26 def proceed_check(**) @reporter = Reporter.new(self) @reporter.start recipe[:tests].collect do |dtest| Test.new(self, dtest) end.each do |test| test.check(**) end @reporter.end if [:return_result] return @reporter else @reporter.display unless no_output? end end |
#recipe ⇒ Object Also known as: data
- Hash
-
Les données de la recette, ou simplement “la recette”
75 76 77 |
# File 'lib/lazy/check/checker.rb', line 75 def recipe @recipe ||= YAML.safe_load(File.read(recipe_path), **YAML_OPTIONS) end |
#recipe_valid? ⇒ Boolean
48 49 50 51 52 53 54 55 56 |
# File 'lib/lazy/check/checker.rb', line 48 def recipe_valid? not(recipe.nil?) || raise(RecipeError, ERRORS[202]) recipe.is_a?(Hash) || raise(RecipeError, ERRORS[203] % {c: recipe.class.name}) unless recipe.key?(:name) && name.is_a?(String) && not(name.empty?) raise(RecipeError, ERRORS[206]) end recipe.key?(:tests) || raise(RecipeError, ERRORS[204] % {ks: recipe.keys.pretty_inspect}) recipe[:tests].is_a?(Array) || raise(RecipeError, ERRORS[205] % {c: recipe[:tests].class.name}) end |