Sha256: cee7a641b42f5b55e8927429b9e5884e9e1c5111b8ecfc5373ef3d63011ade64

Contents?: true

Size: 1.86 KB

Versions: 7

Compression:

Stored size: 1.86 KB

Contents

module Lazy
class Checker

  class RecipeError < StandardError; end

  attr_reader :recipe_path

  attr_reader :reporter

  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

  def check(**options)
    @options = options || {}
    proceed_check(**options)
  end

  # = main =
  # 
  # La méthode (silencieuse) qui produit le check
  # ("silencieuse" parce qu'elle ne produit que des raises)
  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(**options)
    end
    @reporter.end
    if options[:return_result]
      return @reporter
    else
      @reporter.display unless no_output?
    end
  end

  # -- Predicate Methods --

  def base?
    not(base.nil?)
  end

  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

  def no_output?
    @options[:output] === false
  end

  # --- Données ---

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

  # [String] La base pour l'url
  def base
    @base ||= recipe[:base]
  end

  # [Hash] Les données de la recette, ou simplement "la recette"
  # 
  def recipe
    @recipe ||= YAML.safe_load(File.read(recipe_path), **YAML_OPTIONS)
  end
  alias :data :recipe


end #/class Checker
end #/module Lazy

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
lazy-check-1.2.2 lib/lazy/check/checker.rb
lazy-check-1.2.1 lib/lazy/check/checker.rb
lazy-check-1.2.0 lib/lazy/check/checker.rb
lazy-check-1.1.0 lib/lazy/check/checker.rb
lazy-check-1.0.2 lib/lazy/check/checker.rb
lazy-check-1.0.1 lib/lazy/check/checker.rb
lazy-check-1.0.0 lib/lazy/check/checker.rb