yahm 0.2.1 → 0.2.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 65294e27394f32d968fccc87d710ef04e194a9a4
4
- data.tar.gz: d6872442109cbb2f911e6dc9d9fa8bc0cbd6f9f4
3
+ metadata.gz: 9af09e8325917b6053958436d5eb7023eeedd0b8
4
+ data.tar.gz: b1b6bac49b1327d23be32f9116c10948ce4102c0
5
5
  SHA512:
6
- metadata.gz: 5cc6c141459df2b04429daa8a1868c7caf07221b556cff5c9be2c9077fc46bf73593d9591f6accf0ea67ca4e836197f485a2ff96f45842cf2d7a241330e39304
7
- data.tar.gz: b96ffcc2b00d4d1a20b11615dda517f9d51ab5c84be464161729c547b4bfd81e05bd052cba5da285d9d6ae34fc855945797033e42e3a303b98c84db8436eda85
6
+ metadata.gz: d2a65fe0f491797b8402f5b9632f06eb9d73fc3dbcdc7ddf563a4207d36b5e2795b0d079c3da7f9d0b0a0eb4ac1454d613bfff41fc5e589bdb5c8d947c86b9ba
7
+ data.tar.gz: a65e1f32dc5697a8975f776e3efcc3877a32e054523576c7650be395a8f968eab900d99f0a32104dc0b7030282ae5b734ce4fa7791aec53c50c9363161c4ef58
@@ -23,35 +23,20 @@ class Yahm::Mapping
23
23
 
24
24
  @rules.each do |rule|
25
25
  thread_pool.process do
26
- apply_rule(rule, input_hash, @result)
26
+ apply_rule(rule, input_hash, @result, options)
27
27
  end
28
28
  end
29
29
 
30
30
  thread_pool.shutdown
31
31
  else
32
32
  @rules.each do |rule|
33
- apply_rule(rule, input_hash, @result)
33
+ apply_rule(rule, input_hash, @result, options)
34
34
  end
35
35
  end
36
36
 
37
37
  @result
38
38
  end
39
39
 
40
- #
41
- # dynamic context method resolutuon
42
- #
43
- def method_missing(sym, *args, &block)
44
- if @context.respond_to?(sym)
45
- @context.send(sym, *args, &block)
46
- else
47
- super
48
- end
49
- end
50
-
51
- def respond_to_missing?(sym, *)
52
- @context.respond_to?(sym) || super
53
- end
54
-
55
40
  private
56
41
 
57
42
  def map(path, options = {})
@@ -59,7 +44,7 @@ class Yahm::Mapping
59
44
  self
60
45
  end
61
46
 
62
- def apply_rule(rule, input_hash, output_hash)
47
+ def apply_rule(rule, input_hash, output_hash, options = {})
63
48
  value =
64
49
  if rule[:path].is_a?(Array)
65
50
  rule[:path].inject({}) do |memo, _path|
@@ -73,10 +58,10 @@ class Yahm::Mapping
73
58
  value = rule[:default] && value.nil? ? rule[:default] : value
74
59
  value = rule[:force_array] ? (value.nil? ? [] : [value].flatten(1)) : value
75
60
  value = rule[:split_by] && value.is_a?(String) ? value.split(rule[:split_by]).map!(&:strip) : value
76
- value = rule[:processed_by] ? rule[:processed_by].call(value) : value
61
+ value = rule[:processed_by] ? (options[:context] || @context || self).instance_exec(value, &rule[:processed_by]) : value
77
62
 
78
63
  if rule[:to].is_a?(Proc)
79
- instance_exec(value, output_hash, &rule[:to])
64
+ (options[:context] || @context || self).instance_exec(value, output_hash, &rule[:to])
80
65
  else
81
66
  Hpath.set(output_hash, rule[:to], value)
82
67
  end
@@ -1,3 +1,3 @@
1
1
  class Yahm
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
@@ -144,5 +144,19 @@ describe Yahm::Mapping do
144
144
  combined: "hello world"
145
145
  })
146
146
  end
147
+
148
+ it "can be called with a \"context\" option to set/overwrite the mapping context" do
149
+ mapping = Yahm::Mapping.new do
150
+ map "/source", to: "/target", processed_by: lambda { |v| process_value(v) }
151
+ end
152
+
153
+ context = Module.new do
154
+ def self.process_value(v)
155
+ v.to_i
156
+ end
157
+ end
158
+
159
+ expect(mapping.apply_to({source: "1"}, context: context)).to eq({target: 1})
160
+ end
147
161
  end
148
162
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yahm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Sievers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-12 00:00:00.000000000 Z
11
+ date: 2014-06-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hpath