minimapper 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 +47 -6
- data/lib/minimapper/memory.rb +2 -0
- data/lib/minimapper/version.rb +1 -1
- data/lib/minimapper.rb +0 -3
- data/unit/memory_spec.rb +0 -1
- metadata +3 -4
- data/LICENSE.txt +0 -22
data/README.md
CHANGED
@@ -13,7 +13,7 @@ Minimapper is a partial [repository-pattern](http://martinfowler.com/eaaCatalog/
|
|
13
13
|
This library only implements the most basic persistance API (mostly just CRUD). Any significant additions will be made into separate gems (with names like "minimapper-FOO").
|
14
14
|
|
15
15
|
The reasons for this are:
|
16
|
-
* You should be able to
|
16
|
+
* You should be able to depend on the API
|
17
17
|
* It should be possible to learn all it does in a short time
|
18
18
|
* It should be simple to add an adapter for a new database
|
19
19
|
* It should be simple to maintain minimapper
|
@@ -43,28 +43,37 @@ Please avoid installing directly from the github repository. Code will be pushed
|
|
43
43
|
You can use the mappers directly like this:
|
44
44
|
|
45
45
|
``` ruby
|
46
|
+
require "rubygems"
|
47
|
+
require "minimapper"
|
48
|
+
require "minimapper/entity"
|
49
|
+
require "minimapper/memory"
|
50
|
+
|
46
51
|
class User < Minimapper::Entity
|
47
52
|
attributes :name, :email
|
48
|
-
validates :name, presence
|
53
|
+
validates :name, :presence => true
|
49
54
|
end
|
50
55
|
|
51
56
|
class UserMapper < Minimapper::Memory
|
52
57
|
end
|
53
58
|
|
54
59
|
# Creating
|
55
|
-
user = User.new(name
|
60
|
+
user = User.new(:name => "Joe")
|
56
61
|
mapper = UserMapper.new
|
57
62
|
mapper.create(user)
|
58
63
|
|
59
64
|
# Finding
|
60
|
-
user = mapper.find(
|
65
|
+
user = mapper.find(user.id)
|
66
|
+
puts user.name # -> Joe
|
67
|
+
puts mapper.first.name # -> Joe
|
61
68
|
|
62
69
|
# Updating
|
63
70
|
user.name = "Joey"
|
64
71
|
mapper.update(user)
|
72
|
+
puts mapper.first.name # -> Joey
|
65
73
|
|
66
74
|
# Deleting
|
67
75
|
mapper.delete(user)
|
76
|
+
mapper.find(user) # raises Minimapper::Common::CanNotFindEntity
|
68
77
|
|
69
78
|
# Deleting all
|
70
79
|
mapper.delete_all
|
@@ -73,9 +82,11 @@ mapper.delete_all
|
|
73
82
|
Or though a repository:
|
74
83
|
|
75
84
|
``` ruby
|
85
|
+
require "minimapper/repository"
|
86
|
+
|
76
87
|
repository = Minimapper::Repository.build({
|
77
|
-
users
|
78
|
-
projects
|
88
|
+
:users => UserMapper.new,
|
89
|
+
:projects => ProjectMapper.new
|
79
90
|
})
|
80
91
|
|
81
92
|
repository.users.find(1)
|
@@ -84,6 +95,8 @@ repository.users.find(1)
|
|
84
95
|
## Using the ActiveRecord mapper
|
85
96
|
|
86
97
|
``` ruby
|
98
|
+
require "minimapper/ar"
|
99
|
+
|
87
100
|
module AR
|
88
101
|
class UserMapper < Minimapper::AR
|
89
102
|
end
|
@@ -115,6 +128,10 @@ Robert "Uncle Bob" Martin:
|
|
115
128
|
* [Architecture: The Lost Years](http://www.confreaks.com/videos/759-rubymidwest2011-keynote-architecture-the-lost-years)
|
116
129
|
* [The Clean Architecture](http://blog.8thlight.com/uncle-bob/2012/08/13/the-clean-architecture.html)
|
117
130
|
|
131
|
+
## Apps using minimapper
|
132
|
+
|
133
|
+
* The deploy status app that minimapper was extracted from: [https://github.com/joakimk/deployer](https://github.com/joakimk/deployer)
|
134
|
+
|
118
135
|
## Running the tests
|
119
136
|
|
120
137
|
You need mysql and postgres installed (but they do not have to be running) to be able to run bundle. The sql-mapper tests use sqlite3 by default.
|
@@ -131,3 +148,27 @@ You need mysql and postgres installed (but they do not have to be running) to be
|
|
131
148
|
4. Don't forget to write test
|
132
149
|
5. Push to the branch (`git push origin my-new-feature`)
|
133
150
|
6. Create new Pull Request
|
151
|
+
|
152
|
+
## Credits and license
|
153
|
+
|
154
|
+
By [Joakim Kolsjö](https://twitter.com/joakimk) under the MIT license:
|
155
|
+
|
156
|
+
> Copyright (c) 2012 Joakim Kolsjö
|
157
|
+
>
|
158
|
+
> Permission is hereby granted, free of charge, to any person obtaining a copy
|
159
|
+
> of this software and associated documentation files (the "Software"), to deal
|
160
|
+
> in the Software without restriction, including without limitation the rights
|
161
|
+
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
162
|
+
> copies of the Software, and to permit persons to whom the Software is
|
163
|
+
> furnished to do so, subject to the following conditions:
|
164
|
+
>
|
165
|
+
> The above copyright notice and this permission notice shall be included in
|
166
|
+
> all copies or substantial portions of the Software.
|
167
|
+
>
|
168
|
+
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
169
|
+
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
170
|
+
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
171
|
+
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
172
|
+
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
173
|
+
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
174
|
+
> THE SOFTWARE.
|
data/lib/minimapper/memory.rb
CHANGED
data/lib/minimapper/version.rb
CHANGED
data/lib/minimapper.rb
CHANGED
data/unit/memory_spec.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: minimapper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- "Joakim Kolsj\xC3\xB6"
|
@@ -61,7 +61,6 @@ files:
|
|
61
61
|
- .rvmrc
|
62
62
|
- .travis.yml
|
63
63
|
- Gemfile
|
64
|
-
- LICENSE.txt
|
65
64
|
- README.md
|
66
65
|
- Rakefile
|
67
66
|
- lib/minimapper.rb
|
data/LICENSE.txt
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
Copyright (c) 2012 Joakim Kolsjö
|
2
|
-
|
3
|
-
MIT License
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
-
a copy of this software and associated documentation files (the
|
7
|
-
"Software"), to deal in the Software without restriction, including
|
8
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
-
permit persons to whom the Software is furnished to do so, subject to
|
11
|
-
the following conditions:
|
12
|
-
|
13
|
-
The above copyright notice and this permission notice shall be
|
14
|
-
included in all copies or substantial portions of the Software.
|
15
|
-
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|