minimapper 0.5.1 → 0.5.2
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/README.md +2 -2
- data/lib/minimapper/entity/convert.rb +1 -1
- data/lib/minimapper/mapper/ar.rb +2 -2
- data/lib/minimapper/mapper/common.rb +2 -2
- data/lib/minimapper/mapper/memory.rb +1 -1
- data/lib/minimapper/version.rb +1 -1
- data/spec/support/shared_examples/mapper.rb +6 -6
- data/unit/entity/convert_spec.rb +5 -1
- metadata +4 -10
data/README.md
CHANGED
@@ -23,7 +23,7 @@ This gem is tested against all major rubies in 1.8, 1.9 and 2.0, see [.travis.ym
|
|
23
23
|
|
24
24
|
### Only the most basic API
|
25
25
|
|
26
|
-
This library only implements the most basic persistence API (mostly just CRUD). Any significant additions will be made into separate gems. The reasons for this are:
|
26
|
+
This library only implements the most basic persistence API (mostly just CRUD). Any significant additions will be made into separate gems (like [minimapper-extras](https://github.com/barsoom/minimapper-extras)). The reasons for this are:
|
27
27
|
|
28
28
|
* It should have a stable API
|
29
29
|
* It should be possible to learn all it does in a short time
|
@@ -91,7 +91,7 @@ old_id = user.id
|
|
91
91
|
user_mapper.delete(user)
|
92
92
|
p user.id # => nil
|
93
93
|
p user_mapper.find_by_id(old_id) # => nil
|
94
|
-
# user_mapper.find(old_id) # raises Minimapper::
|
94
|
+
# user_mapper.find(old_id) # raises Minimapper::EntityNotFound
|
95
95
|
# user_mapper.delete_all
|
96
96
|
# user_mapper.delete_by_id(1)
|
97
97
|
|
data/lib/minimapper/mapper/ar.rb
CHANGED
@@ -107,7 +107,7 @@ module Minimapper
|
|
107
107
|
|
108
108
|
def find_record_safely(id)
|
109
109
|
find_record(id) ||
|
110
|
-
raise(
|
110
|
+
raise(EntityNotFound, :id => id)
|
111
111
|
end
|
112
112
|
|
113
113
|
def find_record(id)
|
@@ -116,7 +116,7 @@ module Minimapper
|
|
116
116
|
|
117
117
|
def record_for(entity)
|
118
118
|
(entity.id && record_class.find_by_id(entity.id)) ||
|
119
|
-
raise(
|
119
|
+
raise(EntityNotFound, entity.inspect)
|
120
120
|
end
|
121
121
|
|
122
122
|
def entities_for(records)
|
data/lib/minimapper/version.rb
CHANGED
@@ -64,7 +64,7 @@ shared_examples :mapper do
|
|
64
64
|
end
|
65
65
|
|
66
66
|
it "fails when an entity can not be found" do
|
67
|
-
lambda { mapper.find(-1) }.should raise_error(Minimapper::
|
67
|
+
lambda { mapper.find(-1) }.should raise_error(Minimapper::EntityNotFound)
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
@@ -199,14 +199,14 @@ shared_examples :mapper do
|
|
199
199
|
|
200
200
|
it "fails when the entity does not have an id" do
|
201
201
|
entity = build_valid_entity
|
202
|
-
lambda { mapper.update(entity) }.should raise_error(Minimapper::
|
202
|
+
lambda { mapper.update(entity) }.should raise_error(Minimapper::EntityNotFound)
|
203
203
|
end
|
204
204
|
|
205
205
|
it "fails when the entity no longer exists" do
|
206
206
|
entity = build_valid_entity
|
207
207
|
mapper.create(entity)
|
208
208
|
mapper.delete_all
|
209
|
-
lambda { mapper.update(entity) }.should raise_error(Minimapper::
|
209
|
+
lambda { mapper.update(entity) }.should raise_error(Minimapper::EntityNotFound)
|
210
210
|
end
|
211
211
|
end
|
212
212
|
|
@@ -231,13 +231,13 @@ shared_examples :mapper do
|
|
231
231
|
|
232
232
|
it "fails when the entity does not have an id" do
|
233
233
|
entity = entity_class.new
|
234
|
-
lambda { mapper.delete(entity) }.should raise_error(Minimapper::
|
234
|
+
lambda { mapper.delete(entity) }.should raise_error(Minimapper::EntityNotFound)
|
235
235
|
end
|
236
236
|
|
237
237
|
it "fails when the entity can not be found" do
|
238
238
|
entity = entity_class.new
|
239
239
|
entity.id = -1
|
240
|
-
lambda { mapper.delete(entity) }.should raise_error(Minimapper::
|
240
|
+
lambda { mapper.delete(entity) }.should raise_error(Minimapper::EntityNotFound)
|
241
241
|
end
|
242
242
|
end
|
243
243
|
|
@@ -252,7 +252,7 @@ shared_examples :mapper do
|
|
252
252
|
end
|
253
253
|
|
254
254
|
it "fails when an entity can not be found" do
|
255
|
-
lambda { mapper.delete_by_id(-1) }.should raise_error(Minimapper::
|
255
|
+
lambda { mapper.delete_by_id(-1) }.should raise_error(Minimapper::EntityNotFound)
|
256
256
|
end
|
257
257
|
end
|
258
258
|
|
data/unit/entity/convert_spec.rb
CHANGED
@@ -11,7 +11,7 @@ describe Minimapper::Entity::Convert do
|
|
11
11
|
described_class.new('2012-01-01 20:57').to(:date_time).should == DateTime.new(2012, 01, 01, 20, 57)
|
12
12
|
end
|
13
13
|
|
14
|
-
it "
|
14
|
+
it "makes it nil when it can't convert" do
|
15
15
|
described_class.new(' ').to(:integer).should be_nil
|
16
16
|
described_class.new(' ').to(:date_time).should be_nil
|
17
17
|
described_class.new('garbage').to(:integer).should be_nil
|
@@ -21,4 +21,8 @@ describe Minimapper::Entity::Convert do
|
|
21
21
|
it "returns the value as-is when it does not know how to convert it" do
|
22
22
|
described_class.new('foobar').to(:unknown).should == 'foobar'
|
23
23
|
end
|
24
|
+
|
25
|
+
it "does not make false nil" do
|
26
|
+
described_class.new(false).to(:unknown).should eq(false)
|
27
|
+
end
|
24
28
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: minimapper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-04-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
16
|
-
requirement: &
|
16
|
+
requirement: &70225357873540 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70225357873540
|
25
25
|
description: A minimalistic way of separating your models from ORMs like ActiveRecord.
|
26
26
|
email:
|
27
27
|
- joakim.kolsjo@gmail.com
|
@@ -75,18 +75,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
75
75
|
- - ! '>='
|
76
76
|
- !ruby/object:Gem::Version
|
77
77
|
version: '0'
|
78
|
-
segments:
|
79
|
-
- 0
|
80
|
-
hash: 3918684014874405558
|
81
78
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
79
|
none: false
|
83
80
|
requirements:
|
84
81
|
- - ! '>='
|
85
82
|
- !ruby/object:Gem::Version
|
86
83
|
version: '0'
|
87
|
-
segments:
|
88
|
-
- 0
|
89
|
-
hash: 3918684014874405558
|
90
84
|
requirements: []
|
91
85
|
rubyforge_project:
|
92
86
|
rubygems_version: 1.8.5
|