Class: Ronin::Web::Spider::GitArchive
- Defined in:
- lib/ronin/web/spider/git_archive.rb
Overview
Represents a web archive directory that is backed by Git.
Example
Spider a host and archive every web page to a Git repository:
require 'ronin/web/spider'
require 'ronin/web/spider/git_archive'
require 'date'
Ronin::Web::Spider::GitArchive.open('path/to/root') do |archive|
archive.commit("Updated #{Date.today}") do
Ronin::Web::Spider.every_page(host: 'example.com') do |page|
archive.write(page.url,page.body)
end
end
end
Instance Attribute Summary
Attributes inherited from Archive
Class Method Summary collapse
-
.open(root) {|archive| ... } ⇒ GitArchive
Creates the Git archive, if it already does not exist.
Instance Method Summary collapse
-
#commit(message) {|self| ... } ⇒ true
Commits changes to the Git archive.
-
#git? ⇒ Boolean
Determines if the git repository has been initialized.
-
#init ⇒ true
Initializes the Git repository.
-
#write(url, body) ⇒ String
Saves a webpage to the Git archive.
Methods inherited from Archive
Constructor Details
This class inherits a constructor from Ronin::Web::Spider::Archive
Class Method Details
.open(root) {|archive| ... } ⇒ GitArchive
Creates the Git archive, if it already does not exist.
64 65 66 67 68 69 70 |
# File 'lib/ronin/web/spider/git_archive.rb', line 64 def self.open(root) super(root) do |archive| archive.init unless archive.git? yield archive if block_given? end end |
Instance Method Details
#commit(message) {|self| ... } ⇒ true
Commits changes to the Git archive.
154 155 156 157 158 |
# File 'lib/ronin/web/spider/git_archive.rb', line 154 def commit() yield self if block_given? git('commit','-m',.to_s) end |
#git? ⇒ Boolean
Determines if the git repository has been initialized.
77 78 79 |
# File 'lib/ronin/web/spider/git_archive.rb', line 77 def git? File.directory?(File.join(@root,'.git')) end |
#init ⇒ true
Initializes the Git repository.
94 95 96 |
# File 'lib/ronin/web/spider/git_archive.rb', line 94 def init git('init') end |
#write(url, body) ⇒ String
Saves a webpage to the Git archive.
117 118 119 120 121 122 |
# File 'lib/ronin/web/spider/git_archive.rb', line 117 def write(url,body) absolute_path = super(url,body) git('add',absolute_path) return absolute_path end |