Class: Lazy::Checker::CheckedUrl

Inherits:
Object
  • Object
show all
Defined in:
lib/lazy/check/checked_url.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ CheckedUrl

Instanciation



19
20
21
# File 'lib/lazy/check/checked_url.rb', line 19

def initialize(data)
  @data = data
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



11
12
13
# File 'lib/lazy/check/checked_url.rb', line 11

def data
  @data
end

#errorObject (readonly)

String

L’erreur éventuelle à écrire



14
15
16
# File 'lib/lazy/check/checked_url.rb', line 14

def error
  @error
end

Instance Method Details

#check(**options) ⇒ Object

— TESTS METHODS —



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/lazy/check/checked_url.rb', line 30

def check(**options)
  urler.readit
  if test_redirection?
    if urler.redirection? && urler.redirect_to == data[:redirect_to]
      reporter.add_success(self)
    elsif urler.redirect_to.nil?
      @error = ERRORS[5500] % {e:data[:redirect_to]}
      reporter.add_failure(self)
    else
      @error = ERRORS[5501] % {a:urler.redirect_to, e:data[:redirect_to]}
      reporter.add_failure(self)
    end
  elsif test_response?
    # STDOUT.write("\nurler.rvalue = #{urler.rvalue.inspect}".jaune)
    if urler.rvalue == data[:response]
      reporter.add_success(self)
    else
      case urler.rvalue
      when 404
        @error = ERRORS[5503] % {e: urler.url}
      else
        @error = ERRORS[5502] % {a:urler.rvalue, e:data[:response]}
      end
      reporter.add_failure(self)
    end
  end
end

#errorsObject

Returns les erreurs rencontrées.

Returns:

  • les erreurs rencontrées



24
25
26
# File 'lib/lazy/check/checked_url.rb', line 24

def errors
  @errors.join("\n") + "Sous-erreurs : #{@sub_errors.join("\n")}"
end

#nameObject Also known as: message



72
# File 'lib/lazy/check/checked_url.rb', line 72

def name      ; data[:name]       end

#reporterObject



74
# File 'lib/lazy/check/checked_url.rb', line 74

def reporter  ; data[:reporter]   end

#test_redirection?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/lazy/check/checked_url.rb', line 65

def test_redirection?
  data.key?(:redirect_to) && not(data[:redirect_to].nil?)
end

#test_response?Boolean

– Predicate Methods –

Returns:

  • (Boolean)


61
62
63
# File 'lib/lazy/check/checked_url.rb', line 61

def test_response?
  data.key?(:response) && not(data[:response].nil?)
end

#urlerObject

– Data Methods –



71
# File 'lib/lazy/check/checked_url.rb', line 71

def urler     ; data[:urler]      end