padrino-core 0.11.0 → 0.11.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -64,6 +64,8 @@ class HttpRouter
64
64
 
65
65
  # @private
66
66
  class Route
67
+ VALID_HTTP_VERBS.replace %w[GET POST PUT PATCH DELETE HEAD OPTIONS LINK UNLINK]
68
+
67
69
  attr_accessor :use_layout, :controller, :action, :cache, :cache_key, :cache_expires_in, :parent
68
70
 
69
71
  def before_filters(&block)
@@ -88,7 +90,13 @@ class HttpRouter
88
90
  end
89
91
 
90
92
  def significant_variable_names
91
- @significant_variable_names ||= @original_path.nil? ? [] : @original_path.scan(/(^|[^\\])[:\*]([a-zA-Z0-9_]+)/).map{|p| p.last.to_sym}
93
+ @significant_variable_names ||= if @original_path.is_a?(String)
94
+ @original_path.scan(/(^|[^\\])[:\*]([a-zA-Z0-9_]+)/).map{|p| p.last.to_sym}
95
+ elsif @original_path.is_a?(Regexp) and @original_path.respond_to?(:named_captures)
96
+ @original_path.named_captures.keys.map(&:to_sym)
97
+ else
98
+ []
99
+ end
92
100
  end
93
101
  end
94
102
 
@@ -7,8 +7,9 @@ require 'padrino-gen'
7
7
 
8
8
  module PadrinoTasks
9
9
  def self.init(init=false)
10
+ $LOAD_PATH.unshift(File.expand_path("lib")) # Adds "lib" to the load path
10
11
  Padrino::Tasks.files.flatten.uniq.each { |rakefile| Rake.application.add_import(rakefile) rescue puts "<= Failed load #{ext}" }
11
- load(File.expand_path('../rake_tasks.rb', __FILE__))
12
+ load(File.expand_path('../rake_tasks.rb', __FILE__)) # Load default rake tasks
12
13
  Rake.application.load_imports
13
14
  end
14
15
 
@@ -5,8 +5,8 @@ de:
5
5
  # Wenn keine Formate angegeben werden, wird "default" benutzt.
6
6
  # Du kannst auch weitere Formate hinzufügen, wenn Du möchtest.
7
7
  default: "&d.&m.%Y"
8
- short: "%b %d"
9
- long: "%B %d, %Y"
8
+ short: "%d. %b"
9
+ long: "%d. %B %Y"
10
10
  only_day: "%e"
11
11
 
12
12
  day_names: [Sonntag, Montag, Dienstag, Mittwoch, Donnerstag, Freitag, Samstag]
@@ -20,9 +20,9 @@ de:
20
20
 
21
21
  time:
22
22
  formats:
23
- default: "%a, %d %b %Y %H:%M:%S %z"
24
- short: "%d %b %H:%M"
25
- long: "%B %d, %Y %H:%M"
23
+ default: "%a, %d. %b %Y %H:%M:%S %z"
24
+ short: "%d. %b %H:%M"
25
+ long: "%d. %B %Y %H:%M"
26
26
  am: "am"
27
27
  pm: "pm"
28
28
 
@@ -31,4 +31,4 @@ de:
31
31
  array:
32
32
  words_connector: ", "
33
33
  two_words_connector: " und "
34
- last_word_connector: ", und "
34
+ last_word_connector: " und "
@@ -4,15 +4,15 @@ zh_cn:
4
4
  # Use the strftime parameters for formats.
5
5
  # When no format has been given, it uses default.
6
6
  # You can provide other formats here if you like!
7
- default: "%Y-%m-%d"
8
- short: "%b%d日"
9
- long: "%Y年%b%d日"
7
+ default: "%Y 年 %m 月 %d"
8
+ short: "%b%d 日"
9
+ long: "公元 %Y%B 月 %d 日"
10
10
  only_day: "%e"
11
11
 
12
12
  day_names: [星期日, 星期一, 星期二, 星期三, 星期四, 星期五, 星期六]
13
13
  abbr_day_names: [日, 一, 二, 三, 四, 五, 六]
14
- month_names: [~, 一月, 二月, 三月, 四月, 五月, 六月, 七月, 八月, 九月, 十月, 十一月, 十二月]
15
- abbr_month_names: [~, 1月, 2月, 3月, 4月, 5月, 6月, 7月, 8月, 9月, 10月, 11月, 12]
14
+ month_names: [~, 1月, 2月, 3月, 4月, 5月, 6月, 7月, 8月, 9月, 10月, 11月, 12月]
15
+ abbr_month_names: [~, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
16
16
  order:
17
17
  - year
18
18
  - month
@@ -20,15 +20,15 @@ zh_cn:
20
20
 
21
21
  time:
22
22
  formats:
23
- default: "%Y年%b%d日 %A %H:%M:%S %Z"
24
- short: "%b%d日 %H:%M"
25
- long: "%Y年%b%d日 %H:%M"
23
+ default: "%Y 年 %b%d 日 %H:%M:%S %z"
24
+ short: "%d 月 %b 日 %H:%M"
25
+ long: "%Y%B 月 %d 日 %H 时 %M"
26
26
  am: "上午"
27
27
  pm: "下午"
28
28
 
29
29
  # Used in array.to_sentence.
30
30
  support:
31
31
  array:
32
- words_connector: ", "
33
- two_words_connector: " "
34
- last_word_connector: ", 和 "
32
+ words_connector: ""
33
+ two_words_connector: "和"
34
+ last_word_connector: ",还有"
@@ -51,7 +51,7 @@ module Padrino
51
51
  # Detect changed files
52
52
  rotation do |file, mtime|
53
53
  # Retrive the last modified time
54
- new_file = MTIMES[file].nil?
54
+ new_file = MTIMES[file].nil?
55
55
  previous_mtime = MTIMES[file] ||= mtime
56
56
  logger.devel "Detected a new file #{file}" if new_file
57
57
  # We skip to next file if it is not new and not modified
@@ -74,15 +74,9 @@ module Padrino
74
74
  # Remove files and classes loaded with stat
75
75
  #
76
76
  def clear!
77
- MTIMES.clear
78
- LOADED_CLASSES.each do |file, klasses|
79
- klasses.each { |klass| remove_constant(klass) }
80
- LOADED_CLASSES.delete(file)
81
- end
82
- LOADED_FILES.each do |file, dependencies|
83
- dependencies.each { |dependency| $LOADED_FEATURES.delete(dependency) }
84
- $LOADED_FEATURES.delete(file)
85
- end
77
+ clear_modification_times
78
+ clear_loaded_classes
79
+ clear_loaded_files_and_features
86
80
  end
87
81
 
88
82
  ##
@@ -115,56 +109,46 @@ module Padrino
115
109
  # A safe Kernel::require which issues the necessary hooks depending on results
116
110
  #
117
111
  def safe_load(file, options={})
118
- began_at = Time.now
119
- force, file = options[:force], figure_path(file)
112
+ began_at = Time.now
113
+ force = options[:force]
114
+ file = figure_path(file)
115
+ reload = should_reload?(file)
116
+ m_time = modification_time(file)
120
117
 
121
- # Check if file was changed or if force a reload
122
- reload = MTIMES[file] && File.mtime(file) > MTIMES[file]
123
- return if !force && !reload && MTIMES[file]
118
+ return if !force && m_time && !reload
124
119
 
125
- # Removes all classes declared in the specified file
126
- if klasses = LOADED_CLASSES.delete(file)
127
- klasses.each { |klass| remove_constant(klass) }
128
- end
129
-
130
- # Remove all loaded fatures with our file
131
- if features = LOADED_FILES[file]
132
- features.each { |feature| $LOADED_FEATURES.delete(feature) }
133
- end
120
+ remove_loaded_file_classes(file)
121
+ remove_loaded_file_features(file)
134
122
 
135
123
  # Duplicate objects and loaded features before load file
136
124
  klasses = ObjectSpace.classes
137
125
  files = Set.new($LOADED_FEATURES.dup)
138
126
 
139
- # Now we can reload dependencies of our file
140
- if features = LOADED_FILES.delete(file)
141
- features.each { |feature| safe_load(feature, :force => true) }
142
- end
127
+ reload_deps_of_file(file)
143
128
 
144
129
  # And finally load the specified file
145
130
  begin
146
131
  logger.devel :loading, began_at, file if !reload
147
132
  logger.debug :reload, began_at, file if reload
133
+
148
134
  $LOADED_FEATURES.delete(file) if files.include?(file)
149
- verbosity_was, $-v = $-v, nil
135
+ Padrino::Utils.silence_output
150
136
  loaded = false
151
137
  require(file)
152
138
  loaded = true
153
- MTIMES[file] = File.mtime(file)
139
+ update_modification_time(file)
154
140
  rescue SyntaxError => e
155
141
  logger.error "Cannot require #{file} due to a syntax error: #{e.message}"
156
142
  ensure
157
- $-v = verbosity_was
143
+ Padrino::Utils.unsilence_output
158
144
  new_constants = ObjectSpace.new_classes(klasses)
159
145
  if loaded
160
- # Store the file details
161
- LOADED_CLASSES[file] = new_constants
162
- LOADED_FILES[file] = Set.new($LOADED_FEATURES) - files - [file]
163
- # Track only features in our Padrino.root
164
- LOADED_FILES[file].delete_if { |feature| !in_root?(feature) }
146
+ process_loaded_file(:file => file,
147
+ :constants => new_constants,
148
+ :files => files)
165
149
  else
166
150
  logger.devel "Failed to load #{file}; removing partially defined constants"
167
- new_constants.each { |klass| remove_constant(klass) }
151
+ unload_constants(new_constants)
168
152
  end
169
153
  end
170
154
  end
@@ -197,6 +181,101 @@ module Padrino
197
181
  end
198
182
 
199
183
  private
184
+
185
+ ###
186
+ # Clear instance variables that keep track of
187
+ # loaded features/files/mtimes
188
+ #
189
+ def clear_modification_times
190
+ MTIMES.clear
191
+ end
192
+
193
+ def clear_loaded_classes
194
+ LOADED_CLASSES.each do |file, klasses|
195
+ klasses.each { |klass| remove_constant(klass) }
196
+ LOADED_CLASSES.delete(file)
197
+ end
198
+ end
199
+
200
+ def clear_loaded_files_and_features
201
+ LOADED_FILES.each do |file, dependencies|
202
+ dependencies.each { |dependency| $LOADED_FEATURES.delete(dependency) }
203
+ $LOADED_FEATURES.delete(file)
204
+ end
205
+ end
206
+
207
+ ###
208
+ # Macro for mtime query
209
+ #
210
+ def modification_time(file)
211
+ MTIMES[file]
212
+ end
213
+
214
+ ###
215
+ # Macro for mtime update
216
+ #
217
+ def update_modification_time(file)
218
+ MTIMES[file] = File.mtime(file)
219
+ end
220
+
221
+ ###
222
+ # Tracks loaded file features/classes/constants
223
+ #
224
+ def process_loaded_file(*args)
225
+ options = args.extract_options!
226
+ new_constants = options[:constants]
227
+ files = options[:files]
228
+ file = options[:file]
229
+
230
+ # Store the file details
231
+ LOADED_CLASSES[file] = new_constants
232
+ LOADED_FILES[file] = Set.new($LOADED_FEATURES) - files - [file]
233
+
234
+ # Track only features in our Padrino.root
235
+ LOADED_FILES[file].delete_if { |feature| !in_root?(feature) }
236
+ end
237
+
238
+ ###
239
+ # Unloads all constants in new_constants
240
+ #
241
+ def unload_constants(new_constants)
242
+ new_constants.each { |klass| remove_constant(klass) }
243
+ end
244
+
245
+ ###
246
+ # Safe load dependencies of a file
247
+ #
248
+ def reload_deps_of_file(file)
249
+ if features = LOADED_FILES.delete(file)
250
+ features.each { |feature| safe_load(feature, :force => true) }
251
+ end
252
+ end
253
+
254
+ ##
255
+ # Check if file was changed or if force a reload
256
+ #
257
+ def should_reload?(file)
258
+ MTIMES[file] && File.mtime(file) > MTIMES[file]
259
+ end
260
+
261
+ ##
262
+ # Removes all classes declared in the specified file
263
+ #
264
+ def remove_loaded_file_classes(file)
265
+ if klasses = LOADED_CLASSES.delete(file)
266
+ klasses.each { |klass| remove_constant(klass) }
267
+ end
268
+ end
269
+
270
+ ##
271
+ # Remove all loaded fatures with our file
272
+ #
273
+ def remove_loaded_file_features(file)
274
+ if features = LOADED_FILES[file]
275
+ features.each { |feature| $LOADED_FEATURES.delete(feature) }
276
+ end
277
+ end
278
+
200
279
  ##
201
280
  # Return the mounted_apps providing the app location
202
281
  # Can be an array because in one app.rb we can define multiple Padrino::Appplications
@@ -220,15 +299,21 @@ module Padrino
220
299
  # and monitors them for any changes.
221
300
  #
222
301
  def rotation
223
- files = Padrino.load_paths.map { |path| Dir["#{path}/**/*.rb"] }.flatten
224
- files = files | Padrino.mounted_apps.map { |app| app.app_file }
225
- files = files | Padrino.mounted_apps.map { |app| app.app_obj.dependencies }.flatten
226
- files.uniq.map do |file|
302
+ files_for_rotation.uniq.map do |file|
227
303
  file = File.expand_path(file)
228
304
  next if Padrino::Reloader.exclude.any? { |base| file.index(base) == 0 } || !File.exist?(file)
229
305
  yield file, File.mtime(file)
230
306
  end.compact
231
307
  end
308
+
309
+ ##
310
+ # Creates an array of paths for use in #rotation
311
+ #
312
+ def files_for_rotation
313
+ files = Padrino.load_paths.map { |path| Dir["#{path}/**/*.rb"] }.flatten
314
+ files = files | Padrino.mounted_apps.map { |app| app.app_file }
315
+ files = files | Padrino.mounted_apps.map { |app| app.app_obj.dependencies }.flatten
316
+ end
232
317
  end # self
233
318
 
234
319
  ##
@@ -242,3 +242,19 @@ I18n.load_path += Dir["#{File.dirname(__FILE__)}/locale/*.yml"] if defined?(I18n
242
242
  # Used to determine if this file has already been required
243
243
  #
244
244
  module SupportLite; end
245
+
246
+ module Padrino
247
+ class Utils
248
+ ###
249
+ # Silences output verbosity level so load
250
+ # errors are not visible when safe_load(file)
251
+ #
252
+ def self.silence_output
253
+ @verbosity_level, $-v = $-v, nil
254
+ end
255
+
256
+ def self.unsilence_output
257
+ $-v = @verbosity_level
258
+ end
259
+ end
260
+ 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.11.0' unless defined?(Padrino::VERSION)
9
+ VERSION = '0.11.1' unless defined?(Padrino::VERSION)
10
10
 
11
11
  #
12
12
  # The current Padrino version.
@@ -207,6 +207,14 @@ describe "Routing" do
207
207
  assert_equal 404, status
208
208
  end
209
209
 
210
+ should 'allow regex url with format' do
211
+ mock_app do
212
+ get(/.*/, :provides => :any) { "regexp" }
213
+ end
214
+ get "/anything"
215
+ assert_equal "regexp", body
216
+ end
217
+
210
218
  should 'use padrino url method' do
211
219
  mock_app do
212
220
  end
metadata CHANGED
@@ -1,7 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: padrino-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
4
+ version: 0.11.1
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Padrino Team
@@ -11,11 +12,12 @@ authors:
11
12
  autorequire:
12
13
  bindir: bin
13
14
  cert_chain: []
14
- date: 2013-03-22 00:00:00.000000000 Z
15
+ date: 2013-04-07 00:00:00.000000000 Z
15
16
  dependencies:
16
17
  - !ruby/object:Gem::Dependency
17
18
  name: tilt
18
19
  requirement: !ruby/object:Gem::Requirement
20
+ none: false
19
21
  requirements:
20
22
  - - ~>
21
23
  - !ruby/object:Gem::Version
@@ -23,6 +25,7 @@ dependencies:
23
25
  type: :runtime
24
26
  prerelease: false
25
27
  version_requirements: !ruby/object:Gem::Requirement
28
+ none: false
26
29
  requirements:
27
30
  - - ~>
28
31
  - !ruby/object:Gem::Version
@@ -30,6 +33,7 @@ dependencies:
30
33
  - !ruby/object:Gem::Dependency
31
34
  name: sinatra
32
35
  requirement: !ruby/object:Gem::Requirement
36
+ none: false
33
37
  requirements:
34
38
  - - ~>
35
39
  - !ruby/object:Gem::Version
@@ -37,6 +41,7 @@ dependencies:
37
41
  type: :runtime
38
42
  prerelease: false
39
43
  version_requirements: !ruby/object:Gem::Requirement
44
+ none: false
40
45
  requirements:
41
46
  - - ~>
42
47
  - !ruby/object:Gem::Version
@@ -44,6 +49,7 @@ dependencies:
44
49
  - !ruby/object:Gem::Dependency
45
50
  name: http_router
46
51
  requirement: !ruby/object:Gem::Requirement
52
+ none: false
47
53
  requirements:
48
54
  - - ~>
49
55
  - !ruby/object:Gem::Version
@@ -51,6 +57,7 @@ dependencies:
51
57
  type: :runtime
52
58
  prerelease: false
53
59
  version_requirements: !ruby/object:Gem::Requirement
60
+ none: false
54
61
  requirements:
55
62
  - - ~>
56
63
  - !ruby/object:Gem::Version
@@ -58,6 +65,7 @@ dependencies:
58
65
  - !ruby/object:Gem::Dependency
59
66
  name: thor
60
67
  requirement: !ruby/object:Gem::Requirement
68
+ none: false
61
69
  requirements:
62
70
  - - ~>
63
71
  - !ruby/object:Gem::Version
@@ -65,6 +73,7 @@ dependencies:
65
73
  type: :runtime
66
74
  prerelease: false
67
75
  version_requirements: !ruby/object:Gem::Requirement
76
+ none: false
68
77
  requirements:
69
78
  - - ~>
70
79
  - !ruby/object:Gem::Version
@@ -72,29 +81,33 @@ dependencies:
72
81
  - !ruby/object:Gem::Dependency
73
82
  name: activesupport
74
83
  requirement: !ruby/object:Gem::Requirement
84
+ none: false
75
85
  requirements:
76
- - - '>='
86
+ - - ! '>='
77
87
  - !ruby/object:Gem::Version
78
88
  version: 3.1.0
79
89
  type: :runtime
80
90
  prerelease: false
81
91
  version_requirements: !ruby/object:Gem::Requirement
92
+ none: false
82
93
  requirements:
83
- - - '>='
94
+ - - ! '>='
84
95
  - !ruby/object:Gem::Version
85
96
  version: 3.1.0
86
97
  - !ruby/object:Gem::Dependency
87
98
  name: rack-protection
88
99
  requirement: !ruby/object:Gem::Requirement
100
+ none: false
89
101
  requirements:
90
- - - '>='
102
+ - - ! '>='
91
103
  - !ruby/object:Gem::Version
92
104
  version: 1.5.0
93
105
  type: :runtime
94
106
  prerelease: false
95
107
  version_requirements: !ruby/object:Gem::Requirement
108
+ none: false
96
109
  requirements:
97
- - - '>='
110
+ - - ! '>='
98
111
  - !ruby/object:Gem::Version
99
112
  version: 1.5.0
100
113
  description: The Padrino core gem required for use of this framework
@@ -198,27 +211,31 @@ files:
198
211
  - test/test_support_lite.rb
199
212
  homepage: http://www.padrinorb.com
200
213
  licenses: []
201
- metadata: {}
202
214
  post_install_message:
203
215
  rdoc_options:
204
216
  - --charset=UTF-8
205
217
  require_paths:
206
218
  - lib
207
219
  required_ruby_version: !ruby/object:Gem::Requirement
220
+ none: false
208
221
  requirements:
209
- - - '>='
222
+ - - ! '>='
210
223
  - !ruby/object:Gem::Version
211
224
  version: '0'
225
+ segments:
226
+ - 0
227
+ hash: -239546567818067895
212
228
  required_rubygems_version: !ruby/object:Gem::Requirement
229
+ none: false
213
230
  requirements:
214
- - - '>='
231
+ - - ! '>='
215
232
  - !ruby/object:Gem::Version
216
233
  version: 1.3.6
217
234
  requirements: []
218
235
  rubyforge_project: padrino-core
219
- rubygems_version: 2.0.3
236
+ rubygems_version: 1.8.25
220
237
  signing_key:
221
- specification_version: 4
238
+ specification_version: 3
222
239
  summary: The required Padrino core gem
223
240
  test_files:
224
241
  - test/fixtures/app_gem/Gemfile
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA1:
3
- metadata.gz: 9f915e954014b964f9d5afccd9999d80cd888c05
4
- data.tar.gz: 0f64be604ae666519fdd77d32413f9bdf4c32986
5
- SHA512:
6
- metadata.gz: f5b45a55ece397aabf5c7e9d4c961a51edeaa882156962222a0b41d718e62c000fa301f954236fa1599d94e8f2e19109e538b775a2c651c94dfefabf6f187073
7
- data.tar.gz: 7796c665daf7a323174e265e3fbc23d71cef98cc9ae1427cb0d5a3d18a3352fdd861fab8adb83308b01c6f4e2f7b1e3bd6ab372493b6032c43f41431dabbb15e