Class: SLA::Checker

Inherits:
Object
  • Object
show all
Defined in:
lib/sla/checker.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(max_depth: 5, ignore: nil, check_external: false) ⇒ Checker

Returns a new instance of Checker.



5
6
7
8
9
# File 'lib/sla/checker.rb', line 5

def initialize(max_depth: 5, ignore: nil, check_external: false)
  @max_depth = max_depth
  @ignore = ignore
  @check_external = check_external
end

Instance Attribute Details

#check_externalObject (readonly)

Returns the value of attribute check_external.



3
4
5
# File 'lib/sla/checker.rb', line 3

def check_external
  @check_external
end

#ignoreObject (readonly)

Returns the value of attribute ignore.



3
4
5
# File 'lib/sla/checker.rb', line 3

def ignore
  @ignore
end

#max_depthObject (readonly)

Returns the value of attribute max_depth.



3
4
5
# File 'lib/sla/checker.rb', line 3

def max_depth
  @max_depth
end

Instance Method Details

#check(page) {|[:source, page]| ... } ⇒ Object

Yields:

  • ([:source, page])


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/sla/checker.rb', line 11

def check(page, &block)
  return if skip? page

  yield [:source, page] if block_given?

  pages = page_list page

  pages.each do |page|
    if checked.has_key? page.url or ignore? page
      yield [:skip, page] if block_given?
    else
      checked[page.url] = true
      yield [:check, page] if block_given?
    end
  end

  pages.each do |page|
    next if deeply_checked.has_key? page.url
    deeply_checked[page.url] = true
    next if page.external?
    check page, &block
  end
end