yahm 0.0.7 → 0.0.8
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/lib/yahm/hash_mapper.rb +1 -1
- data/lib/yahm/mapping.rb +6 -3
- data/lib/yahm/version.rb +1 -1
- data/spec/yahm/hash_mapper_spec.rb +11 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c7184233b84f3abc2d69fc8e96c4a4832a8571eb
|
4
|
+
data.tar.gz: ce29e872ade8e3d0c73a82b1ec938f4f6c6034f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1580dd0447512dd5d9604dcefa59702885ced26b49be40b0bf0ce85e2faaf17e57d0a62073ee29af89607c821c8e81c63930888ddee4959f43b23febd2087e70
|
7
|
+
data.tar.gz: 48c173585006d03c01baa1c929492cce12d6c45a7ff9878d9ef6233528e397a0a4107b3711e3377a46ac3fadafb8ecb46d87fc8f91f42af022b31a56ebd3d54b
|
data/lib/yahm/hash_mapper.rb
CHANGED
@@ -6,7 +6,7 @@ module Yahm::HashMapper
|
|
6
6
|
mapping = mapping.instance_eval(&block) || mapping
|
7
7
|
|
8
8
|
define_method mapper_method_name do |hash|
|
9
|
-
translated_hash = mapping.translate_hash(hash)
|
9
|
+
translated_hash = mapping.translate_hash(hash, _self: self)
|
10
10
|
unless (setter_name = options[:call_setter]).nil?
|
11
11
|
self.send(setter_name, translated_hash)
|
12
12
|
end
|
data/lib/yahm/mapping.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
class Yahm::Mapping
|
2
|
-
|
2
|
+
|
3
|
+
attr_reader :_self
|
4
|
+
|
5
|
+
def initialize(options = {})
|
3
6
|
@rules = []
|
4
7
|
@translated_hash = nil
|
5
8
|
end
|
@@ -9,8 +12,8 @@ class Yahm::Mapping
|
|
9
12
|
self
|
10
13
|
end
|
11
14
|
|
12
|
-
def translate_hash(input_hash)
|
13
|
-
@
|
15
|
+
def translate_hash(input_hash, options = {})
|
16
|
+
@_self = options[:_self]
|
14
17
|
@translated_hash = {}
|
15
18
|
|
16
19
|
@rules.each do |rule|
|
data/lib/yahm/version.rb
CHANGED
@@ -18,7 +18,12 @@ describe Yahm::HashMapper do
|
|
18
18
|
class ClassExtendedWithHashMapper
|
19
19
|
extend Yahm::HashMapper
|
20
20
|
|
21
|
+
def sample_method(value)
|
22
|
+
true
|
23
|
+
end
|
24
|
+
|
21
25
|
define_mapper :my_mapper do
|
26
|
+
map "/source", to: "target", processed_by: proc { |v| _self.sample_method(v) }
|
22
27
|
end
|
23
28
|
end
|
24
29
|
end
|
@@ -27,6 +32,12 @@ describe Yahm::HashMapper do
|
|
27
32
|
expect(class_extended_with_hash_mapper.new).to respond_to(:my_mapper)
|
28
33
|
end
|
29
34
|
|
35
|
+
it "provides the context of the extended object as \"_self\" for \"processed_by\" callables" do
|
36
|
+
expect(class_extended_with_hash_mapper.new.my_mapper({source: "foo"})).to eq({
|
37
|
+
target: true
|
38
|
+
})
|
39
|
+
end
|
40
|
+
|
30
41
|
context "when called with an option called 'call_setter'" do
|
31
42
|
let(:class_extended_with_hash_mapper) do
|
32
43
|
class ClassExtendedWithHashMapper
|