mapping 0.2.0 → 0.3.0
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.
- checksums.yaml +4 -4
- data/README.md +5 -1
- data/lib/mapping/model.rb +0 -20
- data/lib/mapping/object_model.rb +45 -0
- data/lib/mapping/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 01ccd21c0d569fdcb8a86d6167a18a6ecfd4c450
|
4
|
+
data.tar.gz: d4243a6e2b706234e3d9b563944417a48f72716c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e87b6766578ecd343e80699ca66ed56933427cd75d554a34549724feb94e656182905038f2ed91fb9ca21ab4ff4aa4d3775d4c5208a6d8a6704c388b76d5aca3
|
7
|
+
data.tar.gz: d5770f491a5ca89607665529603825c57db1eaaa0bd11383c69ebf820ab1e11a63e72dcf69a116ddad44e183ef83139934845d8a197022f0e33d676a8ee7f1e3
|
data/README.md
CHANGED
@@ -61,7 +61,7 @@ module Human
|
|
61
61
|
end
|
62
62
|
|
63
63
|
# Your mapping model:
|
64
|
-
class APIv1 < Mapping::
|
64
|
+
class APIv1 < Mapping::ObjectModel
|
65
65
|
map(Human::Person) do |object|
|
66
66
|
{
|
67
67
|
name: object.name,
|
@@ -100,6 +100,10 @@ expect(model.map(person)).to be == {
|
|
100
100
|
}
|
101
101
|
```
|
102
102
|
|
103
|
+
### Model vs ObjectModel
|
104
|
+
|
105
|
+
The base `Mapping::Model` class provides only the basic structure required to create and invoke mapping methods. The `Mapping::ObjectModel` provides a few default mappings for `true`, `false`, `nil`, `Array` and `Hash`.
|
106
|
+
|
103
107
|
## Contributing
|
104
108
|
|
105
109
|
1. Fork it
|
data/lib/mapping/model.rb
CHANGED
@@ -36,26 +36,6 @@ module Mapping
|
|
36
36
|
define_method(method_name, &block)
|
37
37
|
end
|
38
38
|
|
39
|
-
map(NilClass) do |object|
|
40
|
-
nil
|
41
|
-
end
|
42
|
-
|
43
|
-
map(TrueClass) do |object|
|
44
|
-
true
|
45
|
-
end
|
46
|
-
|
47
|
-
map(FalseClass) do |object|
|
48
|
-
false
|
49
|
-
end
|
50
|
-
|
51
|
-
map(Array) do |items|
|
52
|
-
items.collect{|object| map(object)}
|
53
|
-
end
|
54
|
-
|
55
|
-
map(Hash) do |hash|
|
56
|
-
hash
|
57
|
-
end
|
58
|
-
|
59
39
|
def map(root, *args)
|
60
40
|
method_name = self.method_for_mapping(root)
|
61
41
|
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# Copyright, 2016, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
20
|
+
|
21
|
+
require_relative 'model'
|
22
|
+
|
23
|
+
module Mapping
|
24
|
+
class ObjectModel < Model
|
25
|
+
map(NilClass) do |object|
|
26
|
+
nil
|
27
|
+
end
|
28
|
+
|
29
|
+
map(TrueClass) do |object|
|
30
|
+
true
|
31
|
+
end
|
32
|
+
|
33
|
+
map(FalseClass) do |object|
|
34
|
+
false
|
35
|
+
end
|
36
|
+
|
37
|
+
map(Array) do |items|
|
38
|
+
items.collect{|object| map(object)}
|
39
|
+
end
|
40
|
+
|
41
|
+
map(Hash) do |hash|
|
42
|
+
hash
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/lib/mapping/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mapping
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-03-
|
11
|
+
date: 2016-03-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -70,6 +70,7 @@ files:
|
|
70
70
|
- Rakefile
|
71
71
|
- lib/mapping.rb
|
72
72
|
- lib/mapping/model.rb
|
73
|
+
- lib/mapping/object_model.rb
|
73
74
|
- lib/mapping/version.rb
|
74
75
|
- mapping.gemspec
|
75
76
|
homepage: https://github.com/ioquatix/mapping
|