padrino-support 0.12.8.1 → 0.12.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,15 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 7d4c38bd1047d192488330f5631043350e67fd79
4
- data.tar.gz: 0cc09985afeba92a48f168042a722cdf974bd6ba
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZGY3ODIwZjBhNGE0NzYxMzg4ZmY3NTg2NTMxNzk0NzA3ZjE1YzU3OQ==
5
+ data.tar.gz: !binary |-
6
+ YzJmMGZjMGVjMTkyZDExMTdjMGU0MzgxMWY5MTk0MTRiYzBmYTAwMg==
5
7
  SHA512:
6
- metadata.gz: 1f8011e19c55265eb317e0a4b2049300a59fc8e0854fec51544b3d6bcc122fb951e064821680421cb4f6a137333522b4a82b508687e303cbd644a6e12b0802ad
7
- data.tar.gz: 1f773e5a7f31f237ba6d972ee5fff31977b68e09b805fd276fa784a5ca26996a9440de81d49c4e3f3ef2dd8470be441f1bc0fed2eb32476600b3cfb904f7ba6c
8
+ metadata.gz: !binary |-
9
+ MzM0ZWRmMjU0OTY3NTlmNzYyODgzZGY0YjU2OWU3NTIwY2JhMWRhMWI5NGFk
10
+ YWExMzAzZmJkYjBjMWM0MmNjMjExMjFiNGRlZGRlOTM5ZDRlYjM4MTZkYjlk
11
+ NDEzZmMyNzFjNTEzZjI0Nzc2NDRjNWZiZGUxYjNkMmE2MDM4NTg=
12
+ data.tar.gz: !binary |-
13
+ Njk2ZWIzMmFhODAxYjk4MTI2MmViMWE4YzY3ODNhNzg1YzU5OGViZTE2ODVj
14
+ YzA3OTE5ZGYxNGY0MTQwNDk2MTBhMDE1Y2UxMzFiYWQxODliOGZiZDlhYmE1
15
+ NTFmZWViZGQ1NTdiODEzZDE0MDM2OGNhZTFlMmQxYjhkN2RkYWE=
data/Rakefile CHANGED
@@ -1,5 +1 @@
1
- # coding:utf-8
2
- RAKE_ROOT = __FILE__
3
-
4
- require 'rubygems'
5
1
  require File.expand_path(File.dirname(__FILE__) + '/../gem_rake_helper')
@@ -11,21 +11,10 @@ module ObjectSpace
11
11
  # end
12
12
  # end
13
13
  #
14
- def classes
15
- rs = Set.new
16
-
17
- ObjectSpace.each_object(Class).each do |klass|
18
- if block_given?
19
- if r = yield(klass)
20
- # add the returned value if the block returns something
21
- rs << r
22
- end
23
- else
24
- rs << klass
25
- end
26
- end
27
-
28
- rs
14
+ def classes(&block)
15
+ warn 'Warning! ObjectSpace.classes will be removed in Padrino 0.14'
16
+ require 'padrino-core/reloader'
17
+ Padrino::Reloader::Storage.send(:object_classes, &block)
29
18
  end
30
19
 
31
20
  ##
@@ -39,11 +28,9 @@ module ObjectSpace
39
28
  # ObjectSpace.new_classes(snapshot)
40
29
  #
41
30
  def new_classes(snapshot)
42
- self.classes do |klass|
43
- if !snapshot.include?(klass)
44
- klass
45
- end
46
- end
31
+ warn 'Warning! ObjectSpace.new_classes will be removed in Padrino 0.14'
32
+ require 'padrino-core/reloader'
33
+ Padrino::Reloader::Storage.send(:new_classes, snapshot)
47
34
  end
48
35
  end
49
36
  end
@@ -4,7 +4,7 @@ de:
4
4
  # Benutze die strftime Parameter für die Formatierung
5
5
  # Wenn keine Formate angegeben werden, wird "default" benutzt.
6
6
  # Du kannst auch weitere Formate hinzufügen, wenn Du möchtest.
7
- default: "&d.&m.%Y"
7
+ default: "%d.%m.%Y"
8
8
  short: "%d. %b"
9
9
  long: "%d. %B %Y"
10
10
  only_day: "%e"
@@ -0,0 +1,57 @@
1
+ require 'cgi'
2
+
3
+ module Padrino
4
+ module Utils
5
+ extend self
6
+
7
+ ##
8
+ # Builds an URI query from a Hash or any Object.
9
+ #
10
+ # Examples (~ marks here that output is actually escaped by CGI):
11
+ #
12
+ # Utils.build_uri_query(:a => 1, :b => 2) #=> "a=1&b=2"
13
+ # Utils.build_uri_query(:a => [1, 2]) #=> ~"a[]=1&a[]=2"
14
+ # Utils.build_uri_query([1, 2], 'namespace') #=> ~"namespace[]=1&namespace[]=2"
15
+ # Utils.build_uri_query(:a => { :d => 2 }, :b => 3) #=> ~"a[d]=2&b=3"
16
+ #
17
+ def build_uri_query(object, namespace = nil)
18
+ case object
19
+ when Hash
20
+ object.map do |key, value|
21
+ next if value == {} || value == []
22
+ build_uri_query(value, namespace ? "#{namespace}[#{key}]" : key)
23
+ end.compact.join('&')
24
+ when Array
25
+ fail ArgumentError, 'namespace is missing' unless namespace
26
+ (object.empty? ? [''] : object).map do |value|
27
+ build_uri_query(value, "#{namespace}[]")
28
+ end.join('&')
29
+ else
30
+ fail ArgumentError, 'namespace is missing' unless namespace
31
+ "#{CGI.escape(namespace.to_s)}=#{CGI.escape(object.to_s)}"
32
+ end
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
56
+ end
57
+ end
@@ -1,7 +1,6 @@
1
1
  ##
2
2
  # This file loads certain extensions required by Padrino from ActiveSupport.
3
3
  #
4
- require 'active_support/core_ext/module/aliasing' # alias_method_chain
5
4
  require 'active_support/core_ext/hash/reverse_merge' # reverse_merge
6
5
  require 'active_support/core_ext/hash/keys' # symbolize_keys
7
6
  require 'active_support/core_ext/hash/indifferent_access' # params[:foo]
@@ -12,9 +11,9 @@ require 'active_support/core_ext/string/output_safety' # SafeBuffer and htm
12
11
 
13
12
  require 'padrino-support/core_ext/string/inflections'
14
13
  require 'padrino-support/core_ext/string/colorize'
15
- require 'padrino-support/core_ext/string/undent' # deprecated
16
14
  require 'padrino-support/core_ext/object_space'
17
15
  require 'padrino-support/file_set'
16
+ require 'padrino-support/utils'
18
17
 
19
18
 
20
19
  ##
data/test/helper.rb CHANGED
@@ -1,7 +1,6 @@
1
1
  ENV['RACK_ENV'] = 'test'
2
2
  PADRINO_ROOT = File.dirname(__FILE__) unless defined?(PADRINO_ROOT)
3
3
 
4
- require File.expand_path('../../../load_paths', __FILE__)
5
4
  require 'minitest/autorun'
6
5
  require 'minitest/pride'
7
6
  require 'padrino-support'
@@ -0,0 +1,114 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/helper')
2
+
3
+ class MiniTest::Spec
4
+ def assert_query_equal(expected, actual, namespace=nil)
5
+ assert_equal expected.split('&').sort, Padrino::Utils.build_uri_query(actual, namespace).split('&').sort
6
+ end
7
+ end
8
+
9
+ describe 'Padrino::Utils.build_uri_query' do
10
+ it 'should do simple conversion' do
11
+ assert_query_equal 'a=10', :a => 10
12
+ end
13
+
14
+ it 'should do cgi escaping' do
15
+ assert_query_equal 'a%3Ab=c+d', 'a:b' => 'c d'
16
+ end
17
+
18
+ it 'should expand nested hashes' do
19
+ assert_query_equal 'person%5Blogin%5D=seckar&person%5Bname%5D=Nicholas',
20
+ :person => { :login => 'seckar', :name => 'Nicholas' }
21
+ end
22
+
23
+ it 'should expand deeply nested hashes' do
24
+ assert_query_equal 'account%5Bperson%5D%5Bid%5D=20&person%5Bid%5D=10',
25
+ { :account => { :person => { :id => 20 } }, :person => {:id => 10} }
26
+ end
27
+
28
+ it 'should accept arrays' do
29
+ assert_query_equal 'person%5Bid%5D%5B%5D=10&person%5Bid%5D%5B%5D=20',
30
+ :person => {:id => [10, 20]}
31
+ end
32
+
33
+ it 'should accept empty arrays' do
34
+ assert_query_equal "person%5B%5D=",
35
+ [],
36
+ 'person'
37
+ end
38
+
39
+ it 'should expand nested hashes' do
40
+ assert_query_equal '',
41
+ {}
42
+ assert_query_equal 'a=1&b%5Bc%5D=3',
43
+ { a: 1, b: { c: 3, d: {} } }
44
+ assert_query_equal '',
45
+ { a: {b: {c: {}}} }
46
+ assert_query_equal 'b%5Bc%5D=false&b%5Be%5D=&b%5Bf%5D=&p=12',
47
+ { p: 12, b: { c: false, e: nil, f: '' } }
48
+ assert_query_equal 'b%5Bc%5D=3&b%5Bf%5D=',
49
+ { b: { c: 3, k: {}, f: '' } }
50
+ assert_query_equal 'b=3',
51
+ {a: [], b: 3}
52
+ end
53
+
54
+ it 'should accept namespace for hashes' do
55
+ assert_query_equal "user%5Bname%5D=Nakshay&user%5Bnationality%5D=Indian",
56
+ { name: 'Nakshay', nationality: 'Indian' },
57
+ 'user'
58
+ end
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.12.8.1
4
+ version: 0.12.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Padrino Team
@@ -12,31 +12,33 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2016-09-06 00:00:00.000000000 Z
15
+ date: 2018-02-23 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: activesupport
19
19
  requirement: !ruby/object:Gem::Requirement
20
20
  requirements:
21
- - - ">="
21
+ - - ! '>='
22
22
  - !ruby/object:Gem::Version
23
- version: '3.1'
23
+ version: !binary |-
24
+ My4x
24
25
  type: :runtime
25
26
  prerelease: false
26
27
  version_requirements: !ruby/object:Gem::Requirement
27
28
  requirements:
28
- - - ">="
29
+ - - ! '>='
29
30
  - !ruby/object:Gem::Version
30
- version: '3.1'
31
+ version: !binary |-
32
+ My4x
31
33
  description: A number of support methods and extensions for Padrino framework
32
34
  email: padrinorb@gmail.com
33
35
  executables: []
34
36
  extensions: []
35
37
  extra_rdoc_files: []
36
38
  files:
37
- - ".document"
38
- - ".gitignore"
39
- - ".yardopts"
39
+ - .document
40
+ - .gitignore
41
+ - .yardopts
40
42
  - LICENSE.txt
41
43
  - Rakefile
42
44
  - lib/padrino-support.rb
@@ -66,32 +68,33 @@ files:
66
68
  - lib/padrino-support/locale/uk.yml
67
69
  - lib/padrino-support/locale/zh_cn.yml
68
70
  - lib/padrino-support/locale/zh_tw.yml
71
+ - lib/padrino-support/utils.rb
69
72
  - padrino-support.gemspec
70
73
  - test/helper.rb
71
74
  - test/test_colorize.rb
72
- - test/test_support_lite.rb
75
+ - test/test_utils.rb
73
76
  homepage: http://www.padrinorb.com
74
77
  licenses:
75
78
  - MIT
76
79
  metadata: {}
77
80
  post_install_message:
78
81
  rdoc_options:
79
- - "--charset=UTF-8"
82
+ - --charset=UTF-8
80
83
  require_paths:
81
84
  - lib
82
85
  required_ruby_version: !ruby/object:Gem::Requirement
83
86
  requirements:
84
- - - ">="
87
+ - - ! '>='
85
88
  - !ruby/object:Gem::Version
86
89
  version: '0'
87
90
  required_rubygems_version: !ruby/object:Gem::Requirement
88
91
  requirements:
89
- - - ">="
92
+ - - ! '>='
90
93
  - !ruby/object:Gem::Version
91
94
  version: 1.3.6
92
95
  requirements: []
93
96
  rubyforge_project: padrino-support
94
- rubygems_version: 2.5.1
97
+ rubygems_version: 2.6.14
95
98
  signing_key:
96
99
  specification_version: 4
97
100
  summary: Support for padrino
@@ -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