Permalink
Browse files

Basic setup and initialize with database.

  • Loading branch information...
0 parents commit fa3730556eaec6903531c5ce8dae89773946b21c @jnunemaker committed Jun 2, 2010
Showing with 181 additions and 0 deletions.
  1. +20 −0 LICENSE
  2. +15 −0 README.rdoc
  3. +28 −0 Rakefile
  4. +18 −0 bin.gemspec
  5. +7 −0 lib/bin.rb
  6. +10 −0 lib/bin/store.rb
  7. +3 −0 lib/bin/version.rb
  8. +16 −0 spec/bin/store_spec.rb
  9. +7 −0 spec/bin_spec.rb
  10. +7 −0 spec/helper.rb
  11. +4 −0 spec/spec.opts
  12. +46 −0 specs.watchr
20 LICENSE
@@ -0,0 +1,20 @@
+Copyright (c) 2010 John Nunemaker
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,15 @@
+= Bin
+
+ActiveSupport MongoDB Cache store.
+
+== Note on Patches/Pull Requests
+
+* Fork the project.
+* Make your feature addition or bug fix.
+* Add tests for it. This is important so I don't break it in a future version unintentionally.
+* Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
+* Send me a pull request. Bonus points for topic branches.
+
+== Copyright
+
+Copyright (c) 2010 John Nunemaker. See LICENSE for details.
@@ -0,0 +1,28 @@
+require 'rubygems'
+require 'rake'
+require 'spec/rake/spectask'
+require File.expand_path('../lib/bin/version', __FILE__)
+
+Spec::Rake::SpecTask.new do |t|
+ t.ruby_opts << '-rubygems'
+end
+
+task :default => :spec
+
+desc 'Builds the gem'
+task :build do
+ sh "gem build bin.gemspec"
+end
+
+desc 'Builds and installs the gem'
+task :install => :build do
+ sh "gem install bin-#{Bin::Version}"
+end
+
+desc 'Tags version, pushes to remote, and pushes gem'
+task :release => :build do
+ sh "git tag v#{Bin::Version}"
+ sh "git push origin master"
+ sh "git push origin v#{Bin::Version}"
+ sh "gem push bin-#{Bin::Version}.gem"
+end
@@ -0,0 +1,18 @@
+# encoding: UTF-8
+require File.expand_path('../lib/bin/version', __FILE__)
+
+Gem::Specification.new do |s|
+ s.name = 'bin'
+ s.homepage = 'http://github.com/jnunemaker/bin'
+ s.summary = 'ActiveSupport MongoDB Cache store.'
+ s.require_path = 'lib'
+ s.authors = ['John Nunemaker']
+ s.email = ['nunemaker@gmail.com']
+ s.version = Bin::Version
+ s.platform = Gem::Platform::RUBY
+ s.files = Dir.glob("{bin,lib}/**/*") + %w[LICENSE README.rdoc]
+
+ s.add_dependency 'mongo', '~> 1.0.1'
+ s.add_dependency 'activesupport', '>= 2.3.4'
+ s.add_development_dependency 'rspec', '~> 1.3.0'
+end
@@ -0,0 +1,7 @@
+# encoding: UTF-8
+require 'active_support/all'
+require 'mongo'
+
+module Bin
+ autoload :Store, 'bin/store'
+end
@@ -0,0 +1,10 @@
+# encoding: UTF-8
+module Bin
+ class Store < ActiveSupport::Cache::Store
+ attr_reader :database
+
+ def initialize(database)
+ @database = database
+ end
+ end
+end
@@ -0,0 +1,3 @@
+module Bin
+ Version = '0.1'
+end
@@ -0,0 +1,16 @@
+require 'helper'
+
+describe Bin::Store do
+ before(:each) do
+ DB.collections.each do |collection|
+ collection.remove
+ collection.drop_indexes
+ end
+ end
+
+ context "#initialize" do
+ it "accept a database" do
+ Bin::Store.new(DB).database.should == DB
+ end
+ end
+end
@@ -0,0 +1,7 @@
+require 'helper'
+
+describe Bin do
+ it "autoloads Store" do
+ lambda { Bin::Store }.should_not raise_error(NameError)
+ end
+end
@@ -0,0 +1,7 @@
+$:.unshift(File.expand_path('../../lib', __FILE__))
+
+require 'bin'
+require 'spec'
+
+connection = Mongo::Connection.new
+DB = connection.db('bin-store-test')
@@ -0,0 +1,4 @@
+--colour
+--timeout
+20
+--diff
@@ -0,0 +1,46 @@
+def growl(title, msg, img)
+ %x{growlnotify -m #{ msg.inspect} -t #{title.inspect} --image ~/.watchr/#{img}.png}
+end
+
+def form_growl_message(str)
+ msg = str.split("\n").last
+ if msg =~ /(\d)\sfailure/
+ img = $1.to_i > 0 ? 'fail' : 'pass'
+ end
+ growl 'Results', msg, img
+end
+
+def run(cmd)
+ puts cmd
+ output = ""
+ IO.popen(cmd) do |com|
+ com.each_char do |c|
+ print c
+ output << c
+ $stdout.flush
+ end
+ end
+ form_growl_message output
+end
+
+def run_spec(path)
+ path.gsub!('lib/', 'spec/')
+ path.gsub!('_spec', '')
+ file_name = File.basename(path, '.rb')
+ path.gsub!(file_name, file_name + "_spec")
+ run %Q(spec #{path})
+end
+
+watch('spec/helper\.rb') { system('clear'); run('rake') }
+watch('lib/.*\.rb') { |m| system('clear'); run_spec(m[0]) }
+watch('spec/.*_spec\.rb') { |m| system('clear'); run_spec(m[0]) }
+
+# Ctrl-\
+Signal.trap('QUIT') do
+ puts " --- Running all tests ---\n\n"
+ run('rake')
+end
+
+# Ctrl-C
+Signal.trap('INT') { abort("\n") }
+

0 comments on commit fa37305

Please sign in to comment.