Class: CloudbleedChecker::Browser

Inherits:
Object
  • Object
show all
Defined in:
lib/cloudbleed_checker/browser.rb

Direct Known Subclasses

Chrome, Firefox, Safari

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tmpdir) ⇒ Browser

Returns a new instance of Browser.



18
19
20
21
# File 'lib/cloudbleed_checker/browser.rb', line 18

def initialize(tmpdir)
  @tmpdir = tmpdir
  @hosts = Set.new
end

Class Attribute Details

.history_db_globObject

Returns the value of attribute history_db_glob.



11
12
13
# File 'lib/cloudbleed_checker/browser.rb', line 11

def history_db_glob
  @history_db_glob
end

.history_db_pathObject

Returns the value of attribute history_db_path.



10
11
12
# File 'lib/cloudbleed_checker/browser.rb', line 10

def history_db_path
  @history_db_path
end

Class Method Details

.extract_domains(tmpdir) ⇒ Object



13
14
15
# File 'lib/cloudbleed_checker/browser.rb', line 13

def extract_domains(tmpdir)
  new(tmpdir).extract_domains
end

Instance Method Details

#extract_host(row, url_key) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/cloudbleed_checker/browser.rb', line 31

def extract_host(row, url_key)
  url = row[url_key]
  return if url.nil?
  URI.parse(url).host
rescue URI::InvalidURIError => ex
  puts "unable to parse url: '#{row[url_key]}', skipping"
end

#extract_hosts(dataset, url_key) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/cloudbleed_checker/browser.rb', line 23

def extract_hosts(dataset, url_key)
  dataset.paged_each do |row|
    host = extract_host(row, url_key)
    @hosts << host if host
  end
  @hosts
end

#history_db_globObject



43
44
45
# File 'lib/cloudbleed_checker/browser.rb', line 43

def history_db_glob
  self.class.history_db_glob
end

#history_db_pathObject



39
40
41
# File 'lib/cloudbleed_checker/browser.rb', line 39

def history_db_path
  self.class.history_db_path
end

#with_database(db_path = history_db_path) ⇒ Object



47
48
49
50
51
52
53
54
# File 'lib/cloudbleed_checker/browser.rb', line 47

def with_database(db_path = history_db_path)
  dest_path = @tmpdir.join(self.class.name)
  FileUtils.cp(File.expand_path(db_path), dest_path)
  db = Sequel.sqlite(dest_path.to_s)
  yield db
ensure
  db.disconnect if db
end

#with_databases(&block) ⇒ Object



56
57
58
59
60
61
62
# File 'lib/cloudbleed_checker/browser.rb', line 56

def with_databases(&block)
  full_glob = File.expand_path(self.history_db_glob)
  Dir.glob(full_glob).each do |db_path|
    with_database(db_path, &block)
  end
  @hosts
end