footing 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,6 +8,7 @@ module Footing
8
8
  "Object",
9
9
  "String",
10
10
  "Numeric",
11
+ "Array",
11
12
  "Hash"
12
13
  ]
13
14
  end
@@ -1,5 +1,18 @@
1
1
  module Footing
2
2
  module Array
3
3
 
4
+ # Recursively casts all string values in this Array.
5
+ # See Footing::String#cast
6
+ def cast_values!
7
+ each_with_index do |value, index|
8
+ if value.respond_to?(:cast_values!)
9
+ value.cast_values!
10
+ elsif value.respond_to?(:cast)
11
+ self[index] = value.cast
12
+ end
13
+ end
14
+ self
15
+ end
16
+
4
17
  end
5
18
  end
@@ -50,5 +50,18 @@ module Footing
50
50
  each { |k, v| self[k] = yield(v) }
51
51
  end
52
52
 
53
+ # Recursively casts all string values in this Hash.
54
+ # See Footing::String#cast
55
+ def cast_values!
56
+ each do |key, value|
57
+ if value.respond_to?(:cast_values!)
58
+ value.cast_values!
59
+ elsif value.respond_to?(:cast)
60
+ self[key] = value.cast
61
+ end
62
+ end
63
+ self
64
+ end
65
+
53
66
  end
54
67
  end
@@ -1,3 +1,3 @@
1
1
  module Footing
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
@@ -0,0 +1,63 @@
1
+ require File.join(File.dirname(__FILE__), "test_helper")
2
+
3
+ class ArrayTest < MicroTest::Test
4
+
5
+ test ".cast_values!" do
6
+ list = [
7
+ "1",
8
+ "2",
9
+ "3",
10
+ "0.1",
11
+ "0.2",
12
+ "0.3",
13
+ "true",
14
+ "false",
15
+ [
16
+ "1",
17
+ "2",
18
+ "3",
19
+ "0.1",
20
+ "0.2",
21
+ "0.3",
22
+ "true",
23
+ "false"
24
+ ],
25
+ {
26
+ :number => "1",
27
+ :true => "true",
28
+ :false => "false",
29
+ :ilist => ["1", "2", "3"],
30
+ :flist => ["0.1", "0.2", "0.3"]
31
+ }
32
+ ]
33
+ expected = [
34
+ 1,
35
+ 2,
36
+ 3,
37
+ 0.1,
38
+ 0.2,
39
+ 0.3,
40
+ true,
41
+ false,
42
+ [
43
+ 1,
44
+ 2,
45
+ 3,
46
+ 0.1,
47
+ 0.2,
48
+ 0.3,
49
+ true,
50
+ false
51
+ ],
52
+ {
53
+ :number => 1,
54
+ :true => true,
55
+ :false => false,
56
+ :ilist => [1, 2, 3],
57
+ :flist => [0.1, 0.2, 0.3],
58
+ }
59
+ ]
60
+ assert list.cast_values! == expected
61
+ end
62
+
63
+ end
@@ -9,4 +9,40 @@ class HashTest < MicroTest::Test
9
9
  assert dict == {:a=>"1", :b=>"2", :c=>"3"}
10
10
  end
11
11
 
12
+ test ".cast_values!" do
13
+ dict = {
14
+ :integer => "1",
15
+ :float => "0.1",
16
+ :true => "true",
17
+ :false => "false",
18
+ :ilist => ["1", "2", "3"],
19
+ :flist => ["0.1", "0.2", "0.3"],
20
+ :nested => {
21
+ :number => "1",
22
+ :true => "true",
23
+ :false => "false",
24
+ :ilist => ["1", "2", "3"],
25
+ :flist => ["0.1", "0.2", "0.3"]
26
+ }
27
+ }
28
+
29
+ expected = {
30
+ :integer => 1,
31
+ :float => 0.1,
32
+ :true => true,
33
+ :false => false,
34
+ :ilist => [1, 2, 3],
35
+ :flist => [0.1, 0.2, 0.3],
36
+ :nested => {
37
+ :number => 1,
38
+ :true => true,
39
+ :false => false,
40
+ :ilist => [1, 2, 3],
41
+ :flist => [0.1, 0.2, 0.3]
42
+ }
43
+ }
44
+
45
+ assert dict.cast_values! == expected
46
+ end
47
+
12
48
  end
@@ -2,3 +2,5 @@ require "rubygems"
2
2
  require "bundler"
3
3
  Bundler.require :default, :development
4
4
  require File.join(File.dirname(__FILE__), "..", "lib", "footing")
5
+
6
+ Footing.patch_all!
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: footing
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -35,6 +35,7 @@ files:
35
35
  - Gemfile.lock
36
36
  - LICENSE.txt
37
37
  - README.md
38
+ - test/array_test.rb
38
39
  - test/footing_test.rb
39
40
  - test/hash_test.rb
40
41
  - test/kernel_test.rb