busket 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Christopher Burnett
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.markdown ADDED
@@ -0,0 +1,35 @@
1
+ ##Busket
2
+
3
+ class Foo
4
+ include Busket::Helper
5
+ bucket :meta_data, :identifier => :persisted_id
6
+
7
+ def persisted_id
8
+ 1
9
+ end
10
+ end
11
+
12
+ @model = Foo.new
13
+
14
+ @model.meta_data[:foo] = "bar"
15
+ @model.save_meta_data
16
+
17
+
18
+ puts @model.meta_data["foo"]
19
+ => "bar"
20
+
21
+ Description goes here.
22
+
23
+ ##Note on Patches/Pull Requests
24
+
25
+ * Fork the project.
26
+ * Make your feature addition or bug fix.
27
+ * Add tests for it. This is important so I don't break it in a
28
+ future version unintentionally.
29
+ * Commit, do not mess with rakefile, version, or history.
30
+ (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)
31
+ * Send me a pull request. Bonus points for topic branches.
32
+
33
+ ## Copyright
34
+
35
+ Copyright (c) 2010 Christopher Burnett. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,46 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "busket"
8
+ gem.summary = %Q{MongoDB hash persistence}
9
+ gem.description = %Q{MongoDB hash persistence}
10
+ gem.email = "signalstatic@gmail.com"
11
+ gem.homepage = "http://github.com/twoism/mongo_bucket"
12
+ gem.authors = ["Christopher Burnett"]
13
+ gem.add_development_dependency "rspec", ">= 1.2.9"
14
+ gem.add_dependency('mongo', '0.19.3')
15
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
+ end
17
+ Jeweler::GemcutterTasks.new
18
+ rescue LoadError
19
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
20
+ end
21
+
22
+ require 'spec/rake/spectask'
23
+ Spec::Rake::SpecTask.new(:spec) do |spec|
24
+ spec.libs << 'lib' << 'spec'
25
+ spec.spec_files = FileList['spec/**/*_spec.rb']
26
+ end
27
+
28
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
29
+ spec.libs << 'lib' << 'spec'
30
+ spec.pattern = 'spec/**/*_spec.rb'
31
+ spec.rcov = true
32
+ end
33
+
34
+ task :spec => :check_dependencies
35
+
36
+ task :default => :spec
37
+
38
+ require 'rake/rdoctask'
39
+ Rake::RDocTask.new do |rdoc|
40
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
41
+
42
+ rdoc.rdoc_dir = 'rdoc'
43
+ rdoc.title = "busket #{version}"
44
+ rdoc.rdoc_files.include('README*')
45
+ rdoc.rdoc_files.include('lib/**/*.rb')
46
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.2
data/busket.gemspec ADDED
@@ -0,0 +1,61 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{busket}
8
+ s.version = "0.0.2"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Christopher Burnett"]
12
+ s.date = %q{2010-04-06}
13
+ s.description = %q{MongoDB hash persistence}
14
+ s.email = %q{signalstatic@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.markdown"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.markdown",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "busket.gemspec",
27
+ "lib/busket.rb",
28
+ "lib/busket/helper.rb",
29
+ "mongo_bucket.gemspec",
30
+ "spec.opts",
31
+ "spec/busket_spec.rb",
32
+ "spec/spec.opts",
33
+ "spec/spec_helper.rb"
34
+ ]
35
+ s.homepage = %q{http://github.com/twoism/mongo_bucket}
36
+ s.rdoc_options = ["--charset=UTF-8"]
37
+ s.require_paths = ["lib"]
38
+ s.rubygems_version = %q{1.3.6}
39
+ s.summary = %q{MongoDB hash persistence}
40
+ s.test_files = [
41
+ "spec/busket_spec.rb",
42
+ "spec/spec_helper.rb"
43
+ ]
44
+
45
+ if s.respond_to? :specification_version then
46
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
47
+ s.specification_version = 3
48
+
49
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
50
+ s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
51
+ s.add_runtime_dependency(%q<mongo>, ["= 0.19.3"])
52
+ else
53
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
54
+ s.add_dependency(%q<mongo>, ["= 0.19.3"])
55
+ end
56
+ else
57
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
58
+ s.add_dependency(%q<mongo>, ["= 0.19.3"])
59
+ end
60
+ end
61
+
@@ -0,0 +1,49 @@
1
+ module Busket
2
+ module Helper
3
+ def self.included klass
4
+ klass.class_eval do
5
+ extend ClassMethods
6
+ end
7
+ klass.instance_eval do
8
+ include InstanceMethods
9
+ extend ClassMethods
10
+ write_inheritable_attribute(:buckets, {}) if buckets.nil?
11
+ end
12
+ end
13
+ module ClassMethods
14
+ def bucket name, opts={}
15
+ buckets[name] = opts
16
+
17
+ define_method "#{name}_collection" do
18
+ Busket.mongo_database.collection(name)
19
+ end
20
+
21
+ define_method "#{name}" do
22
+ linked_id = send(self.buckets[name.to_sym][:identifier])
23
+ linked_type = self.class.to_s
24
+ collection_with_name(name).save("linked_id" => linked_id, "linked_type" => linked_type) unless collection_exists?(name)
25
+ self.instance_variable_get("@#{name}") || self.instance_variable_set("@#{name}", collection_with_name(name).find_one("linked_id" => linked_id, "linked_type" => linked_type))
26
+ end
27
+
28
+ define_method "save_#{name}" do
29
+ collection_with_name(name).save self.instance_variable_get("@#{name}")
30
+ end
31
+ end
32
+ def buckets
33
+ read_inheritable_attribute(:buckets)
34
+ end
35
+ end
36
+ module InstanceMethods
37
+ def collection_exists? name
38
+ !!collection_with_name(name).find_one(:linked_id => self.send(self.buckets[name][:identifier]), :linked_type => self.class.to_s)
39
+ end
40
+
41
+ def collection_with_name name
42
+ self.send("#{name}_collection".to_sym)
43
+ end
44
+ def buckets
45
+ self.class.buckets
46
+ end
47
+ end
48
+ end
49
+ end
data/lib/busket.rb ADDED
@@ -0,0 +1,32 @@
1
+ require 'mongo'
2
+ require 'active_support'
3
+
4
+ module Busket
5
+ @@database_name = nil
6
+
7
+ def self.mongo_connection
8
+ @@connection ||= Mongo::Connection.new
9
+ end
10
+
11
+ def self.mongo_connection=(new_connection)
12
+ @@connection = new_connection
13
+ end
14
+
15
+ def self.mongo_logger
16
+ connection.logger
17
+ end
18
+
19
+ def self.mongo_database=(name)
20
+ @@database = nil
21
+ @@database_name = name
22
+ end
23
+
24
+ def self.mongo_database
25
+ raise 'You forgot to set the default database name: Busket.database = "foobar"' unless @@database_name
26
+
27
+ @@database ||= Busket.mongo_connection.db(@@database_name)
28
+ end
29
+
30
+ end
31
+
32
+ require "busket/helper"
@@ -0,0 +1,57 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{mongo_bucket}
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Christopher Burnett"]
12
+ s.date = %q{2010-04-05}
13
+ s.description = %q{MongoDB hash persistence}
14
+ s.email = %q{signalstatic@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.markdown"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.markdown",
24
+ "Rakefile",
25
+ "lib/busket.rb",
26
+ "lib/busket/helper.rb",
27
+ "spec/busket_spec.rb",
28
+ "spec/spec.opts",
29
+ "spec/spec_helper.rb"
30
+ ]
31
+ s.homepage = %q{http://github.com/twoism/mongo_bucket}
32
+ s.rdoc_options = ["--charset=UTF-8"]
33
+ s.require_paths = ["lib"]
34
+ s.rubygems_version = %q{1.3.5}
35
+ s.summary = %q{MongoDB hash persistence}
36
+ s.test_files = [
37
+ "spec/busket_spec.rb",
38
+ "spec/spec_helper.rb"
39
+ ]
40
+
41
+ if s.respond_to? :specification_version then
42
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
43
+ s.specification_version = 3
44
+
45
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
46
+ s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
47
+ s.add_runtime_dependency(%q<mongo>, ["= 0.19.3"])
48
+ else
49
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
50
+ s.add_dependency(%q<mongo>, ["= 0.19.3"])
51
+ end
52
+ else
53
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
54
+ s.add_dependency(%q<mongo>, ["= 0.19.3"])
55
+ end
56
+ end
57
+
@@ -0,0 +1,89 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ class Foo
4
+ include Busket::Helper
5
+ bucket :meta_data, :identifier => :persisted_id
6
+ bucket :hoge, :identifier => :persisted_id
7
+ bucket :fuga, :identifier => :persisted_id
8
+
9
+ def persisted_id
10
+ 1
11
+ end
12
+ end
13
+
14
+ describe "Busket" do
15
+ describe "#connection" do
16
+ it "should be a Mongo connections" do
17
+ Busket.mongo_connection.should be_a Mongo::Connection
18
+ end
19
+ end
20
+ describe "#connection=" do
21
+ it "should set the base connection" do
22
+ connection = Mongo::Connection.new('localhost')
23
+ Busket.mongo_connection = connection
24
+ Busket.mongo_connection.should == connection
25
+ end
26
+ end
27
+ describe "#database" do
28
+ it "should raise when not set" do
29
+ Busket.mongo_database = nil
30
+ lambda { Busket.mongo_database }.should raise_error RuntimeError
31
+ end
32
+ describe "when set" do
33
+ before(:each) do
34
+ Busket.mongo_database = 'testing_busket'
35
+ end
36
+ it "should be a db" do
37
+ Busket.mongo_database.should be_a Mongo::DB
38
+ end
39
+ it "should have the correct name" do
40
+ Busket.mongo_database.name.should == 'testing_busket'
41
+ end
42
+ end
43
+ end
44
+ describe "#included" do
45
+ [:meta_data,:hoge,:fuga].each do |field|
46
+ before(:all) do
47
+ @klass = Foo.new
48
+ @klass.send(field)["body"] = "#{field}, Are you a human?"
49
+ @klass.send("save_#{field}")
50
+ end
51
+ it "should have an instance bucket for #{field}" do
52
+ @klass.buckets.should include field
53
+ end
54
+ it "should have a class bucket for #{field}" do
55
+ Foo.buckets.should include field
56
+ end
57
+ it "should respond to the bucket name (#{field})" do
58
+ @klass.should respond_to field
59
+ end
60
+ it "should respond to the save action save_#{field}" do
61
+ @klass.should respond_to "save_#{field}".to_sym
62
+ end
63
+ it "should be a hash" do
64
+ @klass.send(field).should be_a Hash
65
+ end
66
+ it "should create one mongo entry for #{field}" do
67
+ @klass.send("#{field}_collection").count.should == 1
68
+ end
69
+ it "should have the correct body in #{field}" do
70
+ @klass.send(field)["body"].should == "#{field}, Are you a human?"
71
+ end
72
+ it "#{field} should exist in mongo" do
73
+ Busket.mongo_database.collection(field.to_s).find.first.should == @klass.send(field)
74
+ end
75
+
76
+ describe "on change" do
77
+ before(:each) do
78
+ @body = "Negative, I am a meat popsicle!"
79
+ @klass.send(field)[:body] = @body
80
+ @klass.send("save_#{field}")
81
+ @persisted = Foo.new
82
+ end
83
+ it "should persist meta data for #{field}" do
84
+ @persisted.send(field)["body"].should == @body
85
+ end
86
+ end
87
+ end
88
+ end
89
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1,3 @@
1
+ --colour
2
+ --format nested
3
+ --loadby mtime
@@ -0,0 +1,16 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'rubygems'
4
+ require 'busket'
5
+ require 'spec'
6
+ require 'spec/autorun'
7
+
8
+ Busket.mongo_connection = Mongo::Connection.new('localhost',nil, :logger=>Logger.new('mongo.log'))
9
+ Busket.mongo_database = 'testing_busket'
10
+
11
+ Spec::Runner.configure do |config|
12
+ config.mock_with :mocha
13
+ config.after :suite do
14
+ Busket.mongo_database.collections.each(&:drop)
15
+ end
16
+ end
data/spec.opts ADDED
@@ -0,0 +1,5 @@
1
+ --colour
2
+ --format nested
3
+ --format html:log/rspec_report.html
4
+ --format profile:log/spec-profile.txt
5
+ --loadby mtime
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: busket
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 2
9
+ version: 0.0.2
10
+ platform: ruby
11
+ authors:
12
+ - Christopher Burnett
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-04-06 00:00:00 -07:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rspec
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 1
29
+ - 2
30
+ - 9
31
+ version: 1.2.9
32
+ type: :development
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: mongo
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 0
43
+ - 19
44
+ - 3
45
+ version: 0.19.3
46
+ type: :runtime
47
+ version_requirements: *id002
48
+ description: MongoDB hash persistence
49
+ email: signalstatic@gmail.com
50
+ executables: []
51
+
52
+ extensions: []
53
+
54
+ extra_rdoc_files:
55
+ - LICENSE
56
+ - README.markdown
57
+ files:
58
+ - .document
59
+ - .gitignore
60
+ - LICENSE
61
+ - README.markdown
62
+ - Rakefile
63
+ - VERSION
64
+ - busket.gemspec
65
+ - lib/busket.rb
66
+ - lib/busket/helper.rb
67
+ - mongo_bucket.gemspec
68
+ - spec.opts
69
+ - spec/busket_spec.rb
70
+ - spec/spec.opts
71
+ - spec/spec_helper.rb
72
+ has_rdoc: true
73
+ homepage: http://github.com/twoism/mongo_bucket
74
+ licenses: []
75
+
76
+ post_install_message:
77
+ rdoc_options:
78
+ - --charset=UTF-8
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ segments:
86
+ - 0
87
+ version: "0"
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ segments:
93
+ - 0
94
+ version: "0"
95
+ requirements: []
96
+
97
+ rubyforge_project:
98
+ rubygems_version: 1.3.6
99
+ signing_key:
100
+ specification_version: 3
101
+ summary: MongoDB hash persistence
102
+ test_files:
103
+ - spec/busket_spec.rb
104
+ - spec/spec_helper.rb