modalsupport 0.8.0 → 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.8.0
1
+ 0.8.1
@@ -22,7 +22,12 @@ module ModalSupport
22
22
  when Array
23
23
  blk[container.map{|v| recursive_map(v, &blk)}]
24
24
  else
25
- blk[container]
25
+ case mapped = blk[container]
26
+ when Hash, Array
27
+ recursive_map(mapped, &blk)
28
+ else
29
+ mapped
30
+ end
26
31
  end
27
32
  end
28
33
 
data/modalsupport.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{modalsupport}
8
- s.version = "0.8.0"
8
+ s.version = "0.8.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Javier Goizueta"]
@@ -5,9 +5,20 @@ class TestRecursiveMap < Test::Unit::TestCase
5
5
  context "recursive_map" do
6
6
 
7
7
  setup do
8
+ require 'yaml'
8
9
  @value_doubler = lambda{|v| v.kind_of?(Numeric) ? v*2 : v}
9
10
  @hash_to_array = lambda{|v| v.kind_of?(Hash) ? v.to_a : v}
10
11
  @array_to_string = lambda{|v| v.kind_of?(Array) ? v.inspect : v}
12
+ @string_to_cont_and_double = lambda{|v|
13
+ case v
14
+ when String
15
+ YAML.load(v)
16
+ when Numeric
17
+ v*2
18
+ else
19
+ v
20
+ end
21
+ }
11
22
  end
12
23
 
13
24
  should "process values in containers" do
@@ -68,7 +79,17 @@ class TestRecursiveMap < Test::Unit::TestCase
68
79
  )
69
80
  end
70
81
  end
71
-
82
+
83
+ should "recursively process elements transformed to a container" do
84
+ assert_equal(
85
+ [222, 444],
86
+ ModalSupport.recursive_map("[111, 222]", &@string_to_cont_and_double)
87
+ )
88
+ assert_equal(
89
+ [222, 444, [2, 4, 6]],
90
+ ModalSupport.recursive_map("[111, 222, [1, 2, 3]]", &@string_to_cont_and_double)
91
+ )
92
+ end
72
93
 
73
94
  end
74
95
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: modalsupport
3
3
  version: !ruby/object:Gem::Version
4
- hash: 63
4
+ hash: 61
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 8
9
- - 0
10
- version: 0.8.0
9
+ - 1
10
+ version: 0.8.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Javier Goizueta