mince_data_model 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,27 +1,44 @@
1
- # What is this?
2
1
 
3
- Provides a very lightweight interface to store and retrieve data in MongoDB in Ruby.
2
+ # What Iz Mince Data Model?
4
3
 
5
- # Why would you want this?
4
+ Some niceties and defines an implementation to swap out different data persistance strategies. Currently there are 2 supported data persistance strategies: Mince (MongoDB), and HashyDB (in memory hash). If using this gem, all you need to do in order to change the data persistence strategy is to implement the methods outlined by this gem. Check out the [Mince Data Store](https://github.com/asynchrony/mince/blob/master/lib/mince/data_store.rb) and the [HashyDB Data Store](https://github.com/asynchrony/HashyDB/blob/master/lib/hashy_db/data_store.rb) for a list of methods to implement.
6
5
 
7
- - To build a non-active-record implementation application using MongoDB.
8
- - Allows interchanging data persistence with HashyDb
6
+ # Why?
9
7
 
10
- # Todos
8
+ A little background perhaps...
11
9
 
12
- - Remove rails dependency
13
- - Add a better readme
10
+ After developing quite a few Rails apps, we started feeling a lot of pain with our models. I'm sure most of us know this pain. We end up having *at least one* **massive** model which ends up being the brain model of the application. Generally this model is the User model, or the Project model. Whichever class your application primarily focusses on.
14
11
 
15
- # Contribute
12
+ After some time of trying new things and talking to others, reading from others, and evolving our applications, the source of the problem seemed to be the Active Record architecture pattern. Where logic and data are presented as a unified package. The problem with that is that there is a **ton** of logic that can be associated to a very *little* bit of data.
16
13
 
17
- - fork into a topic branch, write specs, make a pull request.
14
+ The idea behind the mince is to provide the lightest weight ORM possible so that you can build your application's business logic and data logic completely isolated from each other.
18
15
 
19
- # Owners
16
+ One great example is the user model. Every app on the face of the uniwebs has it and we can all relate to it. First, you need to register. Registration has validations. Once you've registered, you need to confirm your email before you can login. Once you login you want to change information about yourself. But since you've already created an account, there are different validations than when you were registering! The validations alone make the User model very complex. You end up with a lot of conditional logic in your user models. After you've implemented registration, your user model has already become over 100 lines long!
20
17
 
21
- Matt Simpson - [@railsgrammer](https://twitter.com/railsgrammer)
22
- <br />
23
- Jason Mayer - [@farkerhaiku](https://twitter.com/farkerhaiku)
18
+ What if you could have a separate model for **each** logical event? A registration model, a password updator model, a user account model? Your validations can become specific to one scenario. With this implementation, every class is less than 100 lines long. Now, number of lines is not our goal, but it is a great indicator to how much that class is doing.
24
19
 
25
- # Contributors
26
- - Your name here!
20
+ Form more info about the inspiration behind Mince Data Store:
27
21
 
22
+ - [Uncle Bob Martin's Ruby Midwest 2011 talk](http://confreaks.com/videos/759-rubymidwest2011-keynote-architecture-the-lost-years)
23
+ - [Avdi Grimm's Objects On Rails book](http://devblog.avdi.org/2011/11/15/early-access-beta-of-objects-on-rails-now-available-2/)
24
+ - [Working with guys at Asynchrony](http://asynchrony.com)
25
+
26
+ # Rails Implementation Example
27
+
28
+ [This mince rails example application](https://github.com/coffeencoke/mince_rails_example) is available to reveal A way to implement the use of the Mince Data Store, [Mince](https://github.com/asynchrony/mince), and [Hashy Db](https://github.com/asynchrony/hashy_db) gems.
29
+
30
+ # Mince
31
+
32
+ Mince is a lightweight MongoDB ORM for Ruby. It frees you from using a huge ORM that forces you into using a specific architecture.
33
+
34
+ [@github](https://github.com/asynchrony/mince)
35
+ [@rubygems](https://rubygems.org/gems/mince)
36
+
37
+ # Hashy Db
38
+
39
+ Provides an interface for storing and retreiving information in a Hash in memory.
40
+
41
+ The motivation behind this is so you can clone the repository down, have ruby installed, run bundle install and be able to run your tests and develop without being dependent on any other setup.
42
+
43
+ [@github](https://github.com/asynchrony/hashy_db)
44
+ [@rubygems](https://rubygems.org/gems/hashy_db)
@@ -1,3 +1,3 @@
1
1
  module MinceDataModel
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -67,7 +67,11 @@ module MinceDataModel
67
67
 
68
68
  def find_by_fields(hash)
69
69
  translate_from_data_store all_by_fields(hash).first
70
- end
70
+ end
71
+
72
+ def find_by_field(field, value)
73
+ translate_from_data_store data_store.instance.get_for_key_with_value(data_collection, field, value)
74
+ end
71
75
 
72
76
  def containing_any(field, values)
73
77
  translate_each_from_data_store data_store.instance.containing_any(data_collection, field, values)
@@ -95,12 +95,11 @@ shared_examples_for 'a data model' do
95
95
  let(:expected_data_models) { [{:id => 'some id', primary_key => 'some id'}] }
96
96
  let(:mock_data_models) { [mock_data_model] }
97
97
  let(:expected_data_models) { [HashWithIndifferentAccess.new(mock_data_model)] }
98
- let(:sample_hash) { {field1: nil, field2: 'not nil'} }
99
98
 
100
99
  it 'passes the hash to the mock_data_store_class' do
101
- mock_data_store.should_receive(:get_by_params).with(collection_name, sample_hash).and_return(mock_data_models)
100
+ mock_data_store.should_receive(:get_all_for_key_with_value).with(collection_name, :field2, 'not nil').and_return(mock_data_models)
102
101
 
103
- described_class.all_by_fields(sample_hash).should == expected_data_models
102
+ described_class.all_by_field(:field2, 'not nil').should == expected_data_models
104
103
  end
105
104
  end
106
105
 
@@ -131,6 +130,17 @@ shared_examples_for 'a data model' do
131
130
  end
132
131
  end
133
132
 
133
+ describe "getting a record by a key and value" do
134
+ let(:mock_data_model) { {primary_key => 'some id'} }
135
+ let(:expected_data_model) { {:id => 'some id', primary_key => 'some id'} }
136
+
137
+ it 'returns the correct data model' do
138
+ mock_data_store.should_receive(:get_for_key_with_value).with(collection_name, :field2, 'not nil').and_return(mock_data_model)
139
+
140
+ described_class.find_by_field(:field2, 'not nil').should == HashWithIndifferentAccess.new(expected_data_model)
141
+ end
142
+ end
143
+
134
144
  describe "getting all data models with a specific value for a field" do
135
145
  let(:mock_data_models) { [{primary_key => 'some id'}, {primary_key => 'some id 2'}] }
136
146
  let(:expected_data_models) { [HashWithIndifferentAccess.new({:id => 'some id', primary_key => 'some id'}), HashWithIndifferentAccess.new({id: 'some id 2', primary_key => 'some id 2'})] }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mince_data_model
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,11 +11,11 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2012-03-02 00:00:00.000000000 Z
14
+ date: 2012-03-03 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rspec
18
- requirement: &16308420 !ruby/object:Gem::Requirement
18
+ requirement: &70291511198100 !ruby/object:Gem::Requirement
19
19
  none: false
20
20
  requirements:
21
21
  - - ! '>='
@@ -23,10 +23,10 @@ dependencies:
23
23
  version: '0'
24
24
  type: :development
25
25
  prerelease: false
26
- version_requirements: *16308420
26
+ version_requirements: *70291511198100
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
- requirement: &16307660 !ruby/object:Gem::Requirement
29
+ requirement: &70291511197560 !ruby/object:Gem::Requirement
30
30
  none: false
31
31
  requirements:
32
32
  - - ! '>='
@@ -34,10 +34,10 @@ dependencies:
34
34
  version: '0'
35
35
  type: :development
36
36
  prerelease: false
37
- version_requirements: *16307660
37
+ version_requirements: *70291511197560
38
38
  - !ruby/object:Gem::Dependency
39
39
  name: rails
40
- requirement: &16305880 !ruby/object:Gem::Requirement
40
+ requirement: &70291511196880 !ruby/object:Gem::Requirement
41
41
  none: false
42
42
  requirements:
43
43
  - - ~>
@@ -45,7 +45,7 @@ dependencies:
45
45
  version: '3.0'
46
46
  type: :runtime
47
47
  prerelease: false
48
- version_requirements: *16305880
48
+ version_requirements: *70291511196880
49
49
  description: Interface for interchanging which type of data store to persist data
50
50
  to
51
51
  email:
@@ -94,4 +94,7 @@ rubygems_version: 1.8.10
94
94
  signing_key:
95
95
  specification_version: 3
96
96
  summary: Interface for interchanging which type of data store to persist data to
97
- test_files: []
97
+ test_files:
98
+ - spec/guitar_data_model_spec.rb
99
+ - spec/guitar_spec.rb
100
+ - spec/support/shared_examples/mince_data_model_examples.rb