padrino-core 0.13.1 → 0.13.2

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: 3fc93251e3aa682cd94a019446ab096a31f4365d
4
- data.tar.gz: b7c3653e92dc92655372e0359422307d84122b19
3
+ metadata.gz: 851c38a957c7a3b50110244d3b5eb5691091f845
4
+ data.tar.gz: 131c5ba7f4a596a9079aab6d0571b7cc09eb408c
5
5
  SHA512:
6
- metadata.gz: 54ff19551060bd54f259c55cf383ab8a39a737a4e31fa3ebd03dd44e2353a41dac726478ebfb42af22fc0a412abef9579e88e8d4adb240df6348fc943cba7f98
7
- data.tar.gz: 54d8d4b3a35ffc91e16180b342fdcc8d04d043eb085f2e0e52bb88ee9b4ec3cbee00c9a016e6a972b29951abf772ac0ff6381e7abc7cd72ddf18484ff9abe1dd
6
+ metadata.gz: ae1ff61464492c25cbb92ee965631a3ed05430f51df3a5431cbd6763c39c4d262c5a9ca0ec92bb8661fe5c9194a8f912414771773b47d02f322a2a0e9fd46437
7
+ data.tar.gz: 4b37b25021834707ed9b6c267345538b3a2073e428175fe4b0620e3825d167eb0c973ea058e58590e4f223272defb1ec4b254caca66a541d15ae8e0840b36e1d
@@ -507,7 +507,7 @@ module Padrino
507
507
  path, *route_options[:with] = path if path.is_a?(Array)
508
508
  action = path
509
509
  path, name, route_parents, options, route_options = *parse_route(path, route_options, verb)
510
- options.reverse_merge!(@_conditions) if @_conditions
510
+ options = @_conditions.merge(options) if @_conditions
511
511
 
512
512
  method_name = "#{verb} #{path}"
513
513
  unbound_method = generate_method(method_name, &block)
@@ -656,8 +656,7 @@ module Padrino
656
656
  name = "#{controller_name} #{name}".to_sym unless controller_name.blank?
657
657
  end
658
658
 
659
- # Merge in option defaults.
660
- options.reverse_merge!(:default_values => @_defaults)
659
+ options[:default_values] = @_defaults unless options.has_key?(:default_values)
661
660
 
662
661
  [path, name, parent_params, options, route_options]
663
662
  end
@@ -10,7 +10,15 @@ end
10
10
 
11
11
  module PadrinoTasks
12
12
  def self.init(init=false)
13
- $LOAD_PATH.unshift(File.expand_path("lib"))
13
+ lib_path = File.expand_path("lib")
14
+ unless $LOAD_PATH.any?{ |path| File.expand_path(path) == lib_path }
15
+ warn <<-EOT
16
+ WARNING! In Padrino >= 0.14.0 cli command `padrino rake` will NOT add
17
+ './lib' folder to $LOAD_PATH. Please alter your `require` calls accordingly
18
+ if you depend on this behavior.
19
+ EOT
20
+ $LOAD_PATH.unshift lib_path
21
+ end
14
22
  Padrino::Tasks.files.flatten.uniq.each { |rakefile| Rake.application.add_import(rakefile) rescue puts "<= Failed load #{ext}" }
15
23
  load(File.expand_path('../rake_tasks.rb', __FILE__))
16
24
  Rake.application.load_imports
@@ -65,7 +65,7 @@ end
65
65
 
66
66
  Dir["{lib/tasks/**,tasks/**,test,spec}/*.rake"].each do |file|
67
67
  begin
68
- load(file)
68
+ load(File.expand_path(file))
69
69
  rescue LoadError => e
70
70
  warn "#{file}: #{e.message}"
71
71
  end
@@ -13,17 +13,3 @@ class Sinatra::Request
13
13
  route_obj && route_obj.action
14
14
  end
15
15
  end
16
-
17
- ##
18
- # This patches Sinatra to accept UTF-8 urls on JRuby 1.7.6
19
- #
20
- if RUBY_ENGINE == 'jruby' && defined?(JRUBY_VERSION) && JRUBY_VERSION > '1.7.4'
21
- class Sinatra::Base
22
- class << self
23
- alias_method :old_generate_method, :generate_method
24
- def generate_method(method_name, &block)
25
- old_generate_method(method_name.to_sym, &block)
26
- end
27
- end
28
- end
29
- end
@@ -73,7 +73,7 @@ module Padrino
73
73
  bench(args[0], args[1], args[2], name)
74
74
  else
75
75
  if location = resolve_source_location(caller(1).shift)
76
- args.prepend(location)
76
+ args.unshift(location)
77
77
  end if enable_source_location?
78
78
  push(args * '', name)
79
79
  end
@@ -385,6 +385,12 @@ module Padrino
385
385
  # @option options [Symbol] :colorize_logging (true)
386
386
  # Whether or not to colorize log messages. Defaults to: true.
387
387
  #
388
+ # @option options [Symbol] :sanitize_encoding (false)
389
+ # Logger will replace undefined or broken characters with
390
+ # “uFFFD” for Unicode and “?” otherwise.
391
+ # Can be an encoding, false or true.
392
+ # If it's true, logger sanitizes to Encoding.default_external.
393
+ #
388
394
  def initialize(options={})
389
395
  @buffer = []
390
396
  @auto_flush = options.has_key?(:auto_flush) ? options[:auto_flush] : true
@@ -396,6 +402,8 @@ module Padrino
396
402
  @log_static = options.has_key?(:log_static) ? options[:log_static] : false
397
403
  @colorize_logging = options.has_key?(:colorize_logging) ? options[:colorize_logging] : true
398
404
  @source_location = options[:source_location]
405
+ @sanitize_encoding = options[:sanitize_encoding] || false
406
+ @sanitize_encoding = Encoding.default_external if @sanitize_encoding == true
399
407
  colorize! if @colorize_logging
400
408
  end
401
409
 
@@ -407,10 +415,12 @@ module Padrino
407
415
  # Flush the entire buffer to the log object.
408
416
  #
409
417
  def flush
410
- puts @buffer.size if $l
411
418
  return unless @buffer.size > 0
412
419
  @@mutex.synchronize do
413
- @log.write(@buffer.join(''))
420
+ @buffer.each do |line|
421
+ line.encode!(@sanitize_encoding, :invalid => :replace, :undef => :replace) if @sanitize_encoding
422
+ @log.write(line)
423
+ end
414
424
  @buffer.clear
415
425
  end
416
426
  end
@@ -56,18 +56,18 @@ module Padrino
56
56
  #
57
57
  def path(name, *args)
58
58
  params = args.extract_options!
59
- @routes.each do |route|
60
- next unless route.name == name
61
- matcher = route.matcher
62
- params_for_expand = params.dup
63
- if !args.empty? && matcher.mustermann?
64
- matcher.names.each_with_index do |matcher_name, index|
65
- params_for_expand[matcher_name.to_sym] ||= args[index]
66
- end
59
+ candidates = @routes.select { |route| route.name == name }
60
+ fail InvalidRouteException if candidates.empty?
61
+ route = candidates.sort_by! { |route|
62
+ (params.keys.map(&:to_s) - route.matcher.names).length }.shift
63
+ matcher = route.matcher
64
+ params_for_expand = params.dup
65
+ if !args.empty? && matcher.mustermann?
66
+ matcher.names.each_with_index do |matcher_name, index|
67
+ params_for_expand[matcher_name.to_sym] ||= args[index]
67
68
  end
68
- return matcher.mustermann? ? matcher.expand(params_for_expand) : route.path_for_generation
69
69
  end
70
- fail InvalidRouteException
70
+ matcher.mustermann? ? matcher.expand(params_for_expand) : route.path_for_generation
71
71
  end
72
72
 
73
73
  ##
@@ -105,6 +105,15 @@ module Padrino
105
105
  matcher.expand(params) if matcher.mustermann?
106
106
  end
107
107
 
108
+ ##
109
+ # Overwrites path value by passing new path string.
110
+ #
111
+ def path=(pattern)
112
+ @path = pattern
113
+ @matcher = nil
114
+ @significant_variable_names = nil
115
+ end
116
+
108
117
  ##
109
118
  # Returns parameters which is created by the matcher.
110
119
  #
@@ -73,8 +73,9 @@ module Padrino
73
73
  # We lock dependencies sets to prevent reloading of protected constants
74
74
  #
75
75
  def lock!
76
- klasses = ObjectSpace.classes do |klass|
77
- klass._orig_klass_name.split('::').first
76
+ klasses = Storage.send(:object_classes) do |klass|
77
+ original_klass_name = klass._orig_klass_name
78
+ original_klass_name.split('::').first if original_klass_name
78
79
  end
79
80
  klasses |= Padrino.mounted_apps.map(&:app_class)
80
81
  exclude_constants.merge(klasses)
@@ -22,7 +22,7 @@ module Padrino
22
22
  file = remove(name)
23
23
  @old_entries ||= {}
24
24
  @old_entries[name] = {
25
- :constants => ObjectSpace.classes,
25
+ :constants => object_classes,
26
26
  :features => old_features = Set.new($LOADED_FEATURES.dup)
27
27
  }
28
28
  features = file && file[:features] || []
@@ -32,7 +32,7 @@ module Padrino
32
32
 
33
33
  def commit(name)
34
34
  entry = {
35
- :constants => ObjectSpace.new_classes(@old_entries[name][:constants]),
35
+ :constants => new_classes(@old_entries[name][:constants]),
36
36
  :features => Set.new($LOADED_FEATURES) - @old_entries[name][:features] - [name]
37
37
  }
38
38
  files[name] = entry
@@ -40,7 +40,7 @@ module Padrino
40
40
  end
41
41
 
42
42
  def rollback(name)
43
- new_constants = ObjectSpace.new_classes(@old_entries[name][:constants])
43
+ new_constants = new_classes(@old_entries[name][:constants])
44
44
  new_constants.each{ |klass| Reloader.remove_constant(klass) }
45
45
  @old_entries.delete(name)
46
46
  end
@@ -50,6 +50,34 @@ module Padrino
50
50
  def files
51
51
  @files ||= {}
52
52
  end
53
+
54
+ ##
55
+ # Returns all the classes in the object space.
56
+ #
57
+ def object_classes
58
+ klasses = Set.new
59
+
60
+ ObjectSpace.each_object(Class).each do |klass|
61
+ if block_given?
62
+ if filtered_class = yield(klass)
63
+ klasses << filtered_class
64
+ end
65
+ else
66
+ klasses << klass
67
+ end
68
+ end
69
+
70
+ klasses
71
+ end
72
+
73
+ ##
74
+ # Returns a list of object space classes that are not included in "snapshot".
75
+ #
76
+ def new_classes(snapshot)
77
+ object_classes do |klass|
78
+ snapshot.include?(klass) ? nil : klass
79
+ end
80
+ end
53
81
  end
54
82
  end
55
83
  end
@@ -6,7 +6,7 @@
6
6
  #
7
7
  module Padrino
8
8
  # The version constant for the current version of Padrino.
9
- VERSION = '0.13.1' unless defined?(Padrino::VERSION)
9
+ VERSION = '0.13.2' unless defined?(Padrino::VERSION)
10
10
 
11
11
  #
12
12
  # The current Padrino version.
data/test/helper.rb CHANGED
@@ -9,6 +9,7 @@ require 'builder'
9
9
  require 'rack/test'
10
10
  require 'yaml'
11
11
  require 'padrino-core'
12
+ require 'tilt/haml'
12
13
 
13
14
  require 'ext/minitest-spec'
14
15
  require 'ext/rack-test-methods'
data/test/test_logger.rb CHANGED
@@ -82,12 +82,27 @@ describe "PadrinoLogger" do
82
82
  assert_match /log via alias/, @log.string
83
83
  end
84
84
 
85
- it 'should not blow up on mixed or broken encoodings' do
86
- skip
85
+ it 'should not blow up on mixed or broken encodings' do
87
86
  setup_logger(:log_level => :error, :auto_flush => false)
88
- @logger.error "\xD0".force_encoding('BINARY')
89
- @logger << 'фыв'
87
+ binary_data = "\xD0".force_encoding('BINARY')
88
+ utf8_data = 'фыв'
89
+ @logger.error binary_data
90
+ @logger.error utf8_data
90
91
  @logger.flush
92
+ assert @log.string.include?(utf8_data)
93
+ assert @log.string.force_encoding('BINARY').include?(binary_data)
94
+ end
95
+
96
+ it 'should sanitize mixed or broken encodings if said so' do
97
+ encoding = 'windows-1251'
98
+ setup_logger(:log_level => :error, :auto_flush => false, :sanitize_encoding => encoding)
99
+ @log.string.encode! encoding
100
+ binary_data = "\xD0".force_encoding('BINARY')
101
+ utf8_data = 'фыв'
102
+ @logger.error binary_data
103
+ @logger.error utf8_data
104
+ @logger.flush
105
+ assert_match /\?.*фыв/m, @log.string.encode(Encoding.default_external)
91
106
  end
92
107
 
93
108
  it 'should log an application' do
data/test/test_routing.rb CHANGED
@@ -85,6 +85,17 @@ describe "Routing" do
85
85
  assert_equal "tester", body
86
86
  end
87
87
 
88
+ it 'should recognize route even if paths are duplicated' do
89
+ mock_app do
90
+ get(:index) {}
91
+ get(:index, :with => :id) {}
92
+ get(:index, :with => :id, :provides => :json) {}
93
+ end
94
+ assert_equal "/", @app.url_for(:index)
95
+ assert_equal "/1234", @app.url_for(:index, :id => "1234")
96
+ assert_equal "/1234.json?baz=baz", @app.url_for(:index, :id => "1234", :format => "json", :baz => "baz")
97
+ end
98
+
88
99
  it 'should fail with unrecognized route exception when not found' do
89
100
  mock_app do
90
101
  get(:index){ "okey" }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: padrino-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.1
4
+ version: 0.13.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Padrino Team
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2016-01-17 00:00:00.000000000 Z
14
+ date: 2016-05-09 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: padrino-support
@@ -19,82 +19,82 @@ dependencies:
19
19
  requirements:
20
20
  - - '='
21
21
  - !ruby/object:Gem::Version
22
- version: 0.13.1
22
+ version: 0.13.2
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - '='
28
28
  - !ruby/object:Gem::Version
29
- version: 0.13.1
29
+ version: 0.13.2
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: sinatra
32
32
  requirement: !ruby/object:Gem::Requirement
33
33
  requirements:
34
- - - ~>
34
+ - - "~>"
35
35
  - !ruby/object:Gem::Version
36
36
  version: 1.4.6
37
37
  type: :runtime
38
38
  prerelease: false
39
39
  version_requirements: !ruby/object:Gem::Requirement
40
40
  requirements:
41
- - - ~>
41
+ - - "~>"
42
42
  - !ruby/object:Gem::Version
43
43
  version: 1.4.6
44
44
  - !ruby/object:Gem::Dependency
45
45
  name: mustermann19
46
46
  requirement: !ruby/object:Gem::Requirement
47
47
  requirements:
48
- - - '>='
48
+ - - ">="
49
49
  - !ruby/object:Gem::Version
50
50
  version: '0'
51
51
  type: :runtime
52
52
  prerelease: false
53
53
  version_requirements: !ruby/object:Gem::Requirement
54
54
  requirements:
55
- - - '>='
55
+ - - ">="
56
56
  - !ruby/object:Gem::Version
57
57
  version: '0'
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: thor
60
60
  requirement: !ruby/object:Gem::Requirement
61
61
  requirements:
62
- - - ~>
62
+ - - "~>"
63
63
  - !ruby/object:Gem::Version
64
64
  version: '0.18'
65
65
  type: :runtime
66
66
  prerelease: false
67
67
  version_requirements: !ruby/object:Gem::Requirement
68
68
  requirements:
69
- - - ~>
69
+ - - "~>"
70
70
  - !ruby/object:Gem::Version
71
71
  version: '0.18'
72
72
  - !ruby/object:Gem::Dependency
73
73
  name: activesupport
74
74
  requirement: !ruby/object:Gem::Requirement
75
75
  requirements:
76
- - - '>='
76
+ - - ">="
77
77
  - !ruby/object:Gem::Version
78
78
  version: '3.1'
79
79
  type: :runtime
80
80
  prerelease: false
81
81
  version_requirements: !ruby/object:Gem::Requirement
82
82
  requirements:
83
- - - '>='
83
+ - - ">="
84
84
  - !ruby/object:Gem::Version
85
85
  version: '3.1'
86
86
  - !ruby/object:Gem::Dependency
87
87
  name: rack-protection
88
88
  requirement: !ruby/object:Gem::Requirement
89
89
  requirements:
90
- - - '>='
90
+ - - ">="
91
91
  - !ruby/object:Gem::Version
92
92
  version: 1.5.0
93
93
  type: :runtime
94
94
  prerelease: false
95
95
  version_requirements: !ruby/object:Gem::Requirement
96
96
  requirements:
97
- - - '>='
97
+ - - ">="
98
98
  - !ruby/object:Gem::Version
99
99
  version: 1.5.0
100
100
  description: The Padrino core gem required for use of this framework
@@ -105,9 +105,9 @@ extensions: []
105
105
  extra_rdoc_files:
106
106
  - README.rdoc
107
107
  files:
108
- - .document
109
- - .gitignore
110
- - .yardopts
108
+ - ".document"
109
+ - ".gitignore"
110
+ - ".yardopts"
111
111
  - LICENSE.txt
112
112
  - README.rdoc
113
113
  - Rakefile
@@ -168,7 +168,6 @@ files:
168
168
  - test/fixtures/apps/external_apps/fake_root.rb
169
169
  - test/fixtures/apps/helpers/class_methods_helpers.rb
170
170
  - test/fixtures/apps/helpers/instance_methods_helpers.rb
171
- - test/fixtures/apps/helpers/support.rb
172
171
  - test/fixtures/apps/helpers/system_helpers.rb
173
172
  - test/fixtures/apps/kiq.rb
174
173
  - test/fixtures/apps/lib/myklass.rb
@@ -220,17 +219,17 @@ licenses:
220
219
  metadata: {}
221
220
  post_install_message:
222
221
  rdoc_options:
223
- - --charset=UTF-8
222
+ - "--charset=UTF-8"
224
223
  require_paths:
225
224
  - lib
226
225
  required_ruby_version: !ruby/object:Gem::Requirement
227
226
  requirements:
228
- - - '>='
227
+ - - ">="
229
228
  - !ruby/object:Gem::Version
230
229
  version: '0'
231
230
  required_rubygems_version: !ruby/object:Gem::Requirement
232
231
  requirements:
233
- - - '>='
232
+ - - ">="
234
233
  - !ruby/object:Gem::Version
235
234
  version: 1.3.6
236
235
  requirements: []
@@ -257,7 +256,6 @@ test_files:
257
256
  - test/fixtures/apps/external_apps/fake_root.rb
258
257
  - test/fixtures/apps/helpers/class_methods_helpers.rb
259
258
  - test/fixtures/apps/helpers/instance_methods_helpers.rb
260
- - test/fixtures/apps/helpers/support.rb
261
259
  - test/fixtures/apps/helpers/system_helpers.rb
262
260
  - test/fixtures/apps/kiq.rb
263
261
  - test/fixtures/apps/lib/myklass.rb
@@ -1 +0,0 @@
1
- require 'active_support/logger_silence'