mince 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile.lock +3 -3
- data/README.md +6 -0
- data/lib/mince/config.rb +24 -0
- data/lib/mince/connection.rb +3 -13
- data/lib/mince/version.rb +1 -1
- data/spec/lib/config_spec.rb +32 -0
- data/spec/lib/connection_spec.rb +7 -2
- metadata +6 -4
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
mince (1.
|
4
|
+
mince (1.1.0)
|
5
5
|
activesupport (~> 3.0)
|
6
6
|
bson_ext (~> 1.5.2)
|
7
7
|
mongo (~> 1.5.2)
|
@@ -9,14 +9,14 @@ PATH
|
|
9
9
|
GEM
|
10
10
|
remote: http://rubygems.org/
|
11
11
|
specs:
|
12
|
-
activesupport (3.2.
|
12
|
+
activesupport (3.2.8)
|
13
13
|
i18n (~> 0.6)
|
14
14
|
multi_json (~> 1.0)
|
15
15
|
bson (1.5.2)
|
16
16
|
bson_ext (1.5.2)
|
17
17
|
bson (= 1.5.2)
|
18
18
|
diff-lcs (1.1.3)
|
19
|
-
i18n (0.6.
|
19
|
+
i18n (0.6.1)
|
20
20
|
mongo (1.5.2)
|
21
21
|
bson (= 1.5.2)
|
22
22
|
multi_json (1.3.6)
|
data/README.md
CHANGED
@@ -18,6 +18,12 @@ Start MongoDB at localhost (currently does not support authentication against Mo
|
|
18
18
|
From there you can use Mince to add and retrieve data.
|
19
19
|
|
20
20
|
<pre>
|
21
|
+
# Has default db name
|
22
|
+
Mince::Config.database_name # => 'mince'
|
23
|
+
|
24
|
+
# Set the database name
|
25
|
+
Mince::Config.database_name = 'my_custom_db_name'
|
26
|
+
|
21
27
|
# Add a book to the books collection
|
22
28
|
Mince::DataStore.add 'books', title: 'The World In Photographs', publisher: 'National Geographic'
|
23
29
|
|
data/lib/mince/config.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'active_support/core_ext/object/blank'
|
2
|
+
require 'singleton'
|
3
|
+
|
4
|
+
class Mince::Config
|
5
|
+
include Singleton
|
6
|
+
|
7
|
+
attr_reader :database_name
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
self.database_name = "mince"
|
11
|
+
end
|
12
|
+
|
13
|
+
def database_name=(val)
|
14
|
+
@database_name = [val, ENV['TEST_ENV_NUMBER']].compact.join("-")
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.database_name
|
18
|
+
instance.database_name
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.database_name=(val)
|
22
|
+
instance.database_name = val
|
23
|
+
end
|
24
|
+
end
|
data/lib/mince/connection.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'mongo'
|
2
2
|
require 'singleton'
|
3
|
-
|
3
|
+
require_relative 'config'
|
4
4
|
|
5
5
|
module Mince
|
6
6
|
class Connection
|
@@ -10,17 +10,7 @@ module Mince
|
|
10
10
|
|
11
11
|
def initialize
|
12
12
|
@connection = Mongo::Connection.new
|
13
|
-
@db = connection.db(
|
14
|
-
end
|
15
|
-
|
16
|
-
# todo: push this into a config class which uses yaml or something like that to pull in the different environment settings?
|
17
|
-
def database
|
18
|
-
env_suffix = if (ENV['TEST_ENV_NUMBER'].blank?)
|
19
|
-
""
|
20
|
-
else
|
21
|
-
"-#{ENV['TEST_ENV_NUMBER']}"
|
22
|
-
end
|
23
|
-
"mince#{env_suffix}"
|
13
|
+
@db = connection.db(Mince::Config.database_name)
|
24
14
|
end
|
25
15
|
end
|
26
|
-
end
|
16
|
+
end
|
data/lib/mince/version.rb
CHANGED
@@ -0,0 +1,32 @@
|
|
1
|
+
require_relative '../../lib/mince/config'
|
2
|
+
|
3
|
+
describe Mince::Config do
|
4
|
+
it 'has a default database name' do
|
5
|
+
described_class.database_name.should == 'mince'
|
6
|
+
end
|
7
|
+
|
8
|
+
context 'when running multi threaded tests' do
|
9
|
+
before do
|
10
|
+
ENV['TEST_ENV_NUMBER'] = '3'
|
11
|
+
described_class.database_name = 'test'
|
12
|
+
end
|
13
|
+
|
14
|
+
after do
|
15
|
+
ENV['TEST_ENV_NUMBER'] = nil
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'appends the test number to the database name' do
|
19
|
+
described_class.database_name.should == 'test-3'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'when specifying a custom database name' do
|
24
|
+
before do
|
25
|
+
described_class.database_name = 'custom'
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'uses the custom database name' do
|
29
|
+
described_class.database_name.should == 'custom'
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/spec/lib/connection_spec.rb
CHANGED
@@ -5,11 +5,16 @@ describe Mince::Connection do
|
|
5
5
|
|
6
6
|
let(:mongo_connection) { mock 'a mongo connection object', :db => db }
|
7
7
|
let(:db) { mock 'db'}
|
8
|
+
let(:config_database_name) { mock }
|
9
|
+
|
10
|
+
before do
|
11
|
+
Mince::Config.stub(database_name: config_database_name)
|
12
|
+
end
|
8
13
|
|
9
14
|
it 'is a mongo connection' do
|
10
15
|
Mongo::Connection.should_receive(:new).and_return(mongo_connection)
|
11
|
-
mongo_connection.should_receive(:db).with(
|
16
|
+
mongo_connection.should_receive(:db).with(config_database_name).and_return(db)
|
12
17
|
|
13
18
|
subject.connection.should == mongo_connection
|
14
19
|
end
|
15
|
-
end
|
20
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mince
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2012-
|
14
|
+
date: 2012-09-17 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: activesupport
|
@@ -110,10 +110,12 @@ files:
|
|
110
110
|
- README.md
|
111
111
|
- Rakefile
|
112
112
|
- lib/mince.rb
|
113
|
+
- lib/mince/config.rb
|
113
114
|
- lib/mince/connection.rb
|
114
115
|
- lib/mince/data_store.rb
|
115
116
|
- lib/mince/version.rb
|
116
117
|
- mince.gemspec
|
118
|
+
- spec/lib/config_spec.rb
|
117
119
|
- spec/lib/connection_spec.rb
|
118
120
|
- spec/lib/data_store_spec.rb
|
119
121
|
homepage: https://github.com/asynchrony/mince
|
@@ -136,11 +138,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
136
138
|
version: '0'
|
137
139
|
requirements: []
|
138
140
|
rubyforge_project: mince
|
139
|
-
rubygems_version: 1.8.
|
141
|
+
rubygems_version: 1.8.21
|
140
142
|
signing_key:
|
141
143
|
specification_version: 3
|
142
144
|
summary: Lightweight MongoDB ORM for Ruby.
|
143
145
|
test_files:
|
146
|
+
- spec/lib/config_spec.rb
|
144
147
|
- spec/lib/connection_spec.rb
|
145
148
|
- spec/lib/data_store_spec.rb
|
146
|
-
has_rdoc:
|