Module: Wtch

Defined in:
lib/wtch.rb,
lib/wtch/ui.rb,
lib/wtch/cli.rb,
lib/wtch/version.rb

Defined Under Namespace

Classes: CLI, UI

Constant Summary collapse

VERSION =
"0.0.2"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.uiObject



9
10
11
# File 'lib/wtch.rb', line 9

def ui
  @ui ||= UI.new
end

Class Method Details

.watch(url) ⇒ Object



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

def watch(url)
  agent = Mechanize.new
  stack = agent.get(url).links

  while l = stack.pop
    begin
      next unless l.uri.host.nil? || l.uri.host == agent.history.first.uri.host
      unless agent.visited? l.href
        stack.push(*(agent.click(l).links))
        Wtch.ui.info l.uri
      end
    rescue Errno::ECONNREFUSED, Mechanize::ResponseCodeError, ArgumentError, URI::InvalidComponentError, URI::InvalidURIError, NoMethodError, Mechanize::UnsupportedSchemeError => e
      begin
        Wtch.ui.error "#{e.message} (#{l.uri})"
      rescue
        Wtch.ui.error "#{e.message} (#{l.inspect})"
      end
    end
  end
end