tengine_support 0.3.14 → 0.3.15

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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.14
1
+ 0.3.15
@@ -0,0 +1,6 @@
1
+ class Array
2
+ def deep_dup
3
+ map{|v| v.respond_to?(:deep_dup) ? v.deep_dup : v }
4
+ end
5
+
6
+ end
@@ -0,0 +1,8 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ # このファイルはクラスやモジュールを定義せず、tengine/support/core_ext/*.rbをrequireするだけです
4
+ Dir.chdir(File.expand_path("../../../", File.dirname(__FILE__))) do
5
+ Dir['tengine/support/core_ext/array'].each do |f|
6
+ require File.basename(f)
7
+ end
8
+ end
@@ -0,0 +1,23 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ # activesupport-3.1.0以上では
4
+ # active_support/core_ext/hash/deep_dupでHash#deep_dupを定義していますが、
5
+ # 対象がHashだけなのでArrayをコピーできません。
6
+ # Arrayや他のオブジェクトに対応するためにメソッドを上書きします。
7
+
8
+ if ActiveSupport::VERSION::STRING >= "3.1.0"
9
+ require 'active_support/core_ext/hash/deep_dup'
10
+ end
11
+
12
+ class Hash
13
+ # Returns a deep copy of hash.
14
+ def deep_dup
15
+ duplicate = self.dup
16
+ duplicate.each_pair do |k,v|
17
+ tv = duplicate[k]
18
+ duplicate[k] = tv.respond_to?(:deep_dup) && v.respond_to?(:deep_dup) ? tv.deep_dup : v
19
+ end
20
+ duplicate
21
+ end
22
+
23
+ end
@@ -1,6 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
- require 'active_support/core_ext/hash/deep_dup'
3
- require 'active_support/core_ext/hash/keys'
2
+ require 'tengine/support/core_ext/hash/deep_dup'
4
3
 
5
4
  class Hash
6
5
 
@@ -13,7 +12,11 @@ class Hash
13
12
  def deep_stringify_keys!
14
13
  stringify_keys! # active_support/core_ext/hash/keysのメソッドをそのまま使う
15
14
  values.each do |value|
16
- value.deep_stringify_keys! if value.respond_to?(:deep_stringify_keys!)
15
+ if value.respond_to?(:deep_stringify_keys!)
16
+ value.deep_stringify_keys!
17
+ elsif value.respond_to?(:each)
18
+ value.each{|v| v.deep_stringify_keys! if v.respond_to?(:deep_stringify_keys!)}
19
+ end
17
20
  end
18
21
  self
19
22
  end
@@ -29,7 +32,11 @@ class Hash
29
32
  def deep_symbolize_keys!
30
33
  symbolize_keys! # active_support/core_ext/hash/keysのメソッドをそのまま使う
31
34
  values.each do |value|
32
- value.deep_symbolize_keys! if value.respond_to?(:deep_symbolize_keys!)
35
+ if value.respond_to?(:deep_symbolize_keys!)
36
+ value.deep_symbolize_keys!
37
+ elsif value.respond_to?(:each)
38
+ value.each{|v| v.deep_symbolize_keys! if v.respond_to?(:deep_symbolize_keys!)}
39
+ end
33
40
  end
34
41
  self
35
42
  end
@@ -0,0 +1,62 @@
1
+ # -*- coding: utf-8 -*-
2
+ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
3
+
4
+ require 'active_support'
5
+ require "tengine/support/core_ext/array/deep_dup"
6
+
7
+ describe "tengine/support/core_ext/array/deep_dup" do
8
+
9
+ original = [
10
+ :a,
11
+ [
12
+ :b,
13
+ [:c, :d].freeze,
14
+ {
15
+ :e => {
16
+ :f => [:g, :h].freeze,
17
+ :i => {:j => :k}.freeze,
18
+ }.freeze
19
+ }.freeze
20
+ ].freeze
21
+ ].freeze
22
+
23
+ context "Hash#deep_dupがある場合" do
24
+ before do
25
+ load("tengine/support/core_ext/hash/deep_dup.rb")
26
+ end
27
+
28
+ subject{ original.deep_dup }
29
+ it { subject.should == original }
30
+ it { subject.object_id.should_not == original.object_id }
31
+ it { subject[1].object_id.should_not == original[1].object_id }
32
+ it { subject[1][1].object_id.should_not == original[1][1].object_id }
33
+ it { subject[1][2].object_id.should_not == original[1][2].object_id }
34
+ it { subject[1][2][:e].object_id.should_not == original[1][2][:e].object_id }
35
+ it { subject[1][2][:e][:f].object_id.should_not == original[1][2][:e][:f].object_id }
36
+ it { subject[1][2][:e][:i].object_id.should_not == original[1][2][:e][:i].object_id }
37
+ end
38
+
39
+ context "Hash#deep_dupがない場合" do
40
+ before do
41
+ if Hash.instance_methods.include?(:deep_dup)
42
+ Hash.class_eval do
43
+ remove_method(:deep_dup)
44
+ end
45
+ end
46
+ end
47
+ after do
48
+ load("tengine/support/core_ext/hash/deep_dup.rb")
49
+ end
50
+
51
+ subject{ original.deep_dup }
52
+ it { subject.should == original }
53
+ it { subject.object_id.should_not == original.object_id }
54
+ it { subject[1].object_id.should_not == original[1].object_id }
55
+ it { subject[1][1].object_id.should_not == original[1][1].object_id }
56
+ it { subject[1][2].object_id.should == original[1][2].object_id }
57
+ it { subject[1][2][:e].object_id.should == original[1][2][:e].object_id }
58
+ it { subject[1][2][:e][:f].object_id.should == original[1][2][:e][:f].object_id }
59
+ it { subject[1][2][:e][:i].object_id.should == original[1][2][:e][:i].object_id }
60
+ end
61
+
62
+ end
@@ -0,0 +1,59 @@
1
+ # -*- coding: utf-8 -*-
2
+ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
3
+
4
+ require 'active_support'
5
+ require "tengine/support/core_ext/hash/deep_dup"
6
+
7
+ describe "tengine/support/core_ext/hash/deep_dup" do
8
+
9
+ original = {
10
+ :a => {
11
+ :b => {
12
+ :c => :d
13
+ }.freeze,
14
+ :e => [
15
+ :f,
16
+ {:g => :h}.freeze,
17
+ [:i, :j].freeze
18
+ ].freeze
19
+ }.freeze
20
+ }.freeze
21
+
22
+ context "Array#deep_dupがある場合" do
23
+ before do
24
+ load("tengine/support/core_ext/array/deep_dup.rb")
25
+ end
26
+
27
+ subject{ original.deep_dup }
28
+ it { subject.should == original }
29
+ it { subject.object_id.should_not == original.object_id }
30
+ it { subject[:a].object_id.should_not == original[:a].object_id }
31
+ it { subject[:a][:b].object_id.should_not == original[:a][:b].object_id }
32
+ it { subject[:a][:e].object_id.should_not == original[:a][:e].object_id }
33
+ it { subject[:a][:e][1].object_id.should_not == original[:a][:e][1].object_id }
34
+ it { subject[:a][:e][2].object_id.should_not == original[:a][:e][2].object_id }
35
+ end
36
+
37
+ context "Array#deep_dupがない場合" do
38
+ before do
39
+ if Array.instance_methods.include?(:deep_dup)
40
+ Array.class_eval do
41
+ remove_method(:deep_dup)
42
+ end
43
+ end
44
+ end
45
+ after do
46
+ load("tengine/support/core_ext/array/deep_dup.rb")
47
+ end
48
+
49
+ subject{ original.deep_dup }
50
+ it { subject.should == original }
51
+ it { subject.object_id.should_not == original.object_id }
52
+ it { subject[:a].object_id.should_not == original[:a].object_id }
53
+ it { subject[:a][:b].object_id.should_not == original[:a][:b].object_id }
54
+ it { subject[:a][:e].object_id.should == original[:a][:e].object_id }
55
+ it { subject[:a][:e][1].object_id.should == original[:a][:e][1].object_id }
56
+ it { subject[:a][:e][2].object_id.should == original[:a][:e][2].object_id }
57
+ end
58
+
59
+ end
@@ -3,76 +3,67 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
3
3
 
4
4
  require 'active_support'
5
5
 
6
- # この機能は、activesupport-3.1.0から追加された active_support/core_ext/hash/deep_dup
7
- # 使っているので、3.1.0以下ではテストせず、pendingのメッセージを出します
8
- if ActiveSupport::VERSION::STRING < "3.1.0"
9
- describe "tengine/support/core_ext/hash/keys" do
10
- pending %W[
11
- depends on active_support/core_ext/hash/deep_dup,
12
- but activesupport version is #{ActiveSupport::VERSION::STRING}.
13
- If you need to use Hash#deep_stringify_keys and Hash#deep_symbolize_keys,
14
- install tengine_support with activesupport >= 3.1.0.
15
- ].join(' ')
16
- end
17
- else
18
- require 'active_support/core_ext/hash/deep_dup'
19
- require 'tengine/support/core_ext/hash/keys'
6
+ require 'tengine/support/core_ext/array/deep_dup'
7
+ require 'tengine/support/core_ext/hash/keys'
20
8
 
21
- describe "tengine/support/core_ext/hash/keys" do
9
+ describe "tengine/support/core_ext/hash/keys" do
22
10
 
23
- test_hashs ={
24
- :deep_stringify_keys_result => {
25
- 'a' => 1,
26
- 'b' => {
27
- 'foo' => 2,
28
- 'bar' => {
29
- 'hoge' => "3",
30
- "wake" => {}.freeze,
31
- }.freeze
32
- }.freeze,
33
- 'c' => {
34
- 'baz' => "4"
11
+ test_hashs ={
12
+ :deep_stringify_keys_result => {
13
+ 'a' => 1,
14
+ 'b' => {
15
+ 'foo' => 2,
16
+ 'bar' => {
17
+ 'hoge' => "3",
18
+ "wake" => {}.freeze,
35
19
  }.freeze
36
20
  }.freeze,
21
+ 'c' => [
22
+ { 'baz' => "4" }.freeze,
23
+ { 'blah' => "5" }.freeze,
24
+ ]
25
+ }.freeze,
37
26
 
38
- :deep_symbolize_keys_result => {
39
- :a => 1,
40
- :b => {
41
- :foo => 2,
42
- :bar => {
43
- :hoge => "3",
44
- :wake => {}.freeze,
45
- }.freeze
46
- }.freeze,
47
- :c => {
48
- :baz => "4"
27
+ :deep_symbolize_keys_result => {
28
+ :a => 1,
29
+ :b => {
30
+ :foo => 2,
31
+ :bar => {
32
+ :hoge => "3",
33
+ :wake => {}.freeze,
49
34
  }.freeze
50
35
  }.freeze,
36
+ :c => [
37
+ { :baz => "4" }.freeze,
38
+ { :blah => "5" }.freeze,
39
+ ]
40
+ }.freeze,
51
41
 
52
- :mixed_key_hash => {
53
- 'a' => 1,
54
- :b => {
55
- :foo => 2,
56
- 'bar' => {
57
- 'hoge' => "3",
58
- :wake => {}.freeze,
59
- }.freeze
60
- }.freeze,
61
- :c => {
62
- 'baz' => "4"
42
+ :mixed_key_hash => {
43
+ 'a' => 1,
44
+ :b => {
45
+ :foo => 2,
46
+ 'bar' => {
47
+ 'hoge' => "3",
48
+ :wake => {}.freeze,
63
49
  }.freeze
64
- }.freeze
65
- }
50
+ }.freeze,
51
+ :c => [
52
+ { 'baz' => "4" }.freeze,
53
+ { :blah => "5" }.freeze,
54
+ ]
55
+ }.freeze
56
+ }
66
57
 
67
- [:deep_stringify_keys, :deep_symbolize_keys].each do |method_name|
68
- test_hashs.keys.each do |target_name|
69
- context target_name do
70
- describe ".#{method_name}" do
71
- it "should returns #{method_name}_result" do
72
- original = test_hashs[target_name]
73
- converted = original.send(method_name)
74
- converted.object_id.should_not == original.object_id # object_id is changed
75
- converted.should == test_hashs[:"#{method_name}_result"]
58
+ [:deep_stringify_keys, :deep_symbolize_keys].each do |method_name|
59
+ test_hashs.keys.each do |target_name|
60
+ context target_name do
61
+ describe ".#{method_name}" do
62
+ it "should returns #{method_name}_result" do
63
+ original = test_hashs[target_name]
64
+ converted = original.send(method_name)
65
+ converted.object_id.should_not == original.object_id # object_id is changed
66
+ converted.should == test_hashs[:"#{method_name}_result"]
76
67
  original.should == test_hashs[target_name]
77
68
  end
78
69
  end
@@ -95,4 +86,3 @@ else
95
86
  end
96
87
 
97
88
  end
98
- end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tengine_support
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.14
4
+ version: 0.3.15
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -24,7 +24,7 @@ date: 2011-11-21 00:00:00.000000000Z
24
24
  dependencies:
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: activesupport
27
- requirement: &2155256840 !ruby/object:Gem::Requirement
27
+ requirement: &2167471060 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 3.0.0
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *2155256840
35
+ version_requirements: *2167471060
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec
38
- requirement: &2155256280 !ruby/object:Gem::Requirement
38
+ requirement: &2167470540 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 2.6.0
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *2155256280
46
+ version_requirements: *2167470540
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: yard
49
- requirement: &2155255800 !ruby/object:Gem::Requirement
49
+ requirement: &2167469940 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 0.7.2
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *2155255800
57
+ version_requirements: *2167469940
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: bundler
60
- requirement: &2155255300 !ruby/object:Gem::Requirement
60
+ requirement: &2167469400 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 1.0.18
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *2155255300
68
+ version_requirements: *2167469400
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: jeweler
71
- requirement: &2155254800 !ruby/object:Gem::Requirement
71
+ requirement: &2167468880 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ~>
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: 1.6.4
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *2155254800
79
+ version_requirements: *2167468880
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: simplecov
82
- requirement: &2155254320 !ruby/object:Gem::Requirement
82
+ requirement: &2167468400 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ~>
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: 0.5.3
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *2155254320
90
+ version_requirements: *2167468400
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: autotest
93
- requirement: &2155253840 !ruby/object:Gem::Requirement
93
+ requirement: &2167467800 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ! '>='
@@ -98,10 +98,10 @@ dependencies:
98
98
  version: '0'
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *2155253840
101
+ version_requirements: *2167467800
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: rdiscount
104
- requirement: &2155253360 !ruby/object:Gem::Requirement
104
+ requirement: &2167467300 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - ! '>='
@@ -109,7 +109,7 @@ dependencies:
109
109
  version: '0'
110
110
  type: :development
111
111
  prerelease: false
112
- version_requirements: *2155253360
112
+ version_requirements: *2167467300
113
113
  description: tengine_support provides utility classes/modules which is not included
114
114
  in active_support. It doesn't depend on other tengine gems.
115
115
  email: tengine@nautilus-technologies.com
@@ -140,7 +140,10 @@ files:
140
140
  - lib/tengine/support/config/logger.rb
141
141
  - lib/tengine/support/config/mongoid.rb
142
142
  - lib/tengine/support/core_ext.rb
143
+ - lib/tengine/support/core_ext/array.rb
144
+ - lib/tengine/support/core_ext/array/deep_dup.rb
143
145
  - lib/tengine/support/core_ext/hash.rb
146
+ - lib/tengine/support/core_ext/hash/deep_dup.rb
144
147
  - lib/tengine/support/core_ext/hash/keys.rb
145
148
  - lib/tengine/support/null_logger.rb
146
149
  - lib/tengine/support/yaml_with_erb.rb
@@ -158,6 +161,8 @@ files:
158
161
  - spec/tengine_support/config_spec/load_spec_01.yml.erb
159
162
  - spec/tengine_support/config_spec/load_spec_02.yml.erb
160
163
  - spec/tengine_support/config_spec/parse_spec.rb
164
+ - spec/tengine_support/core_ext/array/deep_dup_spec.rb
165
+ - spec/tengine_support/core_ext/hash/deep_dup_spec.rb
161
166
  - spec/tengine_support/core_ext/hash/keys_spec.rb
162
167
  - spec/tengine_support/null_logger_spec.rb
163
168
  - spec/tengine_support/yaml_with_erb_spec.rb
@@ -181,7 +186,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
181
186
  version: '0'
182
187
  segments:
183
188
  - 0
184
- hash: -4314659835284975712
189
+ hash: -839430569768029966
185
190
  required_rubygems_version: !ruby/object:Gem::Requirement
186
191
  none: false
187
192
  requirements: