Permalink
Browse files

more renaming

  • Loading branch information...
thejefflarson committed Oct 18, 2012
1 parent 198a940 commit 7401cf199b5738a12f61833d9b520c3effd0ad02
Showing with 86 additions and 11 deletions.
  1. +1 −0 .gitignore
  2. +1 −1 Gemfile
  3. +1 −1 Rakefile
  4. +2 −2 falconer.gemspec → daybreak.gemspec
  5. +6 −6 lib/daybreak.rb
  6. +74 −0 lib/daybreak/writer.rb
  7. +1 −1 test/{falconer_test.rb → daybreak_test.rb}
View
@@ -1,4 +1,5 @@
*.db
coverage
.DS_Store
+.yardoc
Gemfile.lock
View
@@ -1,4 +1,4 @@
source 'https://rubygems.org'
-# Specify your gem's dependencies in falconer.gemspec
+# Specify your gem's dependencies in daybreak.gemspec
gemspec
View
@@ -2,6 +2,6 @@
require "bundler/gem_tasks"
task :default do
- require "./test/falconer_test.rb"
+ require "./test/daybreak_test.rb"
end
@@ -1,12 +1,12 @@
# -*- encoding: utf-8 -*-
-require File.expand_path('../lib/falconer/version', __FILE__)
+require File.expand_path('../lib/daybreak/version', __FILE__)
Gem::Specification.new do |gem|
gem.authors = ["Jeff Larson"]
gem.email = ["thejefflarson@gmail.com"]
gem.description = %q{A simple dimple key-value store for ruby.}
gem.summary = %q{Daybreak provides an in memory key-value store that is easily enumerable in ruby.}
- gem.homepage = "http://propublica.github.com/falconer/"
+ gem.homepage = "http://propublica.github.com/daybreak/"
gem.files = `git ls-files`.split($\)
gem.test_files = gem.files.grep(%r{^(test)/})
View
@@ -5,9 +5,9 @@ module Daybreak
require 'tempfile'
require 'thread'
require 'zlib'
-require "#{Daybreak::ROOT}/falconer/version"
-require "#{Daybreak::ROOT}/falconer/locking"
-require "#{Daybreak::ROOT}/falconer/record"
-require "#{Daybreak::ROOT}/falconer/writer"
-require "#{Daybreak::ROOT}/falconer/reader"
-require "#{Daybreak::ROOT}/falconer/db"
+require "#{Daybreak::ROOT}/daybreak/version"
+require "#{Daybreak::ROOT}/daybreak/locking"
+require "#{Daybreak::ROOT}/daybreak/record"
+require "#{Daybreak::ROOT}/daybreak/writer"
+require "#{Daybreak::ROOT}/daybreak/reader"
+require "#{Daybreak::ROOT}/daybreak/db"
View
@@ -14,6 +14,23 @@ def finish!
@worker.finish!
end
+ def flush!
+ @worker.flush!module Daybreak
+ class Writer
+ def initialize(file)
+ @fd = File.open file, 'a'
+ @fd.binmode
+ @worker = Worker.new(@fd)
+ end
+
+ def write(record)
+ @worker.enqueue record
+ end
+
+ def finish!
+ @worker.finish!
+ end
+
def flush!
@worker.flush!
end
@@ -72,3 +89,60 @@ def finish!
end
end
end
+
+ end
+
+ def close!
+ finish!
+ @fd.close
+ end
+
+ def truncate!
+ @fd.truncate(0)
+ end
+
+ private
+
+ class Worker
+ include Locking
+
+ def initialize(fd)
+ @queue = Queue.new
+ @fd = fd
+ @buffer = ""
+ @thread = Thread.new { work }
+ at_exit { finish! }
+ end
+
+ def enqueue(record)
+ @queue << record.representation
+ end
+
+ def work
+ str = ""
+ loop do
+ str = @queue.pop
+ if str.nil?
+ @fd.flush
+ break
+ end
+ read, write = IO.select [], [@fd]
+ if write and fd = write.first
+ lock(@fd, File::LOCK_EX) { fd.write(str) }
+ end
+ end
+ end
+
+ def flush!
+ @queue.push nil
+ @thread.join
+ @thread = Thread.new { work }
+ end
+
+ def finish!
+ @queue.push nil
+ @thread.join
+ end
+ end
+ end
+end
@@ -8,7 +8,7 @@
HERE = File.expand_path(File.dirname(__FILE__))
DB_PATH = File.join HERE, "test.db"
-require File.join HERE, '..', 'lib', 'falconer'
+require File.join HERE, '..', 'lib', 'daybreak'
describe "database functions" do
before do

0 comments on commit 7401cf1

Please sign in to comment.