kartograph 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a5af5f7be8e9504c342f95484c349619f678ff61
4
- data.tar.gz: 99fd01c9d91b017907ed9716b24d9c28100ebde0
3
+ metadata.gz: ca1d38c7c5914edc0a9b78ffed7701e8b3cefff7
4
+ data.tar.gz: 386c0e6f38402b271d00907596052e34327c1ca4
5
5
  SHA512:
6
- metadata.gz: b8ef08180546de7f53a88f49960e36090ca36e77e8cdb83da34dd8b31b0d8f5334bbe92a00ce31be2b9ffec1ffa4cdeb1067965a978450229fc9f03133e71b1c
7
- data.tar.gz: b4458ec9475057f8d92e8039a88424f5c07efe00d0475444fa572b75c234a8adec2e2af630fd263c0f504fcdd88e939a2c1bb9b72b61466e23ff65893492fefb
6
+ metadata.gz: 254b47f2276dea83ef2e3de5ec260cc1ab3d6ed57a557382d725c1ee2d566f3e5f505ad4daacba0015e4112d63cee3b713e362a56115fb759f3b192516305eaa
7
+ data.tar.gz: 4a307fb10db634870adaa9f3d9c291803ace606f299e27a46cb91d45466203d17a33bd6b7d614541e517059af624b1db210e3ad3e92230f6702fe11d7d62a7b5
@@ -15,7 +15,7 @@ module Kartograph
15
15
  scoped_properties = scope ? properties.filter_by_scope(scope) : properties
16
16
  scoped_properties.each_with_object({}) do |property, mapped|
17
17
  raise ArgumentError, "#{object} does not respond to #{property.name}, so we can't map it" unless object.respond_to?(property.name)
18
- mapped[property.name] = property.value_for(object, scope)
18
+ mapped[property.key] = property.value_for(object, scope)
19
19
  end
20
20
  end
21
21
  end
@@ -19,6 +19,10 @@ module Kartograph
19
19
  end
20
20
  end
21
21
 
22
+ def key
23
+ options[:key] || name
24
+ end
25
+
22
26
  def value_for(object, scope = nil)
23
27
  value = object.send(name)
24
28
  map ? artist_value(value, scope) : value
@@ -26,7 +30,7 @@ module Kartograph
26
30
 
27
31
  def value_from(object, scope = nil)
28
32
  return if object.nil?
29
- value = object.has_key?(name) ? object[name] : object[name.to_s]
33
+ value = object.has_key?(key) ? object[key] : object[key.to_s]
30
34
  map ? sculpt_value(value, scope) : value
31
35
  end
32
36
 
@@ -1,4 +1,4 @@
1
1
  module Kartograph
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
4
4
 
@@ -35,6 +35,18 @@ describe Kartograph::Artist do
35
35
  expect { artist.draw }.to raise_error(ArgumentError).with_message("#{object} does not respond to bunk, so we can't map it")
36
36
  end
37
37
 
38
+ context 'for a property with a key set on it' do
39
+ it 'returns the hash with the key set correctly' do
40
+ object = double('object', hello: 'world')
41
+ properties << Kartograph::Property.new(:hello, key: :hola)
42
+
43
+ artist = Kartograph::Artist.new(object, map)
44
+ masterpiece = artist.draw
45
+
46
+ expect(masterpiece).to include(hola: 'world')
47
+ end
48
+ end
49
+
38
50
  context 'for filtered drawing' do
39
51
  it 'only returns the scoped properties' do
40
52
  object = double('object', hello: 'world', foo: 'bar')
@@ -9,6 +9,17 @@ describe Kartograph::Property do
9
9
  property = Kartograph::Property.new(name, options)
10
10
  expect(property.name).to eq(name)
11
11
  expect(property.options).to eq(options)
12
+ expect(property.key).to eq(:hey)
13
+ end
14
+
15
+ context 'with a key' do
16
+ it 'sets the key' do
17
+ name = :hey
18
+ options = { key: 'Hey' }
19
+ property = Kartograph::Property.new(name, options)
20
+
21
+ expect(property.key).to eq('Hey')
22
+ end
12
23
  end
13
24
 
14
25
  context 'with a block' do
@@ -15,13 +15,14 @@ describe Kartograph::Sculptor do
15
15
 
16
16
  describe '#sculpt' do
17
17
  let(:map) { Kartograph::Map.new }
18
- let(:object) { { 'id' => 343, 'name' => 'Guilty Spark' } }
18
+ let(:object) { { 'id' => 343, 'name' => 'Guilty Spark', 'email_address' => 'guilty@bungie.net' } }
19
19
 
20
20
  context 'without a scope' do
21
21
  before do
22
22
  map.mapping DummyUser
23
23
  map.property :id, scopes: [:read]
24
24
  map.property :name, scopes: [:read, :create]
25
+ map.property :email, scopes: [:read, :create], key: 'email_address'
25
26
  end
26
27
 
27
28
  it 'returns a coerced user' do
@@ -31,6 +32,7 @@ describe Kartograph::Sculptor do
31
32
  expect(sculpted).to be_kind_of(DummyUser)
32
33
  expect(sculpted.id).to eq(object['id'])
33
34
  expect(sculpted.name).to eq(object['name'])
35
+ expect(sculpted.email).to eq(object['email_address'])
34
36
  end
35
37
  end
36
38
 
@@ -1,2 +1 @@
1
- class DummyUser < Struct.new(:id, :name, :comment)
2
- end
1
+ DummyUser = Struct.new(:id, :name, :comment, :email)
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.6
4
+ version: 0.0.7
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-08 00:00:00.000000000 Z
11
+ date: 2014-08-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler