kartograph 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +4 -0
- data/README.md +26 -0
- data/Rakefile +4 -0
- data/lib/kartograph.rb +1 -0
- data/lib/kartograph/map.rb +5 -0
- data/lib/kartograph/property.rb +1 -0
- data/lib/kartograph/scope_proxy.rb +17 -0
- data/lib/kartograph/version.rb +1 -1
- data/spec/lib/kartograph/map_spec.rb +13 -0
- data/spec/lib/kartograph/property_spec.rb +12 -0
- data/spec/lib/kartograph/scope_proxy_spec.rb +30 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4b117d28ec0561cefabaf740af34ebfb3cf48a68
|
4
|
+
data.tar.gz: 8874d274b2b788ebbd2c0e79a748c29cdd226e25
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b36df369277c0088da9f2fa895ef0ed1640a3c369beab8fc8286480c5f47bc3b98a5fe5e62a19621fc60a5372519df07336a98ce5b1135c06c6c041254709e57
|
7
|
+
data.tar.gz: ec90464e0b3402ac70249f44d96d5a78f19899c681674cb911043bbbc6b4e607eabaa1db7b03b9d5b590330d6050fedd7698caf27fa4450ad8a66b58bdf8cf00
|
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
A Serialization / Deserialization library.
|
4
4
|
|
5
|
+
[![Build Status](https://travis-ci.org/digitaloceancloud/kartograph.svg?branch=master)](https://travis-ci.org/digitaloceancloud/kartograph)
|
6
|
+
|
5
7
|
## Installation
|
6
8
|
|
7
9
|
Add this line to your application's Gemfile:
|
@@ -134,6 +136,30 @@ class CommentMapping
|
|
134
136
|
end
|
135
137
|
```
|
136
138
|
|
139
|
+
|
140
|
+
### Scope blocks
|
141
|
+
|
142
|
+
Sometimes adding scopes to all properties can be tedious, to avoid that, you can define properties within a scope block.
|
143
|
+
|
144
|
+
```ruby
|
145
|
+
class UserMapping
|
146
|
+
include Kartograph::DSL
|
147
|
+
|
148
|
+
kartograph do
|
149
|
+
scoped :read do
|
150
|
+
property :name
|
151
|
+
property :id
|
152
|
+
property :email, key: 'email_address' # The JSON returned has the key of email_address, our property is called email however.
|
153
|
+
end
|
154
|
+
|
155
|
+
scoped :update, :create do
|
156
|
+
property :name
|
157
|
+
property :email, key: 'email_address'
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
```
|
162
|
+
|
137
163
|
Now when JSON includes comments for a user, it will know how to map the comments using the provided Kartograph definition.
|
138
164
|
|
139
165
|
## Contributing
|
data/Rakefile
CHANGED
data/lib/kartograph.rb
CHANGED
@@ -7,6 +7,7 @@ module Kartograph
|
|
7
7
|
autoload :Property, 'kartograph/property'
|
8
8
|
autoload :PropertyCollection, 'kartograph/property_collection'
|
9
9
|
autoload :RootKey, 'kartograph/root_key'
|
10
|
+
autoload :ScopeProxy, 'kartograph/scope_proxy'
|
10
11
|
|
11
12
|
autoload :Artist, 'kartograph/artist'
|
12
13
|
autoload :Sculptor, 'kartograph/sculptor'
|
data/lib/kartograph/map.rb
CHANGED
data/lib/kartograph/property.rb
CHANGED
@@ -0,0 +1,17 @@
|
|
1
|
+
module Kartograph
|
2
|
+
class ScopeProxy
|
3
|
+
attr_reader :map, :scopes
|
4
|
+
|
5
|
+
def initialize(map, scopes)
|
6
|
+
@map, @scopes = map, scopes
|
7
|
+
end
|
8
|
+
|
9
|
+
def property(*args, &block)
|
10
|
+
options = args.last.is_a?(Hash) ? args.pop : {}
|
11
|
+
options[:scopes] = scopes
|
12
|
+
args << options
|
13
|
+
|
14
|
+
map.property(*args, &block)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/kartograph/version.rb
CHANGED
@@ -92,4 +92,17 @@ describe Kartograph::Map do
|
|
92
92
|
expect(map1).to eq(map2)
|
93
93
|
end
|
94
94
|
end
|
95
|
+
|
96
|
+
describe '#scoped' do
|
97
|
+
it 'adds properties with the scopes defined on the block instantiation' do
|
98
|
+
map.scoped :read, :write do
|
99
|
+
property :name
|
100
|
+
property :something
|
101
|
+
end
|
102
|
+
|
103
|
+
expect(map.properties.size).to eq(2)
|
104
|
+
expect(map.properties.filter_by_scope(:read).map(&:name)).to eq([:name, :something])
|
105
|
+
expect(map.properties.filter_by_scope(:write).map(&:name)).to eq([:name, :something])
|
106
|
+
end
|
107
|
+
end
|
95
108
|
end
|
@@ -109,6 +109,18 @@ describe Kartograph::Property do
|
|
109
109
|
])
|
110
110
|
end
|
111
111
|
end
|
112
|
+
|
113
|
+
context 'when the value for the root object is nil' do
|
114
|
+
it 'returns nil' do
|
115
|
+
top_level = Kartograph::Property.new(:sammy) do
|
116
|
+
property :cephalopod
|
117
|
+
end
|
118
|
+
|
119
|
+
root = double(sammy: nil)
|
120
|
+
|
121
|
+
expect(top_level.value_for(root)).to be_nil
|
122
|
+
end
|
123
|
+
end
|
112
124
|
end
|
113
125
|
end
|
114
126
|
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe Kartograph::ScopeProxy do
|
4
|
+
describe '#initialize' do
|
5
|
+
it 'initializes with a map, scopes, and a block' do
|
6
|
+
map, scopes = double, [:read, :write]
|
7
|
+
|
8
|
+
instance = Kartograph::ScopeProxy.new(map, scopes)
|
9
|
+
|
10
|
+
expect(instance.map).to be(map)
|
11
|
+
expect(instance.scopes).to be(scopes)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '#property' do
|
16
|
+
let(:map) { Kartograph::Map.new }
|
17
|
+
subject(:proxy) { Kartograph::ScopeProxy.new(map, [:read, :write]) }
|
18
|
+
|
19
|
+
it 'adds a property to the properties with the correct scope' do
|
20
|
+
proxy.property :hello
|
21
|
+
proxy.property :world
|
22
|
+
|
23
|
+
read_properties = map.properties.filter_by_scope(:read)
|
24
|
+
expect(read_properties.map(&:name)).to eq([:hello, :world])
|
25
|
+
|
26
|
+
write_properties = map.properties.filter_by_scope(:write)
|
27
|
+
expect(write_properties.map(&:name)).to eq([:hello, :world])
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kartograph
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Ross
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-08-
|
11
|
+
date: 2014-08-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -77,6 +77,7 @@ extra_rdoc_files: []
|
|
77
77
|
files:
|
78
78
|
- .gitignore
|
79
79
|
- .rspec
|
80
|
+
- .travis.yml
|
80
81
|
- Gemfile
|
81
82
|
- LICENSE.txt
|
82
83
|
- README.md
|
@@ -91,6 +92,7 @@ files:
|
|
91
92
|
- lib/kartograph/property.rb
|
92
93
|
- lib/kartograph/property_collection.rb
|
93
94
|
- lib/kartograph/root_key.rb
|
95
|
+
- lib/kartograph/scope_proxy.rb
|
94
96
|
- lib/kartograph/sculptor.rb
|
95
97
|
- lib/kartograph/version.rb
|
96
98
|
- spec/lib/kartograph/artist_spec.rb
|
@@ -99,6 +101,7 @@ files:
|
|
99
101
|
- spec/lib/kartograph/property_collection_spec.rb
|
100
102
|
- spec/lib/kartograph/property_spec.rb
|
101
103
|
- spec/lib/kartograph/root_key_spec.rb
|
104
|
+
- spec/lib/kartograph/scope_proxy_spec.rb
|
102
105
|
- spec/lib/kartograph/sculptor_spec.rb
|
103
106
|
- spec/spec_helper.rb
|
104
107
|
- spec/support/dsl_contexts.rb
|
@@ -136,6 +139,7 @@ test_files:
|
|
136
139
|
- spec/lib/kartograph/property_collection_spec.rb
|
137
140
|
- spec/lib/kartograph/property_spec.rb
|
138
141
|
- spec/lib/kartograph/root_key_spec.rb
|
142
|
+
- spec/lib/kartograph/scope_proxy_spec.rb
|
139
143
|
- spec/lib/kartograph/sculptor_spec.rb
|
140
144
|
- spec/spec_helper.rb
|
141
145
|
- spec/support/dsl_contexts.rb
|