mince 1.2.1 → 2.0.0.pre

Sign up to get free protection for your applications and to get access to all the features.
data/lib/mince/config.rb CHANGED
@@ -1,26 +1,17 @@
1
- require 'active_support/core_ext/object/blank'
2
- require 'singleton'
3
-
4
1
  module Mince
2
+ require 'singleton'
3
+
5
4
  class Config
6
5
  include Singleton
7
6
 
8
- attr_reader :database_name
9
-
10
- def initialize
11
- self.database_name = "mince"
12
- end
13
-
14
- def database_name=(val)
15
- @database_name = [val, ENV['TEST_ENV_NUMBER']].compact.join("-")
16
- end
7
+ attr_accessor :interface
17
8
 
18
- def self.database_name
19
- instance.database_name
9
+ def self.interface=(interface)
10
+ instance.interface = interface
20
11
  end
21
12
 
22
- def self.database_name=(val)
23
- instance.database_name = val
13
+ def self.interface
14
+ instance.interface
24
15
  end
25
16
  end
26
17
  end
@@ -0,0 +1,132 @@
1
+ require_relative '../../mince'
2
+
3
+ shared_examples_for 'a mince interface' do
4
+ describe 'Mince Interface v2' do
5
+ let(:interface) { Mince::Config.interface }
6
+ let(:primary_key) { interface.primary_key }
7
+
8
+ let(:data1) { { primary_key => 1, field_1: 'value 1', field_2: 3, field_3: [1, 2, 3], shared_between_1_and_2: 'awesome_value', :some_array => [1, 2, 3, 4]} }
9
+ let(:data2) { { primary_key => 2, field_1: 'value 1.2', field_2: 6, shared_between_1_and_2: 'awesome_value', :some_array => [4, 5, 6]} }
10
+ let(:data3) { { primary_key => 3, field_1: 'value 3', field_2: 9, shared_between_1_and_2: 'not the same as 1 and 2', :some_array => [1, 7]} }
11
+
12
+ before do
13
+ interface.set_data({})
14
+
15
+ interface.insert(:some_collection, [data1, data2, data3])
16
+ end
17
+
18
+ describe "Generating a primary key" do
19
+ subject do
20
+ (1..number_of_records).map do |salt|
21
+ interface.generate_unique_id(salt)
22
+ end
23
+ end
24
+
25
+ let(:number_of_records) { 1000 }
26
+
27
+ it 'creates a unique id' do
28
+ subject.uniq.size.should == number_of_records
29
+ end
30
+ end
31
+
32
+ it 'can delete a field' do
33
+ interface.delete_field(:some_collection, :field_1)
34
+
35
+ interface.find_all(:some_collection).each do |row|
36
+ row.has_key?(:field_1).should be_false
37
+ end
38
+ end
39
+
40
+ it 'can delete a collection' do
41
+ interface.delete_collection(:some_collection)
42
+
43
+ interface.find_all(:some_collection).should == []
44
+ end
45
+
46
+ it 'can delete records that match a given set of fields' do
47
+ params = { primary_key =>1, field_1: 'value 1' }
48
+
49
+ interface.delete_by_params(:some_collection, params)
50
+
51
+ interface.find_all(:some_collection).should == [data2, data3]
52
+ end
53
+
54
+ it 'can write and read data to and from a collection' do
55
+ data4 = {primary_key =>3, field_1: 'value 3', field_2: 9, shared_between_1_and_2: 'not the same as 1 and 2', :some_array => [1, 7]}
56
+
57
+ interface.add(:some_collection, data4)
58
+ interface.find_all(:some_collection).should == [data1, data2, data3, data4]
59
+ end
60
+
61
+ it 'can replace a record' do
62
+ data2[:field_1] = 'value modified'
63
+ interface.replace(:some_collection, data2)
64
+
65
+ interface.find(:some_collection, primary_key, 2)[:field_1].should == 'value modified'
66
+ end
67
+
68
+ it 'can update a field with a value on a specific record' do
69
+ interface.update_field_with_value(:some_collection, 3, :field_2, '10')
70
+
71
+ interface.find(:some_collection, primary_key, 3)[:field_2].should == '10'
72
+ end
73
+
74
+ it 'can increment a field with a given amount for a specific field' do
75
+ interface.increment_field_by_amount(:some_collection, 1, :field_2, 3)
76
+
77
+ interface.find(:some_collection, primary_key, 1)[:field_2].should == 6
78
+ end
79
+
80
+ it 'can get one document' do
81
+ interface.find(:some_collection, :field_1, 'value 1').should == data1
82
+ interface.find(:some_collection, :field_2, 6).should == data2
83
+ end
84
+
85
+ it 'can clear the data store' do
86
+ interface.clear
87
+
88
+ interface.find_all(:some_collection).should == []
89
+ end
90
+
91
+ it 'can get all records of a specific key value' do
92
+ interface.get_all_for_key_with_value(:some_collection, :shared_between_1_and_2, 'awesome_value').should == [data1, data2]
93
+ end
94
+
95
+ it 'can get all records where a value includes any of a set of values' do
96
+ interface.containing_any(:some_collection, :some_array, []).should == []
97
+ interface.containing_any(:some_collection, :some_array, [7, 2, 3]).should == [data1, data3]
98
+ interface.containing_any(:some_collection, primary_key, [1, 2, 5]).should == [data1, data2]
99
+ end
100
+
101
+ it 'can get all records where the array includes a value' do
102
+ interface.array_contains(:some_collection, :some_array, 1).should == [data1, data3]
103
+ interface.array_contains(:some_collection, :some_array_2, 1).should == []
104
+ end
105
+
106
+ it 'can push a value to an array for a specific record' do
107
+ interface.push_to_array(:some_collection, primary_key, 1, :field_3, 'add to existing array')
108
+ interface.push_to_array(:some_collection, primary_key, 1, :new_field, 'add to new array')
109
+
110
+ interface.find(:some_collection, primary_key, 1)[:field_3].should include('add to existing array')
111
+ interface.find(:some_collection, primary_key, 1)[:new_field].should == ['add to new array']
112
+ end
113
+
114
+ it 'can remove a value from an array for a specific record' do
115
+ interface.remove_from_array(:some_collection, primary_key, 1, :field_3, 2)
116
+
117
+ interface.find(:some_collection, primary_key, 1)[:field_3].should_not include(2)
118
+ end
119
+
120
+ it 'can get all records that match a given set of keys and values' do
121
+ records = interface.get_by_params(:some_collection, field_1: 'value 1', shared_between_1_and_2: 'awesome_value')
122
+ records.size.should be(1)
123
+ records.first[primary_key].should == 1
124
+ interface.find_all(:some_collection).size.should == 3
125
+ end
126
+
127
+ it 'can get a record for a specific key and value' do
128
+ interface.get_for_key_with_value(:some_collection, :field_1, 'value 1').should == data1
129
+ end
130
+ end
131
+ end
132
+
data/lib/mince/version.rb CHANGED
@@ -1,3 +1,19 @@
1
1
  module Mince
2
- VERSION = '1.2.1'
2
+ module Version
3
+ def self.major
4
+ 2
5
+ end
6
+
7
+ def self.minor
8
+ 0
9
+ end
10
+
11
+ def self.patch
12
+ '0.pre'
13
+ end
14
+ end
15
+
16
+ def self.version
17
+ [Version.major, Version.minor, Version.patch].join('.')
18
+ end
3
19
  end
data/lib/mince.rb CHANGED
@@ -1 +1,2 @@
1
- require 'mince/data_store'
1
+ require_relative 'mince/version'
2
+ require_relative 'mince/config'
@@ -0,0 +1,10 @@
1
+ require_relative '../../../lib/mince/config'
2
+
3
+ describe Mince::Config do
4
+ it 'can be assigned an mince interface' do
5
+ interface = mock
6
+ described_class.interface = interface
7
+
8
+ described_class.interface.should == interface
9
+ end
10
+ end
@@ -0,0 +1,11 @@
1
+ require 'hashy_db'
2
+
3
+ require_relative '../../../lib/mince/shared_examples/interface_example'
4
+
5
+ describe 'The shared example for a mince interface' do
6
+ before do
7
+ Mince::Config.interface = Mince::HashyDb::Interface
8
+ end
9
+
10
+ it_behaves_like 'a mince interface'
11
+ end
metadata CHANGED
@@ -1,123 +1,142 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mince
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
5
- prerelease:
4
+ version: 2.0.0.pre
5
+ prerelease: 6
6
6
  platform: ruby
7
7
  authors:
8
8
  - Matt Simpson
9
- - Jason Mayer
10
- - Asynchrony Solutions
9
+ - Asynchrony
11
10
  autorequire:
12
11
  bindir: bin
13
12
  cert_chain: []
14
- date: 2012-09-17 00:00:00.000000000 Z
13
+ date: 2012-10-02 00:00:00.000000000 Z
15
14
  dependencies:
16
15
  - !ruby/object:Gem::Dependency
17
- name: activesupport
16
+ name: rake
18
17
  requirement: !ruby/object:Gem::Requirement
19
18
  none: false
20
19
  requirements:
21
20
  - - ~>
22
21
  - !ruby/object:Gem::Version
23
- version: '3.0'
24
- type: :runtime
22
+ version: '0.9'
23
+ type: :development
25
24
  prerelease: false
26
25
  version_requirements: !ruby/object:Gem::Requirement
27
26
  none: false
28
27
  requirements:
29
28
  - - ~>
30
29
  - !ruby/object:Gem::Version
31
- version: '3.0'
30
+ version: '0.9'
32
31
  - !ruby/object:Gem::Dependency
33
- name: mongo
32
+ name: rspec
34
33
  requirement: !ruby/object:Gem::Requirement
35
34
  none: false
36
35
  requirements:
37
36
  - - ~>
38
37
  - !ruby/object:Gem::Version
39
- version: 1.5.2
40
- type: :runtime
38
+ version: '2.0'
39
+ type: :development
41
40
  prerelease: false
42
41
  version_requirements: !ruby/object:Gem::Requirement
43
42
  none: false
44
43
  requirements:
45
44
  - - ~>
46
45
  - !ruby/object:Gem::Version
47
- version: 1.5.2
46
+ version: '2.0'
48
47
  - !ruby/object:Gem::Dependency
49
- name: bson_ext
48
+ name: guard-rspec
50
49
  requirement: !ruby/object:Gem::Requirement
51
50
  none: false
52
51
  requirements:
53
52
  - - ~>
54
53
  - !ruby/object:Gem::Version
55
- version: 1.5.2
56
- type: :runtime
54
+ version: '0.6'
55
+ type: :development
57
56
  prerelease: false
58
57
  version_requirements: !ruby/object:Gem::Requirement
59
58
  none: false
60
59
  requirements:
61
60
  - - ~>
62
61
  - !ruby/object:Gem::Version
63
- version: 1.5.2
62
+ version: '0.6'
64
63
  - !ruby/object:Gem::Dependency
65
- name: rake
64
+ name: yard
66
65
  requirement: !ruby/object:Gem::Requirement
67
66
  none: false
68
67
  requirements:
69
- - - ! '>='
68
+ - - ~>
70
69
  - !ruby/object:Gem::Version
71
- version: '0'
70
+ version: '0.7'
72
71
  type: :development
73
72
  prerelease: false
74
73
  version_requirements: !ruby/object:Gem::Requirement
75
74
  none: false
76
75
  requirements:
77
- - - ! '>='
76
+ - - ~>
78
77
  - !ruby/object:Gem::Version
79
- version: '0'
78
+ version: '0.7'
80
79
  - !ruby/object:Gem::Dependency
81
- name: rspec
80
+ name: redcarpet
82
81
  requirement: !ruby/object:Gem::Requirement
83
82
  none: false
84
83
  requirements:
85
- - - ! '>='
84
+ - - ~>
86
85
  - !ruby/object:Gem::Version
87
- version: '0'
86
+ version: '2.1'
88
87
  type: :development
89
88
  prerelease: false
90
89
  version_requirements: !ruby/object:Gem::Requirement
91
90
  none: false
92
91
  requirements:
93
- - - ! '>='
92
+ - - ~>
93
+ - !ruby/object:Gem::Version
94
+ version: '2.1'
95
+ - !ruby/object:Gem::Dependency
96
+ name: debugger
97
+ requirement: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ~>
94
101
  - !ruby/object:Gem::Version
95
- version: '0'
96
- description: Lightweight MongoDB ORM for Ruby.
102
+ version: '1.2'
103
+ type: :development
104
+ prerelease: false
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ~>
109
+ - !ruby/object:Gem::Version
110
+ version: '1.2'
111
+ - !ruby/object:Gem::Dependency
112
+ name: hashy_db
113
+ requirement: !ruby/object:Gem::Requirement
114
+ none: false
115
+ requirements:
116
+ - - '='
117
+ - !ruby/object:Gem::Version
118
+ version: 2.0.0.pre
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ none: false
123
+ requirements:
124
+ - - '='
125
+ - !ruby/object:Gem::Version
126
+ version: 2.0.0.pre
127
+ description: Library to interact with mince interfacing data libraries
97
128
  email:
98
129
  - matt@railsgrammer.com
99
- - jason.mayer@gmail.com
100
130
  executables: []
101
131
  extensions: []
102
132
  extra_rdoc_files: []
103
133
  files:
104
- - .gitignore
105
- - .rspec
106
- - .rvmrc
107
- - Gemfile
108
- - Gemfile.lock
109
- - LICENSE
110
- - README.md
111
- - Rakefile
112
134
  - lib/mince.rb
113
- - lib/mince/config.rb
114
- - lib/mince/connection.rb
115
- - lib/mince/data_store.rb
116
135
  - lib/mince/version.rb
117
- - mince.gemspec
118
- - spec/lib/config_spec.rb
119
- - spec/lib/connection_spec.rb
120
- - spec/lib/data_store_spec.rb
136
+ - lib/mince/config.rb
137
+ - lib/mince/shared_examples/interface_example.rb
138
+ - spec/units/mince/config_spec.rb
139
+ - spec/units/mince/interface_example_spec.rb
121
140
  homepage: https://github.com/asynchrony/mince
122
141
  licenses: []
123
142
  post_install_message:
@@ -133,16 +152,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
133
152
  required_rubygems_version: !ruby/object:Gem::Requirement
134
153
  none: false
135
154
  requirements:
136
- - - ! '>='
155
+ - - ! '>'
137
156
  - !ruby/object:Gem::Version
138
- version: '0'
157
+ version: 1.3.1
139
158
  requirements: []
140
159
  rubyforge_project: mince
141
- rubygems_version: 1.8.21
160
+ rubygems_version: 1.8.24
142
161
  signing_key:
143
162
  specification_version: 3
144
- summary: Lightweight MongoDB ORM for Ruby.
163
+ summary: Library to interact with mince interfacing data libraries
145
164
  test_files:
146
- - spec/lib/config_spec.rb
147
- - spec/lib/connection_spec.rb
148
- - spec/lib/data_store_spec.rb
165
+ - spec/units/mince/config_spec.rb
166
+ - spec/units/mince/interface_example_spec.rb
167
+ has_rdoc:
data/.gitignore DELETED
@@ -1,5 +0,0 @@
1
- *.gem
2
- .idea
3
- .bundle
4
- Gemfile.lock
5
- pkg/*
data/.rspec DELETED
@@ -1 +0,0 @@
1
- --colour
data/.rvmrc DELETED
@@ -1 +0,0 @@
1
- rvm use 1.9.3
data/Gemfile DELETED
@@ -1,3 +0,0 @@
1
- source :rubygems
2
-
3
- gemspec
data/Gemfile.lock DELETED
@@ -1,39 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- mince (1.1.0)
5
- activesupport (~> 3.0)
6
- bson_ext (~> 1.5.2)
7
- mongo (~> 1.5.2)
8
-
9
- GEM
10
- remote: http://rubygems.org/
11
- specs:
12
- activesupport (3.2.8)
13
- i18n (~> 0.6)
14
- multi_json (~> 1.0)
15
- bson (1.5.2)
16
- bson_ext (1.5.2)
17
- bson (= 1.5.2)
18
- diff-lcs (1.1.3)
19
- i18n (0.6.1)
20
- mongo (1.5.2)
21
- bson (= 1.5.2)
22
- multi_json (1.3.6)
23
- rake (0.8.7)
24
- rspec (2.8.0.rc1)
25
- rspec-core (= 2.8.0.rc1)
26
- rspec-expectations (= 2.8.0.rc1)
27
- rspec-mocks (= 2.8.0.rc1)
28
- rspec-core (2.8.0.rc1)
29
- rspec-expectations (2.8.0.rc1)
30
- diff-lcs (~> 1.1.2)
31
- rspec-mocks (2.8.0.rc1)
32
-
33
- PLATFORMS
34
- ruby
35
-
36
- DEPENDENCIES
37
- mince!
38
- rake
39
- rspec
data/LICENSE DELETED
@@ -1,201 +0,0 @@
1
- Apache License
2
- Version 2.0, January 2004
3
- http://www.apache.org/licenses/
4
-
5
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
-
7
- 1. Definitions.
8
-
9
- "License" shall mean the terms and conditions for use, reproduction,
10
- and distribution as defined by Sections 1 through 9 of this document.
11
-
12
- "Licensor" shall mean the copyright owner or entity authorized by
13
- the copyright owner that is granting the License.
14
-
15
- "Legal Entity" shall mean the union of the acting entity and all
16
- other entities that control, are controlled by, or are under common
17
- control with that entity. For the purposes of this definition,
18
- "control" means (i) the power, direct or indirect, to cause the
19
- direction or management of such entity, whether by contract or
20
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
- outstanding shares, or (iii) beneficial ownership of such entity.
22
-
23
- "You" (or "Your") shall mean an individual or Legal Entity
24
- exercising permissions granted by this License.
25
-
26
- "Source" form shall mean the preferred form for making modifications,
27
- including but not limited to software source code, documentation
28
- source, and configuration files.
29
-
30
- "Object" form shall mean any form resulting from mechanical
31
- transformation or translation of a Source form, including but
32
- not limited to compiled object code, generated documentation,
33
- and conversions to other media types.
34
-
35
- "Work" shall mean the work of authorship, whether in Source or
36
- Object form, made available under the License, as indicated by a
37
- copyright notice that is included in or attached to the work
38
- (an example is provided in the Appendix below).
39
-
40
- "Derivative Works" shall mean any work, whether in Source or Object
41
- form, that is based on (or derived from) the Work and for which the
42
- editorial revisions, annotations, elaborations, or other modifications
43
- represent, as a whole, an original work of authorship. For the purposes
44
- of this License, Derivative Works shall not include works that remain
45
- separable from, or merely link (or bind by name) to the interfaces of,
46
- the Work and Derivative Works thereof.
47
-
48
- "Contribution" shall mean any work of authorship, including
49
- the original version of the Work and any modifications or additions
50
- to that Work or Derivative Works thereof, that is intentionally
51
- submitted to Licensor for inclusion in the Work by the copyright owner
52
- or by an individual or Legal Entity authorized to submit on behalf of
53
- the copyright owner. For the purposes of this definition, "submitted"
54
- means any form of electronic, verbal, or written communication sent
55
- to the Licensor or its representatives, including but not limited to
56
- communication on electronic mailing lists, source code control systems,
57
- and issue tracking systems that are managed by, or on behalf of, the
58
- Licensor for the purpose of discussing and improving the Work, but
59
- excluding communication that is conspicuously marked or otherwise
60
- designated in writing by the copyright owner as "Not a Contribution."
61
-
62
- "Contributor" shall mean Licensor and any individual or Legal Entity
63
- on behalf of whom a Contribution has been received by Licensor and
64
- subsequently incorporated within the Work.
65
-
66
- 2. Grant of Copyright License. Subject to the terms and conditions of
67
- this License, each Contributor hereby grants to You a perpetual,
68
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
- copyright license to reproduce, prepare Derivative Works of,
70
- publicly display, publicly perform, sublicense, and distribute the
71
- Work and such Derivative Works in Source or Object form.
72
-
73
- 3. Grant of Patent License. Subject to the terms and conditions of
74
- this License, each Contributor hereby grants to You a perpetual,
75
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
- (except as stated in this section) patent license to make, have made,
77
- use, offer to sell, sell, import, and otherwise transfer the Work,
78
- where such license applies only to those patent claims licensable
79
- by such Contributor that are necessarily infringed by their
80
- Contribution(s) alone or by combination of their Contribution(s)
81
- with the Work to which such Contribution(s) was submitted. If You
82
- institute patent litigation against any entity (including a
83
- cross-claim or counterclaim in a lawsuit) alleging that the Work
84
- or a Contribution incorporated within the Work constitutes direct
85
- or contributory patent infringement, then any patent licenses
86
- granted to You under this License for that Work shall terminate
87
- as of the date such litigation is filed.
88
-
89
- 4. Redistribution. You may reproduce and distribute copies of the
90
- Work or Derivative Works thereof in any medium, with or without
91
- modifications, and in Source or Object form, provided that You
92
- meet the following conditions:
93
-
94
- (a) You must give any other recipients of the Work or
95
- Derivative Works a copy of this License; and
96
-
97
- (b) You must cause any modified files to carry prominent notices
98
- stating that You changed the files; and
99
-
100
- (c) You must retain, in the Source form of any Derivative Works
101
- that You distribute, all copyright, patent, trademark, and
102
- attribution notices from the Source form of the Work,
103
- excluding those notices that do not pertain to any part of
104
- the Derivative Works; and
105
-
106
- (d) If the Work includes a "NOTICE" text file as part of its
107
- distribution, then any Derivative Works that You distribute must
108
- include a readable copy of the attribution notices contained
109
- within such NOTICE file, excluding those notices that do not
110
- pertain to any part of the Derivative Works, in at least one
111
- of the following places: within a NOTICE text file distributed
112
- as part of the Derivative Works; within the Source form or
113
- documentation, if provided along with the Derivative Works; or,
114
- within a display generated by the Derivative Works, if and
115
- wherever such third-party notices normally appear. The contents
116
- of the NOTICE file are for informational purposes only and
117
- do not modify the License. You may add Your own attribution
118
- notices within Derivative Works that You distribute, alongside
119
- or as an addendum to the NOTICE text from the Work, provided
120
- that such additional attribution notices cannot be construed
121
- as modifying the License.
122
-
123
- You may add Your own copyright statement to Your modifications and
124
- may provide additional or different license terms and conditions
125
- for use, reproduction, or distribution of Your modifications, or
126
- for any such Derivative Works as a whole, provided Your use,
127
- reproduction, and distribution of the Work otherwise complies with
128
- the conditions stated in this License.
129
-
130
- 5. Submission of Contributions. Unless You explicitly state otherwise,
131
- any Contribution intentionally submitted for inclusion in the Work
132
- by You to the Licensor shall be under the terms and conditions of
133
- this License, without any additional terms or conditions.
134
- Notwithstanding the above, nothing herein shall supersede or modify
135
- the terms of any separate license agreement you may have executed
136
- with Licensor regarding such Contributions.
137
-
138
- 6. Trademarks. This License does not grant permission to use the trade
139
- names, trademarks, service marks, or product names of the Licensor,
140
- except as required for reasonable and customary use in describing the
141
- origin of the Work and reproducing the content of the NOTICE file.
142
-
143
- 7. Disclaimer of Warranty. Unless required by applicable law or
144
- agreed to in writing, Licensor provides the Work (and each
145
- Contributor provides its Contributions) on an "AS IS" BASIS,
146
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
- implied, including, without limitation, any warranties or conditions
148
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
- PARTICULAR PURPOSE. You are solely responsible for determining the
150
- appropriateness of using or redistributing the Work and assume any
151
- risks associated with Your exercise of permissions under this License.
152
-
153
- 8. Limitation of Liability. In no event and under no legal theory,
154
- whether in tort (including negligence), contract, or otherwise,
155
- unless required by applicable law (such as deliberate and grossly
156
- negligent acts) or agreed to in writing, shall any Contributor be
157
- liable to You for damages, including any direct, indirect, special,
158
- incidental, or consequential damages of any character arising as a
159
- result of this License or out of the use or inability to use the
160
- Work (including but not limited to damages for loss of goodwill,
161
- work stoppage, computer failure or malfunction, or any and all
162
- other commercial damages or losses), even if such Contributor
163
- has been advised of the possibility of such damages.
164
-
165
- 9. Accepting Warranty or Additional Liability. While redistributing
166
- the Work or Derivative Works thereof, You may choose to offer,
167
- and charge a fee for, acceptance of support, warranty, indemnity,
168
- or other liability obligations and/or rights consistent with this
169
- License. However, in accepting such obligations, You may act only
170
- on Your own behalf and on Your sole responsibility, not on behalf
171
- of any other Contributor, and only if You agree to indemnify,
172
- defend, and hold each Contributor harmless for any liability
173
- incurred by, or claims asserted against, such Contributor by reason
174
- of your accepting any such warranty or additional liability.
175
-
176
- END OF TERMS AND CONDITIONS
177
-
178
- APPENDIX: How to apply the Apache License to your work.
179
-
180
- To apply the Apache License to your work, attach the following
181
- boilerplate notice, with the fields enclosed by brackets "[]"
182
- replaced with your own identifying information. (Don't include
183
- the brackets!) The text should be enclosed in the appropriate
184
- comment syntax for the file format. We also recommend that a
185
- file or class name and description of purpose be included on the
186
- same "printed page" as the copyright notice for easier
187
- identification within third-party archives.
188
-
189
- Copyright [yyyy] [name of copyright owner]
190
-
191
- Licensed under the Apache License, Version 2.0 (the "License");
192
- you may not use this file except in compliance with the License.
193
- You may obtain a copy of the License at
194
-
195
- http://www.apache.org/licenses/LICENSE-2.0
196
-
197
- Unless required by applicable law or agreed to in writing, software
198
- distributed under the License is distributed on an "AS IS" BASIS,
199
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
- See the License for the specific language governing permissions and
201
- limitations under the License.
data/README.md DELETED
@@ -1,77 +0,0 @@
1
- # What is mince?
2
-
3
- Light weight ORM to persist data to a hash.
4
-
5
- Provides a very light weight interface for storing and retreiving information to MongoDB.
6
-
7
- The motivation behind this is so your application is not tightly tied to a specific database. As your application grows you may need to upgrade to a different database or pull specific models to a different persistence strategy.
8
-
9
- [@github](https://github.com/asynchrony/mince)
10
- [@rubygems](https://rubygems.org/gems/mince)
11
-
12
- # How to use
13
-
14
- view the [example mince rails app](https://github.com/coffeencoke/mince_rails_example) to see how to use this.
15
-
16
- Start MongoDB at localhost (currently does not support authentication against MongoDB).
17
-
18
- From there you can use Mince to add and retrieve data.
19
-
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
-
27
- # Add a book to the books collection
28
- Mince::DataStore.add 'books', title: 'The World In Photographs', publisher: 'National Geographic'
29
-
30
- # Retrieve all records from the books collection
31
- Mince::DataStore.find_all 'books'
32
-
33
- # Replace a specific book
34
- Mince::DataStore.replace 'books', id: 1, title: 'A World In Photographs', publisher: 'National Geographic'
35
- </pre>
36
-
37
- View the [data_store.rb](https://github.com/asynchrony/mince/blob/master/lib/mince/data_store.rb) file for all methods available.
38
-
39
- Use with [mince data model](https://github.com/asynchrony/mince_data_model) to make it easy to change from one data storage to another, like [Hashy Db](https://github.com/asynchrony/hashy_db), a Hash data persistence implementation.
40
-
41
- # Why would you want this?
42
-
43
- - To defer choosing your database until you know most about your application.
44
- - Provides assitance in designing a database agnostic architecture.
45
- - When used along with [Hashy Db](https://github.com/asynchrony/hashy_db) it offers very little technical dependencies. Use Hashy Db in development mode so that you can clone the repo and develop, and run tests, cucumbers without databases, migrations, etc. Then in production mode, switch to Mince.
46
-
47
- If you are able to switch between Hashy Db and Mince, your application will be more open to new and improved database in the future, or as your application evolves you aren't tied to a database.
48
-
49
-
50
- # Todo
51
-
52
- - Load configuration from a yaml file
53
- - Add rdoc comments
54
-
55
- # Contribute
56
-
57
- - fork into a topic branch, write specs, make a pull request.
58
-
59
- # Owners
60
-
61
- Matt Simpson - [@railsgrammer](https://twitter.com/railsgrammer)
62
-
63
- Jason Mayer - [@farkerhaiku](https://twitter.com/farkerhaiku)
64
-
65
- # Contributors
66
-
67
- Amos King - [@adkron](https://twitter.com/adkron)
68
-
69
- - Your name here!
70
-
71
- ![Mince Some App](https://github.com/coffeencoke/gist-files/raw/master/images/mince%20garlic.png)
72
-
73
- -------
74
-
75
- Copyright (c) 2012 Asynchrony
76
-
77
- Distributes under the Apache License, see LICENSE in the source distro
data/Rakefile DELETED
@@ -1 +0,0 @@
1
- require "bundler/gem_tasks"
@@ -1,16 +0,0 @@
1
- require 'mongo'
2
- require 'singleton'
3
- require_relative 'config'
4
-
5
- module Mince
6
- class Connection
7
- include Singleton
8
-
9
- attr_reader :connection, :db
10
-
11
- def initialize
12
- @connection = Mongo::Connection.new
13
- @db = connection.db(Mince::Config.database_name)
14
- end
15
- end
16
- end
@@ -1,102 +0,0 @@
1
- # SRP: Model with implementation on how to store each collection in a data store
2
- require 'singleton'
3
-
4
- require_relative 'connection'
5
-
6
- module Mince
7
- class DataStore
8
- include Singleton
9
-
10
- def self.primary_key_identifier
11
- '_id'
12
- end
13
-
14
- def self.generate_unique_id(*args)
15
- BSON::ObjectId.new.to_s
16
- end
17
-
18
- def delete_field(collection_name, key)
19
- collection(collection_name).update({}, {"$unset" => { key => 1 } }, multi: true)
20
- end
21
-
22
- def delete_by_params(collection_name, params)
23
- collection(collection_name).remove(params)
24
- end
25
-
26
- def add(collection_name, hash)
27
- collection(collection_name).insert(hash)
28
- end
29
-
30
- def replace(collection_name, hash)
31
- collection(collection_name).update({"_id" => hash[:_id]}, hash)
32
- end
33
-
34
- def update_field_with_value(collection_name, primary_key_value, field_name, new_value)
35
- collection(collection_name).update({"_id" => primary_key_value}, {'$set' => { field_name => new_value } })
36
- end
37
-
38
- def increment_field_by_amount(collection_name, primary_key_value, field_name, amount)
39
- collection(collection_name).update({"_id" => primary_key_value}, {'$inc' => { field_name => amount } })
40
- end
41
-
42
- def get_all_for_key_with_value(collection_name, key, value)
43
- get_by_params(collection_name, key.to_s => value)
44
- end
45
-
46
- def get_for_key_with_value(collection_name, key, value)
47
- get_all_for_key_with_value(collection_name, key, value).first
48
- end
49
-
50
- def get_by_params(collection_name, hash)
51
- collection(collection_name).find(hash)
52
- end
53
-
54
- def find_all(collection_name)
55
- collection(collection_name).find
56
- end
57
-
58
- def find(collection_name, key, value)
59
- collection(collection_name).find_one({key.to_s => value})
60
- end
61
-
62
- def push_to_array(collection_name, identifying_key, identifying_value, array_key, value_to_push)
63
- collection(collection_name).update({identifying_key.to_s => identifying_value}, {'$push' => {array_key.to_s => value_to_push}})
64
- end
65
-
66
- def remove_from_array(collection_name, identifying_key, identifying_value, array_key, value_to_remove)
67
- collection(collection_name).update({identifying_key.to_s => identifying_value}, {'$pull' => {array_key.to_s => value_to_remove}})
68
- end
69
-
70
- def containing_any(collection_name, key, values)
71
- collection(collection_name).find({key.to_s => {"$in" => values}})
72
- end
73
-
74
- def array_contains(collection_name, key, value)
75
- collection(collection_name).find(key.to_s => value)
76
- end
77
-
78
- def clear
79
- db.collection_names.each do |collection_name|
80
- db.drop_collection collection_name unless collection_name.include?('system')
81
- end
82
- end
83
-
84
- def delete_collection(collection_name)
85
- collection(collection_name).drop
86
- end
87
-
88
- def collection(collection_name)
89
- db.collection(collection_name)
90
- end
91
-
92
- def insert(collection_name, data)
93
- data.each do |datum|
94
- add collection_name, datum
95
- end
96
- end
97
-
98
- def db
99
- Mince::Connection.instance.db
100
- end
101
- end
102
- end
data/mince.gemspec DELETED
@@ -1,27 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
3
- require 'mince/version'
4
-
5
- Gem::Specification.new do |s|
6
- s.name = "mince"
7
- s.version = Mince::VERSION
8
- s.authors = ["Matt Simpson", "Jason Mayer", "Asynchrony Solutions"]
9
- s.email = ["matt@railsgrammer.com", "jason.mayer@gmail.com"]
10
- s.homepage = "https://github.com/asynchrony/mince"
11
- s.summary = %q{Lightweight MongoDB ORM for Ruby.}
12
- s.description = %q{Lightweight MongoDB ORM for Ruby.}
13
-
14
- s.rubyforge_project = "mince"
15
-
16
- s.files = `git ls-files`.split("\n")
17
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
- s.require_paths = ["lib"]
20
-
21
- s.add_dependency('activesupport', '~> 3.0')
22
- s.add_dependency('mongo', '~> 1.5.2')
23
- s.add_dependency('bson_ext', '~> 1.5.2')
24
-
25
- s.add_development_dependency('rake')
26
- s.add_development_dependency('rspec')
27
- end
@@ -1,32 +0,0 @@
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
@@ -1,20 +0,0 @@
1
- require_relative '../../lib/mince/connection'
2
-
3
- describe Mince::Connection do
4
- subject { described_class.instance }
5
-
6
- let(:mongo_connection) { mock 'a mongo connection object', :db => db }
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
13
-
14
- it 'is a mongo connection' do
15
- Mongo::Connection.should_receive(:new).and_return(mongo_connection)
16
- mongo_connection.should_receive(:db).with(config_database_name).and_return(db)
17
-
18
- subject.connection.should == mongo_connection
19
- end
20
- end
@@ -1,149 +0,0 @@
1
- require_relative '../../lib/mince/data_store'
2
-
3
- describe Mince::DataStore do
4
- subject { described_class.instance }
5
-
6
- let(:db) { mock 'mongo database' }
7
- let(:connection) { mock 'mongo connection', db: db }
8
- let(:mongo_data_store_connection) { mock 'mongo_data_store_connection', :db => db}
9
- let(:collection) { mock 'some collection'}
10
- let(:collection_name) { 'some_collection_name'}
11
- let(:primary_key) { mock 'primary key'}
12
- let(:mock_id) { mock 'id' }
13
- let(:data) { { :_id => mock_id}}
14
- let(:return_data) { mock 'return data' }
15
-
16
- before do
17
- Mince::Connection.stub(:instance => mongo_data_store_connection)
18
- db.stub(:collection).with(collection_name).and_return(collection)
19
- end
20
-
21
- it 'uses the correct collection' do
22
- db.stub(collection: collection)
23
- subject.collection('collection name').should == collection
24
- end
25
-
26
- it 'has a primary key identifier' do
27
- described_class.primary_key_identifier.should == '_id'
28
- end
29
-
30
- it 'can delete a field' do
31
- field = mock 'field to delete'
32
- collection.should_receive(:update).with({}, {'$unset' => { field => 1 } }, multi: true)
33
-
34
- subject.delete_field(collection_name, field)
35
- end
36
-
37
- it 'can delete all records the match a given set of params' do
38
- params = mock 'params to condition the deleted records to'
39
- collection.should_receive(:remove).with(params)
40
-
41
- subject.delete_by_params(collection_name, params)
42
- end
43
-
44
- it 'can delete a collection' do
45
- collection.should_receive(:drop)
46
-
47
- subject.delete_collection(collection_name)
48
- end
49
-
50
- describe "Generating a primary key" do
51
- let(:unique_id) { mock 'id' }
52
- it 'should create a reasonably unique id' do
53
- BSON::ObjectId.should_receive(:new).and_return(unique_id)
54
-
55
- described_class.generate_unique_id('something').should == unique_id.to_s
56
- end
57
- end
58
-
59
- it 'can write to the collection' do
60
- collection.should_receive(:insert).with(data).and_return(return_data)
61
-
62
- subject.add(collection_name, data).should == return_data
63
- end
64
-
65
- it 'can update a field with a specific value' do
66
- key = mock 'key'
67
- value = mock 'value'
68
- id = mock 'id'
69
- collection.should_receive(:update).with({ '_id' => id }, { '$set' => { key => value } })
70
-
71
- subject.update_field_with_value collection_name, id, key, value
72
- end
73
-
74
- it 'can increment a field by a specific amount' do
75
- key = mock 'key'
76
- amount = mock 'amount to increment the field by'
77
- id = mock 'id'
78
- collection.should_receive(:update).with({ '_id' => id }, { '$inc' => { key => amount } })
79
-
80
- subject.increment_field_by_amount collection_name, id, key, amount
81
- end
82
-
83
- it 'can read from the collection' do
84
- collection.should_receive(:find).and_return(return_data)
85
-
86
- subject.find_all(collection_name).should == return_data
87
- end
88
-
89
- it 'can replace a record' do
90
- collection.should_receive(:update).with({"_id" => data[:_id]}, data)
91
-
92
- subject.replace(collection_name, data)
93
- end
94
-
95
- it 'can get one document' do
96
- field = "stuff"
97
- value = "more stuff"
98
-
99
- collection.should_receive(:find_one).with(field => value).and_return(return_data)
100
-
101
- subject.find(collection_name, field, value).should == return_data
102
- end
103
-
104
- it 'can clear the data store' do
105
- collection_names = %w(collection_1 collection_2 system_profiles)
106
- db.stub(:collection_names => collection_names)
107
-
108
- db.should_receive(:drop_collection).with('collection_1')
109
- db.should_receive(:drop_collection).with('collection_2')
110
-
111
- subject.clear
112
- end
113
-
114
- it 'can get all records of a specific key value' do
115
- collection.should_receive(:find).with({"key" => "value"}).and_return(return_data)
116
-
117
- subject.get_all_for_key_with_value(collection_name, "key", "value").should == return_data
118
- end
119
-
120
- it 'can get a record of a specific key value' do
121
- collection.should_receive(:find).with({"key" => "value"}).and_return([return_data])
122
-
123
- subject.get_for_key_with_value(collection_name, "key", "value").should == return_data
124
- end
125
-
126
- it 'can get all records where a value includes any of a set of values' do
127
- collection.should_receive(:find).with({"key1" => { "$in" => [1,2,4]} }).and_return(return_data)
128
-
129
- subject.containing_any(collection_name, "key1", [1,2,4]).should == return_data
130
- end
131
-
132
- it 'can get all records where the array includes a value' do
133
- collection.should_receive(:find).with({"key" => "value"}).and_return(return_data)
134
-
135
- subject.array_contains(collection_name, "key", "value").should == return_data
136
- end
137
-
138
- it 'can push a value to an array for a specific record' do
139
- collection.should_receive(:update).with({"key" => "value"}, { '$push' => { "array_key" => "value_to_push"}}).and_return(return_data)
140
-
141
- subject.push_to_array(collection_name, :key, "value", :array_key, "value_to_push").should == return_data
142
- end
143
-
144
- it 'can remove a value from an array for a specific record' do
145
- collection.should_receive(:update).with({"key" => "value"}, { '$pull' => { "array_key" => "value_to_remove"}}).and_return(return_data)
146
-
147
- subject.remove_from_array(collection_name, :key, "value", :array_key, "value_to_remove").should == return_data
148
- end
149
- end