padrino-support 0.12.9 → 0.13.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- ZGY3ODIwZjBhNGE0NzYxMzg4ZmY3NTg2NTMxNzk0NzA3ZjE1YzU3OQ==
5
- data.tar.gz: !binary |-
6
- YzJmMGZjMGVjMTkyZDExMTdjMGU0MzgxMWY5MTk0MTRiYzBmYTAwMg==
2
+ SHA1:
3
+ metadata.gz: 9da6927993084641e92a81874b6a571ab8ff46a2
4
+ data.tar.gz: 0b8c80b666d7f1586ceb9de720a3ff071677d52b
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- MzM0ZWRmMjU0OTY3NTlmNzYyODgzZGY0YjU2OWU3NTIwY2JhMWRhMWI5NGFk
10
- YWExMzAzZmJkYjBjMWM0MmNjMjExMjFiNGRlZGRlOTM5ZDRlYjM4MTZkYjlk
11
- NDEzZmMyNzFjNTEzZjI0Nzc2NDRjNWZiZGUxYjNkMmE2MDM4NTg=
12
- data.tar.gz: !binary |-
13
- Njk2ZWIzMmFhODAxYjk4MTI2MmViMWE4YzY3ODNhNzg1YzU5OGViZTE2ODVj
14
- YzA3OTE5ZGYxNGY0MTQwNDk2MTBhMDE1Y2UxMzFiYWQxODliOGZiZDlhYmE1
15
- NTFmZWViZGQ1NTdiODEzZDE0MDM2OGNhZTFlMmQxYjhkN2RkYWE=
6
+ metadata.gz: ec043e200f7a73bf4ee06a109af9e80eca022f5fc65ed180abaae2b7f811c37d87811e28b7bc855d5bc381ec775ebbe7c66f8422180be5307a801c32c8574bf1
7
+ data.tar.gz: 5323aca9c9a6baa6c64f8908274a61dc702c476e923ee784b7174ffb64be3496ef9fba41c84b15463cdab6211a05848ad5b04427f40481465810e54e40274e63
@@ -11,10 +11,21 @@ module ObjectSpace
11
11
  # end
12
12
  # end
13
13
  #
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)
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
18
29
  end
19
30
 
20
31
  ##
@@ -28,9 +39,11 @@ module ObjectSpace
28
39
  # ObjectSpace.new_classes(snapshot)
29
40
  #
30
41
  def new_classes(snapshot)
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)
42
+ self.classes do |klass|
43
+ if !snapshot.include?(klass)
44
+ klass
45
+ end
46
+ end
34
47
  end
35
48
  end
36
49
  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"
@@ -1,6 +1,7 @@
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
4
5
  require 'active_support/core_ext/hash/reverse_merge' # reverse_merge
5
6
  require 'active_support/core_ext/hash/keys' # symbolize_keys
6
7
  require 'active_support/core_ext/hash/indifferent_access' # params[:foo]
@@ -13,7 +14,6 @@ require 'padrino-support/core_ext/string/inflections'
13
14
  require 'padrino-support/core_ext/string/colorize'
14
15
  require 'padrino-support/core_ext/object_space'
15
16
  require 'padrino-support/file_set'
16
- require 'padrino-support/utils'
17
17
 
18
18
 
19
19
  ##
@@ -29,5 +29,5 @@ end
29
29
  # In reloader for accessing class_name Foo._orig_klass_name
30
30
  #
31
31
  class Module
32
- alias :_orig_klass_name :name
32
+ alias :_orig_klass_name :to_s
33
33
  end
@@ -0,0 +1,50 @@
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
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.9
4
+ version: 0.13.0.beta1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Padrino Team
@@ -12,24 +12,22 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2018-02-23 00:00:00.000000000 Z
15
+ date: 2015-02-22 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: !binary |-
24
- My4x
23
+ version: '3.1'
25
24
  type: :runtime
26
25
  prerelease: false
27
26
  version_requirements: !ruby/object:Gem::Requirement
28
27
  requirements:
29
- - - ! '>='
28
+ - - '>='
30
29
  - !ruby/object:Gem::Version
31
- version: !binary |-
32
- My4x
30
+ version: '3.1'
33
31
  description: A number of support methods and extensions for Padrino framework
34
32
  email: padrinorb@gmail.com
35
33
  executables: []
@@ -45,7 +43,6 @@ files:
45
43
  - lib/padrino-support/core_ext/object_space.rb
46
44
  - lib/padrino-support/core_ext/string/colorize.rb
47
45
  - lib/padrino-support/core_ext/string/inflections.rb
48
- - lib/padrino-support/core_ext/string/undent.rb
49
46
  - lib/padrino-support/file_set.rb
50
47
  - lib/padrino-support/locale/cs.yml
51
48
  - lib/padrino-support/locale/da.yml
@@ -68,11 +65,10 @@ files:
68
65
  - lib/padrino-support/locale/uk.yml
69
66
  - lib/padrino-support/locale/zh_cn.yml
70
67
  - lib/padrino-support/locale/zh_tw.yml
71
- - lib/padrino-support/utils.rb
72
68
  - padrino-support.gemspec
73
69
  - test/helper.rb
74
70
  - test/test_colorize.rb
75
- - test/test_utils.rb
71
+ - test/test_support_lite.rb
76
72
  homepage: http://www.padrinorb.com
77
73
  licenses:
78
74
  - MIT
@@ -84,18 +80,22 @@ require_paths:
84
80
  - lib
85
81
  required_ruby_version: !ruby/object:Gem::Requirement
86
82
  requirements:
87
- - - ! '>='
83
+ - - '>='
88
84
  - !ruby/object:Gem::Version
89
85
  version: '0'
90
86
  required_rubygems_version: !ruby/object:Gem::Requirement
91
87
  requirements:
92
- - - ! '>='
88
+ - - '>'
93
89
  - !ruby/object:Gem::Version
94
- version: 1.3.6
90
+ version: 1.3.1
95
91
  requirements: []
96
92
  rubyforge_project: padrino-support
97
- rubygems_version: 2.6.14
93
+ rubygems_version: 2.0.6
98
94
  signing_key:
99
95
  specification_version: 4
100
96
  summary: Support for padrino
101
- test_files: []
97
+ test_files:
98
+ - test/helper.rb
99
+ - test/test_colorize.rb
100
+ - test/test_support_lite.rb
101
+ has_rdoc:
@@ -1,19 +0,0 @@
1
- ##
2
- # Removes indentation
3
- #
4
- # @example
5
- # help <<-EOS.undent
6
- # Here my help usage
7
- # sample_code
8
- #
9
- # Fix
10
- # EOS
11
- # puts help.red.bold
12
- #
13
- class String
14
- # Strip unnecessary indentation of the front of a string
15
- def undent
16
- warn "##{__method__} is deprecated"
17
- gsub(/^.{#{slice(/^ +/).size}}/, '')
18
- end
19
- end
@@ -1,57 +0,0 @@
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
data/test/test_utils.rb DELETED
@@ -1,114 +0,0 @@
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