hashy_db 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -48,6 +48,10 @@ module HashyDB
48
48
  HashyDB::DataStore.instance.get_one(data_collection, :id, id)
49
49
  end
50
50
 
51
+ def by_field(field, value)
52
+ DataStore.instance.get_for_key_with_value(data_collection, field, value)
53
+ end
54
+
51
55
  def all
52
56
  HashyDB::DataStore.instance.get(data_collection)
53
57
  end
@@ -22,6 +22,10 @@ module HashyDB
22
22
  get(collection_name).select { |a| a[key] == value }
23
23
  end
24
24
 
25
+ def get_for_key_with_value(collection_name, key, value)
26
+ get_all_for_key_with_value(collection_name, key, value)[0]
27
+ end
28
+
25
29
  def get_by_params(collection_name, hash)
26
30
  get(collection_name).select do |record|
27
31
  hash.all?{|k,v| record[k] == v }
@@ -1,3 +1,3 @@
1
1
  module HashyDB
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
@@ -72,4 +72,8 @@ describe HashyDB::DataStore do
72
72
  records.first[:id].should == 1
73
73
  subject.get(:some_collection).size.should == 3
74
74
  end
75
+
76
+ it 'can get a record for a specific key and value' do
77
+ subject.get_for_key_with_value(:some_collection, :field_1, 'value 1').should == data1
78
+ end
75
79
  end
@@ -90,6 +90,16 @@ shared_examples_for 'a data model' do
90
90
  end
91
91
  end
92
92
 
93
+ describe "getting a data model by a specific field" do
94
+ let(:mock_data_model) { mock 'data model in the data store' }
95
+
96
+ it 'returns the stored data models' do
97
+ mock_data_store.should_receive(:get_for_key_with_value).with(collection_name, :field, 'some value').and_return(mock_data_model)
98
+
99
+ described_class.by_field(:field, 'some value').should == mock_data_model
100
+ end
101
+ end
102
+
93
103
  describe "getting all the data fields by a parameter hash" do
94
104
  let(:mock_data_models) { mock 'some data model'}
95
105
  let(:sample_hash) { {field1: nil, field2: 'not nil' }}
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.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -14,7 +14,7 @@ date: 2012-02-02 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
17
- requirement: &70340164683200 !ruby/object:Gem::Requirement
17
+ requirement: &70143401652780 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ~>
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: '3.1'
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *70340164683200
25
+ version_requirements: *70143401652780
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: rake
28
- requirement: &70340164682180 !ruby/object:Gem::Requirement
28
+ requirement: &70143401651840 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
- version_requirements: *70340164682180
36
+ version_requirements: *70143401651840
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: rspec
39
- requirement: &70340164681320 !ruby/object:Gem::Requirement
39
+ requirement: &70143401650920 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ! '>='
@@ -44,7 +44,7 @@ dependencies:
44
44
  version: '0'
45
45
  type: :development
46
46
  prerelease: false
47
- version_requirements: *70340164681320
47
+ version_requirements: *70143401650920
48
48
  description: Provides an inteface to store and retrieve data in a Hash.
49
49
  email:
50
50
  - matt@railsgrammer.com