hashy_db 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,21 +1,54 @@
1
- # What is this?
1
+ # What is hashy db?
2
2
 
3
3
  Light weight ORM to persist data to a hash.
4
4
 
5
+ Provides an interface for storing and retreiving information to a Hash.
6
+
7
+ 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.
8
+
9
+ [@github](https://github.com/asynchrony/HashyDB)
10
+ [@rubygems](https://rubygems.org/gems/hashy_db)
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
+ Basic usage is to create a constant called DB_HASH and set it to an empty hash in an initializer file, or whenever your application gets loaded (if you're not running rails).
17
+
18
+ <pre>
19
+ # initializers/datastore.rb
20
+ ::DB_HASH = {}
21
+ </pre>
22
+
23
+ From there you can use Hashy Db to add and retrieve data.
24
+
25
+ <pre>
26
+ # Add a book to the books collection
27
+ HashyDb::DataStore.add 'books', title: 'The World In Photographs', publisher: 'National Geographic'
28
+
29
+ # Retrieve all records from the books collection
30
+ HashyDb::DataStore.find_all 'books'
31
+
32
+ # Update a field with a value for a specific record
33
+ HashyDb::DataStore.update_field_with_value 'books', 'primary_id_123', :field_name, 'value to update with'
34
+
35
+ # Replace a specific book
36
+ HashyDb::DataStore.replace 'books', id: 1, title: 'A World In Photographs', publisher: 'National Geographic'
37
+ </pre>
38
+
39
+ View the [data_store.rb](https://github.com/asynchrony/hashy_db/blob/master/lib/hashy_db/data_store.rb) file for all methods available.
40
+
41
+ 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 [Mince](https://github.com/asynchrony/mince), a MongoDB implementation.
42
+
43
+
5
44
  # Why would you want this?
6
45
 
7
46
  - To defer choosing your database until you know most about your application.
8
47
  - Provides assitance in designing a database agnostic architecture.
48
+ - Offers very little technical dependencies. In order to develop or run the tests for your application you just need ruby installed, run bundle install and you're good to go. No need to install and start your database, migrate, etc.
9
49
 
10
50
  The hash can be loaded in memory and be used as your data store.
11
51
 
12
- Example in a rails app:
13
-
14
- initializers/datastore.rb
15
-
16
- `
17
- ::DB_HASH = {}
18
- `
19
52
  # Contribute
20
53
 
21
54
  - fork into a topic branch, write specs, make a pull request.
@@ -23,9 +56,10 @@ initializers/datastore.rb
23
56
  # Owners
24
57
 
25
58
  Matt Simpson - [@railsgrammer](https://twitter.com/railsgrammer)
26
- <br />
59
+
27
60
  Jason Mayer - [@farkerhaiku](https://twitter.com/farkerhaiku)
28
61
 
29
62
  # Contributors
30
63
 
31
64
  David Czarnecki - [@czarneckid](https://twitter.com/czarneckid)
65
+ Amos King - [@adkron](https://twitter.com/adkron)
@@ -25,6 +25,10 @@ module HashyDb
25
25
  collection[index] = hash
26
26
  end
27
27
 
28
+ def update_field_with_value(collection_name, primary_key_value, field_name, new_value)
29
+ find(collection_name, :id, primary_key_value)[field_name] = new_value
30
+ end
31
+
28
32
  def get_all_for_key_with_value(collection_name, key, value)
29
33
  find_all(collection_name).select { |a| a[key] == value }
30
34
  end
@@ -96,4 +100,4 @@ module HashyDb
96
100
  @data_store ||= ::DB_HASH
97
101
  end
98
102
  end
99
- end
103
+ end
@@ -1,3 +1,3 @@
1
1
  module HashyDb
2
- VERSION = '0.0.5'
2
+ VERSION = '0.0.6'
3
3
  end
@@ -50,6 +50,12 @@ describe HashyDb::DataStore do
50
50
  subject.find(:some_collection, :id, 2)[:field_1].should == 'value modified'
51
51
  end
52
52
 
53
+ it 'can update a field with a value on a specific record' do
54
+ subject.update_field_with_value(:some_collection, 3, :field_2, '10')
55
+
56
+ subject.find(:some_collection, :id, 3)[:field_2].should == '10'
57
+ end
58
+
53
59
  it 'can get one document' do
54
60
  subject.find(:some_collection, :field_1, 'value 1').should == data1
55
61
  subject.find(:some_collection, :field_2, 6).should == data2
@@ -100,4 +106,4 @@ describe HashyDb::DataStore do
100
106
  it 'can get a record for a specific key and value' do
101
107
  subject.get_for_key_with_value(:some_collection, :field_1, 'value 1').should == data1
102
108
  end
103
- end
109
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hashy_db
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
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-03 00:00:00.000000000 Z
14
+ date: 2012-04-04 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: activesupport
18
- requirement: &70323341342760 !ruby/object:Gem::Requirement
18
+ requirement: !ruby/object:Gem::Requirement
19
19
  none: false
20
20
  requirements:
21
21
  - - ~>
@@ -23,10 +23,15 @@ dependencies:
23
23
  version: '3.1'
24
24
  type: :runtime
25
25
  prerelease: false
26
- version_requirements: *70323341342760
26
+ version_requirements: !ruby/object:Gem::Requirement
27
+ none: false
28
+ requirements:
29
+ - - ~>
30
+ - !ruby/object:Gem::Version
31
+ version: '3.1'
27
32
  - !ruby/object:Gem::Dependency
28
33
  name: rake
29
- requirement: &70323341342040 !ruby/object:Gem::Requirement
34
+ requirement: !ruby/object:Gem::Requirement
30
35
  none: false
31
36
  requirements:
32
37
  - - ! '>='
@@ -34,10 +39,15 @@ dependencies:
34
39
  version: '0'
35
40
  type: :development
36
41
  prerelease: false
37
- version_requirements: *70323341342040
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
38
48
  - !ruby/object:Gem::Dependency
39
49
  name: rspec
40
- requirement: &70323341340960 !ruby/object:Gem::Requirement
50
+ requirement: !ruby/object:Gem::Requirement
41
51
  none: false
42
52
  requirements:
43
53
  - - ! '>='
@@ -45,7 +55,12 @@ dependencies:
45
55
  version: '0'
46
56
  type: :development
47
57
  prerelease: false
48
- version_requirements: *70323341340960
58
+ version_requirements: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
49
64
  description: Provides an interface to store and retrieve data in a Hash.
50
65
  email:
51
66
  - matt@railsgrammer.com
@@ -56,7 +71,6 @@ extra_rdoc_files: []
56
71
  files:
57
72
  - .gitignore
58
73
  - .rspec
59
- - .rvmrc
60
74
  - Gemfile
61
75
  - LICENSE.txt
62
76
  - README.md
@@ -86,7 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
86
100
  version: '0'
87
101
  requirements: []
88
102
  rubyforge_project: hashy_db
89
- rubygems_version: 1.8.10
103
+ rubygems_version: 1.8.21
90
104
  signing_key:
91
105
  specification_version: 3
92
106
  summary: Provides an interface to store and retrieve data in a Hash.
data/.rvmrc DELETED
@@ -1 +0,0 @@
1
- rvm use 1.9.3@hashy_db --create