-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
452 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
*.swp | ||
Gemfile.lock | ||
test.db | ||
test.tch | ||
test.kch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
source :rubygems | ||
|
||
gemspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,25 @@ | ||
require 'rubygems' | ||
require 'rake' | ||
require 'rspec/core/rake_task' | ||
|
||
require 'spec/rake/spectask' | ||
Spec::Rake::SpecTask.new(:spec) do |spec| | ||
spec.libs << 'lib' << 'spec' | ||
spec.spec_files = FileList['spec/**/*_spec.rb'] | ||
desc "Run all specs" | ||
RSpec::Core::RakeTask.new(:rspec) do |spec| | ||
spec.pattern = 'spec/**/*_spec.rb' | ||
end | ||
|
||
Spec::Rake::SpecTask.new(:rcov) do |spec| | ||
spec.libs << 'lib' << 'spec' | ||
RSpec::Core::RakeTask.new(:rcov) do |spec| | ||
spec.pattern = 'spec/**/*_spec.rb' | ||
spec.rcov = true | ||
end | ||
|
||
task :default => :spec | ||
task :default => :rspec | ||
|
||
require 'rake/rdoctask' | ||
Rake::RDocTask.new do |rdoc| | ||
require 'rdoc/task' | ||
RDoc::Task.new do |rdoc| | ||
version = File.exist?('VERSION') ? File.read('VERSION') : "" | ||
|
||
rdoc.rdoc_dir = 'rdoc' | ||
rdoc.title = "anemone #{version}" | ||
rdoc.rdoc_files.include('README*') | ||
rdoc.rdoc_files.include('lib/**/*.rb') | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
0.6.1 | ||
0.7.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ | |
|
||
module Anemone | ||
|
||
VERSION = '0.6.1'; | ||
VERSION = '0.7.0'; | ||
|
||
# | ||
# Convenience method to start a crawl | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
begin | ||
require 'kyotocabinet' | ||
rescue LoadError | ||
puts $! | ||
puts "You need the kyotocabinet-ruby gem to use Anemone::Storage::KyotoCabinet" | ||
exit | ||
end | ||
|
||
require 'forwardable' | ||
|
||
module Anemone | ||
module Storage | ||
class KyotoCabinet | ||
extend Forwardable | ||
|
||
def_delegators :@db, :close, :size, :each | ||
|
||
def initialize(file) | ||
raise "KyotoCabinet filename must have .kch extension" if File.extname(file) != '.kch' | ||
@db = ::KyotoCabinet::DB::new | ||
@db.open(file, ::KyotoCabinet::DB::OWRITER | ::KyotoCabinet::DB::OCREATE) | ||
@db.clear | ||
end | ||
|
||
def [](key) | ||
if value = @db[key] | ||
load_value(value) | ||
end | ||
end | ||
|
||
def []=(key, value) | ||
@db[key] = [Marshal.dump(value)].pack("m") | ||
end | ||
|
||
def each | ||
@db.each do |k, v| | ||
yield(k, load_value(v)) | ||
end | ||
end | ||
|
||
def has_key?(key) | ||
# Kyoto Cabinet doesn't have a way to query whether a key exists, so hack it | ||
keys = @db.match_prefix(key) | ||
!!keys && keys.include?(key) | ||
end | ||
|
||
def keys | ||
acc = [] | ||
@db.each_key { |key| acc << key.first } | ||
acc | ||
end | ||
|
||
def delete(key) | ||
value = self[key] | ||
@db.delete(key) | ||
value | ||
end | ||
|
||
def merge!(hash) | ||
hash.each { |key, value| self[key] = value } | ||
self | ||
end | ||
|
||
private | ||
|
||
def load_value(value) | ||
Marshal.load(value.unpack("m")[0]) | ||
end | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
begin | ||
require 'sqlite3' | ||
rescue LoadError | ||
puts "You need the sqlite3 gem to use Anemone::Storage::SQLite3" | ||
exit | ||
end | ||
|
||
module Anemone | ||
module Storage | ||
class SQLite3 | ||
|
||
def initialize(file) | ||
@db = ::SQLite3::Database.new(file) | ||
create_schema | ||
end | ||
|
||
def [](url) | ||
value = @db.get_first_value('SELECT data FROM anemone_storage WHERE key = ?', url.to_s) | ||
if value | ||
Marshal.load(value) | ||
end | ||
end | ||
|
||
def []=(url, value) | ||
data = Marshal.dump(value) | ||
if has_key?(url) | ||
@db.execute('UPDATE anemone_storage SET data = ? WHERE key = ?', data, url.to_s) | ||
else | ||
@db.execute('INSERT INTO anemone_storage (data, key) VALUES(?, ?)', data, url.to_s) | ||
end | ||
end | ||
|
||
def delete(url) | ||
page = self[url] | ||
@db.execute('DELETE FROM anemone_storage WHERE key = ?', url.to_s) | ||
page | ||
end | ||
|
||
def each | ||
@db.execute("SELECT key, data FROM anemone_storage ORDER BY id") do |row| | ||
value = Marshal.load(row[1]) | ||
yield row[0], value | ||
end | ||
end | ||
|
||
def merge!(hash) | ||
hash.each { |key, value| self[key] = value } | ||
self | ||
end | ||
|
||
def size | ||
@db.get_first_value('SELECT COUNT(id) FROM anemone_storage') | ||
end | ||
|
||
def keys | ||
@db.execute("SELECT key FROM anemone_storage ORDER BY id").map{|t| t[0]} | ||
end | ||
|
||
def has_key?(url) | ||
!!@db.get_first_value('SELECT id FROM anemone_storage WHERE key = ?', url.to_s) | ||
end | ||
|
||
def close | ||
@db.close | ||
end | ||
|
||
private | ||
|
||
def create_schema | ||
@db.execute_batch <<SQL | ||
create table if not exists anemone_storage ( | ||
id INTEGER PRIMARY KEY ASC, | ||
key TEXT, | ||
data BLOB | ||
); | ||
create index if not exists anemone_key_idx on anemone_storage (key); | ||
SQL | ||
end | ||
|
||
def load_page(hash) | ||
BINARY_FIELDS.each do |field| | ||
hash[field] = hash[field].to_s | ||
end | ||
Page.from_hash(hash) | ||
end | ||
|
||
end | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.