Skip to content
Browse files

+ notes, docs, specs

  • Loading branch information...
1 parent 49b6202 commit dc976aea341fae2908acf5c181d5f3b3efd6c4a5 @floere committed Oct 25, 2011
View
8 server/lib/picky/backends/file.rb
@@ -10,25 +10,25 @@ module Backends
#
class File < Backend
- # Returns an object that responds to:
+ # Returns an object that on #initial, #load returns an object that responds to:
# [:token] # => [id, id, id, id, id] (an array of ids)
#
def create_inverted bundle
JSON.new bundle.index_path(:inverted)
end
- # Returns an object that responds to:
+ # Returns an object that on #initial, #load returns an object that responds to:
# [:token] # => 1.23 (a weight)
#
def create_weights bundle
JSON.new bundle.index_path(:weights)
end
- # Returns an object that responds to:
+ # Returns an object that on #initial, #load returns an object that responds to:
# [:encoded] # => [:original, :original] (an array of original symbols this similarity encoded thing maps to)
#
def create_similarity bundle
JSON.new bundle.index_path(:similarity)
end
- # Returns an object that responds to:
+ # Returns an object that on #initial, #load returns an object that responds to:
# [:key] # => value (a value for this config key)
#
def create_configuration bundle
View
3 server/lib/picky/backends/file/basic.rb
@@ -32,6 +32,9 @@ def initialize cache_path
# The initial content before loading.
#
+ # Note: We could also load the mapping file
+ # as in #load.
+ #
def initial
nil
end
View
8 server/lib/picky/backends/memory.rb
@@ -4,25 +4,25 @@ module Backends
class Memory < Backend
- # Returns an object that responds to:
+ # Returns an object that on #initial, #load returns an object that responds to:
# [:token] # => [id, id, id, id, id] (an array of ids)
#
def create_inverted bundle
JSON.new bundle.index_path(:inverted)
end
- # Returns an object that responds to:
+ # Returns an object that on #initial, #load returns an object that responds to:
# [:token] # => 1.23 (a weight)
#
def create_weights bundle
JSON.new bundle.index_path(:weights)
end
- # Returns an object that responds to:
+ # Returns an object that on #initial, #load returns an object that responds to:
# [:encoded] # => [:original, :original] (an array of original symbols this similarity encoded thing maps to)
#
def create_similarity bundle
Marshal.new bundle.index_path(:similarity)
end
- # Returns an object that responds to:
+ # Returns an object that on #initial, #load returns an object that responds to:
# [:key] # => value (a value for this config key)
#
def create_configuration bundle
View
8 server/lib/picky/backends/redis.rb
@@ -12,25 +12,25 @@ def initialize options = {}
@client = options[:client] || ::Redis.new(:db => (options[:db] || 15))
end
- # Returns an object that responds to:
+ # Returns an object that on #initial, #load returns an object that responds to:
# [:token] # => [id, id, id, id, id] (an array of ids)
#
def create_inverted bundle
List.new client, "#{bundle.identifier}:inverted"
end
- # Returns an object that responds to:
+ # Returns an object that on #initial, #load returns an object that responds to:
# [:token] # => 1.23 (a weight)
#
def create_weights bundle
Float.new client, "#{bundle.identifier}:weights"
end
- # Returns an object that responds to:
+ # Returns an object that on #initial, #load returns an object that responds to:
# [:encoded] # => [:original, :original] (an array of original symbols this similarity encoded thing maps to)
#
def create_similarity bundle
List.new client, "#{bundle.identifier}:similarity"
end
- # Returns an object that responds to:
+ # Returns an object that on #initial, #load returns an object that responds to:
# [:key] # => value (a value for this config key)
#
def create_configuration bundle
View
5 server/lib/picky/backends/redis/basic.rb
@@ -25,8 +25,11 @@ def initialize client, namespace
# The initial content before loading.
#
+ # Note: As Redis indexes needn't be loaded per se,
+ # this just returns the same thing as #load.
+ #
def initial
- nil
+ self
end
# Returns itself.
View
56 server/spec/lib/backends/memory/json_spec.rb
@@ -2,29 +2,43 @@
describe Picky::Backends::Memory::JSON do
- let(:file) { described_class.new 'some/cache/path/to/file' }
-
- describe "dump" do
- it "delegates to the given hash" do
- hash = stub :hash
-
- hash.should_receive(:dump_json).once.with "some/cache/path/to/file.memory.json"
-
- file.dump hash
+ context 'hash-based indexes' do
+ let(:json) { described_class.new 'some/cache/path/to/file' }
+
+ describe 'extension' do
+ it 'is correct' do
+ json.extension.should == :json
+ end
end
- end
-
- describe "retrieve" do
- it "raises" do
- lambda do
- file.retrieve
- end.should raise_error("Can't retrieve from JSON file. Use text file.")
+
+ describe 'initial' do
+ it 'is correct' do
+ json.initial.should == {}
+ end
end
- end
-
- describe 'to_s' do
- it 'returns the cache path with the default file extension' do
- file.to_s.should == 'Picky::Backends::Memory::JSON(some/cache/path/to/file.memory.json)'
+
+ describe "dump" do
+ it "delegates to the given hash" do
+ hash = stub :hash
+
+ hash.should_receive(:dump_json).once.with "some/cache/path/to/file.memory.json"
+
+ json.dump hash
+ end
+ end
+
+ describe "retrieve" do
+ it "raises" do
+ lambda do
+ json.retrieve
+ end.should raise_error("Can't retrieve from JSON file. Use text file.")
+ end
+ end
+
+ describe 'to_s' do
+ it 'returns the cache path with the default file extension' do
+ json.to_s.should == 'Picky::Backends::Memory::JSON(some/cache/path/to/file.memory.json)'
+ end
end
end
View
46 server/spec/lib/backends/memory/marshal_spec.rb
@@ -2,29 +2,43 @@
describe Picky::Backends::Memory::Marshal do
- let(:file) { described_class.new 'some/cache/path/to/file' }
+ context 'hash-based indexes' do
+ let(:marshal) { described_class.new 'some/cache/path/to/file' }
- describe "dump" do
- it "delegates to the given hash" do
- hash = stub :hash
+ describe 'extension' do
+ it 'is correct' do
+ marshal.extension.should == :dump
+ end
+ end
+
+ describe 'initial' do
+ it 'is correct' do
+ marshal.initial.should == {}
+ end
+ end
+
+ describe "dump" do
+ it "delegates to the given hash" do
+ hash = stub :hash
- hash.should_receive(:dump_marshal).once.with "some/cache/path/to/file.memory.dump"
+ hash.should_receive(:dump_marshal).once.with "some/cache/path/to/file.memory.dump"
- file.dump hash
+ marshal.dump hash
+ end
end
- end
- describe "retrieve" do
- it "raises" do
- lambda do
- file.retrieve
- end.should raise_error("Can't retrieve from marshalled file. Use text file.")
+ describe "retrieve" do
+ it "raises" do
+ lambda do
+ marshal.retrieve
+ end.should raise_error("Can't retrieve from marshalled file. Use text file.")
+ end
end
- end
- describe 'to_s' do
- it 'returns the cache path with the default file extension' do
- file.to_s.should == 'Picky::Backends::Memory::Marshal(some/cache/path/to/file.memory.dump)'
+ describe 'to_s' do
+ it 'returns the cache path with the default file extension' do
+ marshal.to_s.should == 'Picky::Backends::Memory::Marshal(some/cache/path/to/file.memory.dump)'
+ end
end
end
View
24 server/spec/lib/backends/memory/text_spec.rb
@@ -2,21 +2,33 @@
describe Picky::Backends::Memory::Text do
- before(:each) do
- @file = described_class.new "some_cache_path"
+ let(:text) { described_class.new "some_cache_path" }
+
+ describe 'extension' do
+ it 'is correct' do
+ text.extension.should == :txt
+ end
+ end
+
+ describe 'initial' do
+ it 'raises' do
+ expect {
+ text.initial
+ }.to raise_error("Can't have an initial content from text file. Use JSON or Marshal.")
+ end
end
describe "load" do
it "raises" do
lambda do
- @file.load
+ text.load
end.should raise_error("Can't load from text file. Use JSON or Marshal.")
end
end
describe "dump" do
it "raises" do
lambda do
- @file.dump :anything
+ text.dump :anything
end.should raise_error("Can't dump to text file. Use JSON or Marshal.")
end
end
@@ -27,13 +39,13 @@
::File.should_receive(:open).any_number_of_times.and_yield @io
end
it "yields split lines and returns the id and token text" do
- @file.retrieve do |id, token|
+ text.retrieve do |id, token|
id.should == '123456'
token.should == :some_nice_token
end
end
it "is fast" do
- performance_of { @file.retrieve { |id, token| } }.should < 0.00005
+ performance_of { text.retrieve { |id, token| } }.should < 0.00005
end
end
View
6 server/spec/lib/backends/redis/basic_spec.rb
@@ -16,6 +16,12 @@
end
end
+ describe 'initial' do
+ it 'is correct' do
+ index.initial.class.should == described_class
+ end
+ end
+
describe 'cache_small?' do
context 'size 0' do
before(:each) do

0 comments on commit dc976ae

Please sign in to comment.
Something went wrong with that request. Please try again.