kartograph 0.2.0 → 0.2.1
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 +1 -1
- data/lib/kartograph/map.rb +19 -3
- data/lib/kartograph/property.rb +1 -1
- data/lib/kartograph/root_key.rb +1 -1
- data/lib/kartograph/sculptor.rb +3 -1
- data/lib/kartograph/version.rb +1 -1
- data/spec/lib/kartograph/property_spec.rb +1 -1
- data/spec/lib/kartograph/root_key_spec.rb +5 -0
- data/spec/lib/kartograph/sculptor_spec.rb +6 -1
- metadata +2 -5
- data/lib/kartograph/scope_proxy.rb +0 -17
- data/spec/lib/kartograph/scope_proxy_spec.rb +0 -30
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3a573a744b7b213bb2721c5309cdeec2ea3fce35
|
4
|
+
data.tar.gz: 029172328c658996de6163c4473e6894e5a1f698
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ed413d7e3ce8cfc5506f427dd1dd6193e63eacedd492b02749bb4702603d7fd03b2ce57b07e2044fc77eb6d58d1e87c49af62b628ea6b942b4557a2b55bc80dc
|
7
|
+
data.tar.gz: bbdb12c55b428908117b1c03d19b0b74e408d682f40f72757a5a8982765039ac2c828ebca6f02554874adf7c68379aff57b81f9592a4b63a1b607b0b518e08d3
|
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
A Serialization / Deserialization library.
|
4
4
|
|
5
|
-
[](https://travis-ci.org/digitalocean/kartograph)
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
data/lib/kartograph/map.rb
CHANGED
@@ -1,7 +1,18 @@
|
|
1
|
+
require 'thread'
|
2
|
+
|
1
3
|
module Kartograph
|
2
4
|
class Map
|
5
|
+
def initialize
|
6
|
+
@scope_mutex = Mutex.new
|
7
|
+
end
|
8
|
+
|
3
9
|
def property(*args, &block)
|
4
10
|
options = args.last.is_a?(Hash) ? args.pop : {}
|
11
|
+
|
12
|
+
# Append scopes if we're currently mapping in a scoped block
|
13
|
+
options[:scopes] ||= []
|
14
|
+
options[:scopes] += Array(@current_scopes)
|
15
|
+
|
5
16
|
args.each do |prop|
|
6
17
|
properties << Property.new(prop, options, &block)
|
7
18
|
end
|
@@ -12,8 +23,13 @@ module Kartograph
|
|
12
23
|
end
|
13
24
|
|
14
25
|
def scoped(*scopes, &block)
|
15
|
-
|
16
|
-
|
26
|
+
@scope_mutex.synchronize do
|
27
|
+
@current_scopes = scopes
|
28
|
+
|
29
|
+
instance_eval(&block) if block_given?
|
30
|
+
|
31
|
+
@current_scopes = nil
|
32
|
+
end
|
17
33
|
end
|
18
34
|
|
19
35
|
def root_keys
|
@@ -65,7 +81,7 @@ module Kartograph
|
|
65
81
|
end
|
66
82
|
|
67
83
|
def ==(other)
|
68
|
-
methods = %i(properties root_keys mapping)
|
84
|
+
methods = %i(properties root_keys mapping cache cache_key)
|
69
85
|
methods.inject(true) do |current_value, method|
|
70
86
|
break unless current_value
|
71
87
|
send(method) == other.send(method)
|
data/lib/kartograph/property.rb
CHANGED
data/lib/kartograph/root_key.rb
CHANGED
data/lib/kartograph/sculptor.rb
CHANGED
@@ -12,6 +12,8 @@ module Kartograph
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def sculpt(scope = nil)
|
15
|
+
return nil if @object.nil?
|
16
|
+
|
15
17
|
# Initializing the object we're coercing so we can set attributes on it
|
16
18
|
coerced = map.mapping.new
|
17
19
|
scoped_properties = scope ? properties.filter_by_scope(scope) : properties
|
@@ -23,4 +25,4 @@ module Kartograph
|
|
23
25
|
end
|
24
26
|
end
|
25
27
|
end
|
26
|
-
end
|
28
|
+
end
|
data/lib/kartograph/version.rb
CHANGED
@@ -15,6 +15,11 @@ describe Kartograph::RootKey do
|
|
15
15
|
instance = Kartograph::RootKey.new(scopes: [:read])
|
16
16
|
expect(instance.scopes).to eq([:read])
|
17
17
|
end
|
18
|
+
|
19
|
+
it 'reads the scopes as an array always' do
|
20
|
+
instance = Kartograph::RootKey.new(scopes: :read)
|
21
|
+
expect(instance.scopes).to eq([:read])
|
22
|
+
end
|
18
23
|
end
|
19
24
|
|
20
25
|
describe '#singular' do
|
@@ -17,6 +17,11 @@ describe Kartograph::Sculptor do
|
|
17
17
|
let(:map) { Kartograph::Map.new }
|
18
18
|
let(:object) { { 'id' => 343, 'name' => 'Guilty Spark', 'email_address' => 'guilty@bungie.net' } }
|
19
19
|
|
20
|
+
it 'returns nil if the object in nil' do
|
21
|
+
sculptor = Kartograph::Sculptor.new(nil, map)
|
22
|
+
expect(sculptor.sculpt).to be_nil
|
23
|
+
end
|
24
|
+
|
20
25
|
context 'without a scope' do
|
21
26
|
before do
|
22
27
|
map.mapping DummyUser
|
@@ -75,4 +80,4 @@ describe Kartograph::Sculptor do
|
|
75
80
|
end
|
76
81
|
end
|
77
82
|
end
|
78
|
-
end
|
83
|
+
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.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Ross
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-03-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -93,7 +93,6 @@ files:
|
|
93
93
|
- lib/kartograph/property.rb
|
94
94
|
- lib/kartograph/property_collection.rb
|
95
95
|
- lib/kartograph/root_key.rb
|
96
|
-
- lib/kartograph/scope_proxy.rb
|
97
96
|
- lib/kartograph/sculptor.rb
|
98
97
|
- lib/kartograph/version.rb
|
99
98
|
- spec/lib/kartograph/artist_spec.rb
|
@@ -102,7 +101,6 @@ files:
|
|
102
101
|
- spec/lib/kartograph/property_collection_spec.rb
|
103
102
|
- spec/lib/kartograph/property_spec.rb
|
104
103
|
- spec/lib/kartograph/root_key_spec.rb
|
105
|
-
- spec/lib/kartograph/scope_proxy_spec.rb
|
106
104
|
- spec/lib/kartograph/sculptor_spec.rb
|
107
105
|
- spec/spec_helper.rb
|
108
106
|
- spec/support/dsl_contexts.rb
|
@@ -140,7 +138,6 @@ test_files:
|
|
140
138
|
- spec/lib/kartograph/property_collection_spec.rb
|
141
139
|
- spec/lib/kartograph/property_spec.rb
|
142
140
|
- spec/lib/kartograph/root_key_spec.rb
|
143
|
-
- spec/lib/kartograph/scope_proxy_spec.rb
|
144
141
|
- spec/lib/kartograph/sculptor_spec.rb
|
145
142
|
- spec/spec_helper.rb
|
146
143
|
- spec/support/dsl_contexts.rb
|
@@ -1,17 +0,0 @@
|
|
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
|
@@ -1,30 +0,0 @@
|
|
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
|