padrino-support 0.13.2 → 0.13.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 98254f4842554e96dd0accf958ab629966ae8484
4
- data.tar.gz: 508e6954fe00f2856c9ff99a45cc3ae06d1a67d4
3
+ metadata.gz: 0c88111ca420a5a95a8bf0c0c7ebd212e89859c3
4
+ data.tar.gz: 7a2a53a88f1b373f81d25a3d63593d49eb8a6a42
5
5
  SHA512:
6
- metadata.gz: b35602c73202904b25577d8944e960a2f0835802c8499488cfb42f7853009abae55131750734eed24e318b2401b910411f6f6f23b0bd3f8c1c81923827286758
7
- data.tar.gz: e1d56e38387badce7ba88c35f3dcbf2fa28a0641294844fa5fc7c5b76278ea8c274efa55cb13622fca561adbc8f5dc0e641f405d77b5696fe0eed005366e8a42
6
+ metadata.gz: 4f220b1467a288e99dc3cc80885888fe835d62e5890848b846685b1e328dfae63033f001308493baf1007cd1ca55cdbdd818d20cd75a25131b3b31ea9d2d42d0
7
+ data.tar.gz: bb7284c6acdd5cfea0148fe0bde3bd67a2b445eef9e8159f661001b7ac9e194c8541adf3b8d4ed512956dc5092c1a126c4393ff084f28d65ebd03f7c46dd3b69
@@ -99,8 +99,14 @@ class String
99
99
  ##
100
100
  # Capitalizes the first word, turns underscores into spaces, and strips a trailing '_id' if present.
101
101
  #
102
- def humanize(options = {})
103
- ActiveSupport::Inflector.humanize(self, options)
102
+ if ActiveSupport::Inflector.method(:humanize).arity == 1
103
+ def humanize
104
+ ActiveSupport::Inflector.humanize(self)
105
+ end
106
+ else
107
+ def humanize(options = {})
108
+ ActiveSupport::Inflector.humanize(self, options)
109
+ end
104
110
  end
105
111
 
106
112
  ##
@@ -31,5 +31,27 @@ module Padrino
31
31
  "#{CGI.escape(namespace.to_s)}=#{CGI.escape(object.to_s)}"
32
32
  end
33
33
  end
34
+
35
+ ##
36
+ # Recursively duplicates the passed object.
37
+ #
38
+ def deep_dup(object)
39
+ case object
40
+ when Array
41
+ object.map{ |value| deep_dup(value) }
42
+ when Hash
43
+ object.each_with_object(object.dup.clear) do |(key, value), new_hash|
44
+ new_hash[deep_dup(key)] = deep_dup(value)
45
+ end
46
+ when NilClass, FalseClass, TrueClass, Symbol, Numeric, Method
47
+ object
48
+ else
49
+ begin
50
+ object.dup
51
+ rescue TypeError
52
+ object
53
+ end
54
+ end
55
+ end
34
56
  end
35
57
  end
@@ -3,14 +3,20 @@
3
3
  #
4
4
  require 'active_support/core_ext/hash/keys' # symbolize_keys
5
5
  require 'active_support/core_ext/hash/indifferent_access' # params[:foo]
6
- require 'active_support/core_ext/hash/slice' # slice
7
- require 'active_support/core_ext/array/extract_options' # Array#extract_options!
8
6
  require 'active_support/core_ext/object/blank' # present?
9
7
  require 'active_support/core_ext/string/output_safety' # SafeBuffer and html_safe
10
8
 
11
9
  # Remove these on 0.14:
12
10
  require 'active_support/core_ext/hash/reverse_merge' # reverse_merge
13
11
  require 'active_support/core_ext/module/aliasing' # alias_method_chain
12
+ require 'active_support/core_ext/array/extract_options' # Array#extract_options!
13
+ require 'active_support/core_ext/hash/slice' # slice
14
+ begin
15
+ require 'active_support/core_ext/object/deep_dup' # AS 4.1
16
+ rescue LoadError
17
+ require 'active_support/core_ext/hash/deep_dup' # AS >= 3.1
18
+ end
19
+
14
20
 
15
21
  require 'padrino-support/core_ext/string/inflections'
16
22
  require 'padrino-support/core_ext/string/colorize'
data/test/test_utils.rb CHANGED
@@ -57,3 +57,58 @@ describe 'Padrino::Utils.build_uri_query' do
57
57
  'user'
58
58
  end
59
59
  end
60
+
61
+ describe 'Padrino::Utils.deep_dup' do
62
+ it 'should recursively dup array' do
63
+ array = [1, [2, 3]]
64
+ dup = Padrino::Utils.deep_dup(array)
65
+ dup[1][2] = 4
66
+ assert_equal nil, array[1][2]
67
+ assert_equal 4, dup[1][2]
68
+ end
69
+
70
+ it 'should recursively dup hash' do
71
+ hash = { :a => { :b => 'b' } }
72
+ dup = Padrino::Utils.deep_dup(hash)
73
+ dup[:a][:c] = 'c'
74
+ assert_equal nil, hash[:a][:c]
75
+ assert_equal 'c', dup[:a][:c]
76
+ end
77
+
78
+ it 'should recursively dup array with hash' do
79
+ array = [1, { :a => 2, :b => 3 } ]
80
+ dup = Padrino::Utils.deep_dup(array)
81
+ dup[1][:c] = 4
82
+ assert_equal nil, array[1][:c]
83
+ assert_equal 4, dup[1][:c]
84
+ end
85
+
86
+ it 'should recursively dup hash with array' do
87
+ hash = { :a => [1, 2] }
88
+ dup = Padrino::Utils.deep_dup(hash)
89
+ dup[:a][2] = 'c'
90
+ assert_equal nil, hash[:a][2]
91
+ assert_equal 'c', dup[:a][2]
92
+ end
93
+
94
+ it 'should dup initial hash values' do
95
+ zero_hash = Hash.new 0
96
+ hash = { :a => zero_hash }
97
+ dup = Padrino::Utils.deep_dup(hash)
98
+ assert_equal 0, dup[:a][44]
99
+ end
100
+
101
+ it 'should properly dup objects' do
102
+ object = Object.new
103
+ dup = Padrino::Utils.deep_dup(object)
104
+ dup.instance_variable_set(:@a, 1)
105
+ assert !object.instance_variable_defined?(:@a)
106
+ assert dup.instance_variable_defined?(:@a)
107
+ end
108
+
109
+ it 'should not double the frozen keys' do
110
+ hash = { Fixnum => 1 }
111
+ dup = Padrino::Utils.deep_dup(hash)
112
+ assert_equal 1, dup.keys.length
113
+ end
114
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: padrino-support
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.2
4
+ version: 0.13.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Padrino Team
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2016-05-09 00:00:00.000000000 Z
15
+ date: 2016-08-17 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: activesupport
@@ -69,7 +69,6 @@ files:
69
69
  - padrino-support.gemspec
70
70
  - test/helper.rb
71
71
  - test/test_colorize.rb
72
- - test/test_support_lite.rb
73
72
  - test/test_utils.rb
74
73
  homepage: http://www.padrinorb.com
75
74
  licenses:
@@ -92,13 +91,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
92
91
  version: 1.3.6
93
92
  requirements: []
94
93
  rubyforge_project: padrino-support
95
- rubygems_version: 2.4.8
94
+ rubygems_version: 2.6.4
96
95
  signing_key:
97
96
  specification_version: 4
98
97
  summary: Support for padrino
99
- test_files:
100
- - test/helper.rb
101
- - test/test_colorize.rb
102
- - test/test_support_lite.rb
103
- - test/test_utils.rb
104
- has_rdoc:
98
+ test_files: []
@@ -1,50 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/helper')
2
-
3
- describe "ObjectSpace" do
4
- describe "#classes" do
5
- it 'should take an snapshot of the current loaded classes' do
6
- snapshot = ObjectSpace.classes
7
- assert_equal snapshot.include?(Padrino::Logger), true
8
- end
9
-
10
- it 'should return a Set object' do
11
- snapshot = ObjectSpace.classes
12
- assert_equal snapshot.kind_of?(Set), true
13
- end
14
-
15
- it 'should be able to process a the class name given a block' do
16
- klasses = ObjectSpace.classes do |klass|
17
- if klass.name =~ /^Padrino::/
18
- klass
19
- end
20
- end
21
-
22
- assert_equal (klasses.size > 1), true
23
- klasses.each do |klass|
24
- assert_match /^Padrino::/, klass.to_s
25
- end
26
- end
27
- end
28
-
29
- describe "#new_classes" do
30
- before do
31
- @snapshot = ObjectSpace.classes
32
- end
33
-
34
- it 'should return list of new classes' do
35
- class OSTest; end
36
- module OSTestModule; class B; end; end
37
-
38
- new_classes = ObjectSpace.new_classes(@snapshot)
39
-
40
- assert_equal new_classes.size, 2
41
- assert_equal new_classes.include?(OSTest), true
42
- assert_equal new_classes.include?(OSTestModule::B), true
43
- end
44
-
45
- it 'should return a Set object' do
46
- new_classes = ObjectSpace.new_classes(@snapshot)
47
- assert_equal new_classes.kind_of?(Set), true
48
- end
49
- end
50
- end