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
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#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.
12 13 14 15 16 17 |
# File 'lib/lazy/check/checker.rb', line 12 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
#options ⇒ Object (readonly)
Returns the value of attribute options.
10 11 12 |
# File 'lib/lazy/check/checker.rb', line 10 def @options end |
#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ées check>})
… 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
72 73 74 |
# File 'lib/lazy/check/checker.rb', line 72 def base @base ||= recipe[:base] end |
#base? ⇒ Boolean
– Predicate Methods –
47 48 49 |
# File 'lib/lazy/check/checker.rb', line 47 def base? not(base.nil?) end |
#check(**options) ⇒ Object
19 20 21 22 |
# File 'lib/lazy/check/checker.rb', line 19 def check(**) @options = || {} proceed_check(**) end |
#name ⇒ Object
— Données —
67 68 69 |
# File 'lib/lazy/check/checker.rb', line 67 def name @name ||= recipe[:name] end |
#no_output? ⇒ Boolean
51 52 53 |
# File 'lib/lazy/check/checker.rb', line 51 def no_output? [:return_result] === true end |
#proceed_check(**options) ⇒ Object
main =
La méthode (silencieuse) qui produit le check (“silencieuse” parce qu’elle ne produit que des raises)
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/lazy/check/checker.rb', line 28 def proceed_check(**) @options = @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 no_output? return @reporter else @reporter.display end end |
#recipe ⇒ Object Also known as: data
- Hash
-
Les données de la recette, ou simplement “la recette”
78 79 80 |
# File 'lib/lazy/check/checker.rb', line 78 def recipe @recipe ||= YAML.safe_load(File.read(recipe_path), **YAML_OPTIONS) end |
#recipe_valid? ⇒ Boolean
55 56 57 58 59 60 61 62 63 |
# File 'lib/lazy/check/checker.rb', line 55 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 |