Class: Lazy::Checker

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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.expand_path('.', 'recipe.yaml')
  File.exist?(recipe_path) || raise(ERRORS[200] % {path: recipe_path})
  @recipe_path = recipe_path
  recipe_valid?
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



10
11
12
# File 'lib/lazy/check/checker.rb', line 10

def options
  @options
end

#recipe_pathObject (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

#reporterObject (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.

Parameters:

  • options (Hash)

    Cf. Lazy::Checker::Code#check_against



29
30
31
32
33
34
# File 'lib/lazy/check/checker_code.rb', line 29

def check(xml_code, data_check, **options)
  @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, **options)
end

Instance Method Details

#baseObject

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 –

Returns:

  • (Boolean)


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)
  @options = options || {}
  proceed_check(**options)
end

#nameObject

— Données —



67
68
69
# File 'lib/lazy/check/checker.rb', line 67

def name
  @name ||= recipe[:name]
end

#no_output?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/lazy/check/checker.rb', line 51

def no_output?
  options[: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)
  @options = options
  @reporter = Reporter.new(self)
  @reporter.start
  recipe[:tests].collect do |dtest|
    Test.new(self, dtest)
  end.each do |test|
    test.check(**options)
  end
  @reporter.end
  if no_output?
    return @reporter
  else
    @reporter.display
  end
end

#recipeObject 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

Returns:

  • (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