padrino-core 0.10.2 → 0.10.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. data/.document +3 -3
  2. data/.yardopts +1 -0
  3. data/{LICENSE → LICENSE.txt} +0 -0
  4. data/README.rdoc +2 -2
  5. data/lib/padrino-core/application/rendering.rb +79 -26
  6. data/lib/padrino-core/application/routing.rb +215 -127
  7. data/lib/padrino-core/application/showexceptions.rb +2 -1
  8. data/lib/padrino-core/application.rb +67 -57
  9. data/lib/padrino-core/caller.rb +10 -4
  10. data/lib/padrino-core/command.rb +11 -0
  11. data/lib/padrino-core/loader.rb +52 -24
  12. data/lib/padrino-core/locale/cs.yml +4 -1
  13. data/lib/padrino-core/locale/da.yml +4 -1
  14. data/lib/padrino-core/locale/de.yml +4 -1
  15. data/lib/padrino-core/locale/en.yml +4 -1
  16. data/lib/padrino-core/locale/es.yml +4 -1
  17. data/lib/padrino-core/locale/fr.yml +4 -1
  18. data/lib/padrino-core/locale/hu.yml +4 -1
  19. data/lib/padrino-core/locale/it.yml +4 -1
  20. data/lib/padrino-core/locale/ja.yml +4 -1
  21. data/lib/padrino-core/locale/lv.yml +34 -0
  22. data/lib/padrino-core/locale/nl.yml +4 -1
  23. data/lib/padrino-core/locale/no.yml +4 -1
  24. data/lib/padrino-core/locale/pl.yml +4 -1
  25. data/lib/padrino-core/locale/pt_br.yml +4 -1
  26. data/lib/padrino-core/locale/ru.yml +4 -1
  27. data/lib/padrino-core/locale/tr.yml +4 -1
  28. data/lib/padrino-core/locale/uk.yml +4 -1
  29. data/lib/padrino-core/locale/zh_cn.yml +4 -1
  30. data/lib/padrino-core/locale/zh_tw.yml +4 -1
  31. data/lib/padrino-core/logger.rb +119 -128
  32. data/lib/padrino-core/mounter.rb +46 -14
  33. data/lib/padrino-core/reloader.rb +5 -3
  34. data/lib/padrino-core/router.rb +30 -11
  35. data/lib/padrino-core/server.rb +14 -5
  36. data/lib/padrino-core/support_lite.rb +54 -20
  37. data/lib/padrino-core/tasks.rb +1 -3
  38. data/lib/padrino-core/version.rb +8 -4
  39. data/lib/padrino-core.rb +58 -11
  40. data/padrino-core.gemspec +1 -1
  41. data/test/fixtures/apps/simple.rb +1 -1
  42. data/test/helper.rb +4 -24
  43. data/test/mini_shoulda.rb +45 -0
  44. data/test/test_application.rb +19 -18
  45. data/test/test_core.rb +2 -2
  46. data/test/test_dependencies.rb +5 -5
  47. data/test/test_filters.rb +2 -1
  48. data/test/test_locale.rb +1 -1
  49. data/test/test_logger.rb +1 -1
  50. data/test/test_mounter.rb +26 -25
  51. data/test/test_reloader_complex.rb +5 -3
  52. data/test/test_reloader_simple.rb +6 -5
  53. data/test/test_rendering.rb +8 -5
  54. data/test/test_restful_routing.rb +1 -1
  55. data/test/test_router.rb +1 -1
  56. data/test/test_routing.rb +33 -12
  57. metadata +13 -9
@@ -13,7 +13,10 @@ pt_br:
13
13
  abbr_day_names: [Dom, Seg, Ter, Qua, Qui, Sex, Sab]
14
14
  month_names: [~, Janeiro, Fevereiro, Março, Abril, Maio, Junho, Julho, Agosto, Setembro, Outubro, Novembro, Dezembro]
15
15
  abbr_month_names: [~, Jan, Fev, Mar, Abr, Maio, Jun, Jul, Ago, Set, Out, Nov, Dez]
16
- order: [ :day, :month, :year ]
16
+ order:
17
+ - day
18
+ - month
19
+ - year
17
20
 
18
21
  time:
19
22
  formats:
@@ -13,7 +13,10 @@ ru:
13
13
  abbr_day_names: [Вс, Пн, Вт, Ср, Чт, Пт, Сб]
14
14
  month_names: [~, Январь, Февраль, Март, Апрель, Май, Июнь, Июль, Август, Сентябрь, Октябрь, Ноябрь, Декабрь]
15
15
  abbr_month_names: [~, Янв, Феб, Мар, Апр, Май, Июн, Июл, Авг, Сен, Окт, Ноя, Дек]
16
- order: [ :year, :month, :day ]
16
+ order:
17
+ - year
18
+ - month
19
+ - day
17
20
 
18
21
  time:
19
22
  formats:
@@ -13,7 +13,10 @@ tr:
13
13
  abbr_day_names: [Paz, Pts, Sal, Çar, Per, Cum, Cts]
14
14
  month_names: [~, Ocak, Şubat, Mart, Nisan, Mayıs, Haziran, Temmuz, Ağustos, Eylül, Ekim, Kasım, Aralık]
15
15
  abbr_month_names: [~, Oca, Şub, Mar, Nis, May, Haz, Tem, Ağu, Eyl, Eki, Kas, Ara]
16
- order: [ :day, :month, :year ]
16
+ order:
17
+ - day
18
+ - month
19
+ - year
17
20
 
18
21
  time:
19
22
  formats:
@@ -13,7 +13,10 @@ uk:
13
13
  abbr_day_names: [Нд, Пн, Вт, Ср, Чт, Пт, Сб]
14
14
  month_names: [~, Січено, Лютий, Березень, Квітень, Травень, Червень, Липень, Серпень, Вересень, Жовтень, Листопад, Грудень]
15
15
  abbr_month_names: [~, Січ, Лют, Бер, Кві, Тра, Чер, Лип, Сер, Вер, Жов, Лис, Гру]
16
- order: [ :year, :month, :day ]
16
+ order:
17
+ - year
18
+ - month
19
+ - day
17
20
 
18
21
  time:
19
22
  formats:
@@ -13,7 +13,10 @@ zh_cn:
13
13
  abbr_day_names: [日, 一, 二, 三, 四, 五, 六]
14
14
  month_names: [~, 一月, 二月, 三月, 四月, 五月, 六月, 七月, 八月, 九月, 十月, 十一月, 十二月]
15
15
  abbr_month_names: [~, 1月, 2月, 3月, 4月, 5月, 6月, 7月, 8月, 9月, 10月, 11月, 12月]
16
- order: [ :year, :month, :day ]
16
+ order:
17
+ - year
18
+ - month
19
+ - day
17
20
 
18
21
  time:
19
22
  formats:
@@ -13,7 +13,10 @@ zh_tw:
13
13
  abbr_day_names: [日, 一, 二, 三, 四, 五, 六]
14
14
  month_names: [~, 一月, 二月, 三月, 四月, 五月, 六月, 七月, 八月, 九月, 十月, 十一月, 十二月]
15
15
  abbr_month_names: [~, 1月, 2月, 3月, 4月, 5月, 6月, 7月, 8月, 9月, 10月, 11月, 12月]
16
- order: [ :year, :month, :day ]
16
+ order:
17
+ - year
18
+ - month
19
+ - day
17
20
 
18
21
  time:
19
22
  formats:
@@ -5,10 +5,9 @@ PADRINO_LOGGER = ENV['PADRINO_LOGGER'] unless defined?(PADRINO_LOGGER)
5
5
  module Padrino
6
6
 
7
7
  ##
8
- # Returns the padrino logger
9
- #
10
- # ==== Examples
8
+ # @return [Padrino::Logger]
11
9
  #
10
+ # @example
12
11
  # logger.debug "foo"
13
12
  # logger.warn "bar"
14
13
  #
@@ -20,6 +19,20 @@ module Padrino
20
19
  ##
21
20
  # Set the padrino logger
22
21
  #
22
+ # @param [Object] value
23
+ # an object that respond to <<, write, puts, debug, warn etc..
24
+ #
25
+ # @return [Object]
26
+ # the given value
27
+ #
28
+ # @example using ruby default logger
29
+ # require 'logger'
30
+ # Padrino.logger = Logger.new(STDOUT)
31
+ #
32
+ # @example using ActiveSupport
33
+ # require 'active_support/buffered_logger'
34
+ # Padrino.logger = Buffered.new(STDOUT)
35
+ #
23
36
  def self.logger=(value)
24
37
  Thread.current[:padrino_logger] = value
25
38
  end
@@ -27,11 +40,6 @@ module Padrino
27
40
  ##
28
41
  # Extensions to the built in Ruby logger.
29
42
  #
30
- # ==== Examples
31
- #
32
- # logger.debug "foo"
33
- # logger.warn "bar"
34
- #
35
43
  class Logger
36
44
 
37
45
  attr_accessor :level
@@ -76,8 +84,7 @@ module Padrino
76
84
  # :format_message:: Format of message. Defaults to: ""%s - - [%s] \"%s\"""
77
85
  # :log_static:: Whether or not to show log messages for static files. Defaults to: false
78
86
  #
79
- # ==== Examples
80
- #
87
+ # @example
81
88
  # Padrino::Logger::Config[:development] = { :log_level => :debug, :stream => :to_file }
82
89
  # # or you can edit our defaults
83
90
  # Padrino::Logger::Config[:development][:log_level] = :error
@@ -97,36 +104,27 @@ module Padrino
97
104
  #
98
105
  Config = {
99
106
  :production => { :log_level => :warn, :stream => :to_file },
100
- :development => { :log_level => :debug, :stream => :stdout },
107
+ :development => { :log_level => :debug, :stream => :stdout, :format_datetime => ' ' },
101
108
  :test => { :log_level => :debug, :stream => :null }
102
109
  }
103
110
  Config.merge!(PADRINO_LOGGER) if PADRINO_LOGGER
104
111
 
105
- # Embed in a String to clear all previous ANSI sequences.
106
- CLEAR = "\e[0m"
107
- BOLD = "\e[1m"
108
- BLACK = "\e[30m"
109
- RED = "\e[31m"
110
- GREEN = "\e[32m"
111
- YELLOW = "\e[33m"
112
- BLUE = "\e[34m"
113
- MAGENTA = "\e[35m"
114
- CYAN = "\e[36m"
115
- WHITE = "\e[37m"
116
-
117
112
  # Colors for levels
118
113
  ColoredLevels = {
119
- :fatal => [BOLD, RED],
120
- :error => [RED],
121
- :warn => [YELLOW],
122
- :info => [GREEN],
123
- :debug => [CYAN],
124
- :devel => [MAGENTA]
114
+ :fatal => [:bold, :red],
115
+ :error => [:red],
116
+ :warn => [:yellow],
117
+ :info => [:green],
118
+ :debug => [:cyan],
119
+ :devel => [:magenta]
125
120
  } unless defined?(ColoredLevels)
126
121
 
127
122
  ##
128
123
  # Setup a new logger
129
124
  #
125
+ # @return [Padrino::Logger]
126
+ # A {Padrino::Logger} instance
127
+ #
130
128
  def self.setup!
131
129
  config_level = (PADRINO_LOG_LEVEL || Padrino.env || :test).to_sym # need this for PADRINO_LOG_LEVEL
132
130
  config = Config[config_level]
@@ -151,46 +149,49 @@ module Padrino
151
149
  ##
152
150
  # To initialize the logger you create a new object, proxies to set_log.
153
151
  #
154
- # ==== Options
152
+ # @param [Hash] options
155
153
  #
156
- # :stream:: Either an IO object or a name of a logfile. Defaults to $stdout
157
- # :log_level::
158
- # The log level from, e.g. :fatal or :info. Defaults to :debug in the
159
- # production environment and :debug otherwise.
160
- # :auto_flush::
154
+ # @option options [Symbol] :stream ($stdout)
155
+ # Either an IO object or a name of a logfile. Defaults to $stdout
156
+ #
157
+ # @option options [Symbol] :log_level (:production in the production environment and :debug otherwise)
158
+ # The log level from, e.g. :fatal or :info.
159
+ #
160
+ # @option options [Symbol] :auto_flush (true)
161
161
  # Whether the log should automatically flush after new messages are
162
162
  # added. Defaults to true.
163
- # :format_datetime:: Format of datetime. Defaults to: "%d/%b/%Y %H:%M:%S"
164
- # :format_message:: Format of message. Defaults to: ""%s - - [%s] \"%s\"""
165
- # :log_static:: Whether or not to show log messages for static files. Defaults to: false
163
+ #
164
+ # @option options [Symbol] :format_datetime (" [%d/%b/%Y %H:%M:%S] ")
165
+ # Format of datetime
166
+ #
167
+ # @option options [Symbol] :format_message ("%s -%s%s")
168
+ # Format of message
169
+ #
170
+ # @option options [Symbol] :log_static (false)
171
+ # Whether or not to show log messages for static files.
166
172
  #
167
173
  def initialize(options={})
168
- @buffer = []
169
- @auto_flush = options.has_key?(:auto_flush) ? options[:auto_flush] : true
170
- @level = options[:log_level] ? Levels[options[:log_level]] : Levels[:debug]
171
- @log = options[:stream] || $stdout
172
- @log.sync = true
173
- @mutex = @@mutex[@log] ||= Mutex.new
174
- @format_datetime = options[:format_datetime] || "%d/%b/%Y %H:%M:%S"
175
- @format_message = options[:format_message] || "%s - [%s] \"%s\""
176
- @log_static = options.has_key?(:log_static) ? options[:log_static] : false
174
+ @buffer = []
175
+ @auto_flush = options.has_key?(:auto_flush) ? options[:auto_flush] : true
176
+ @level = options[:log_level] ? Levels[options[:log_level]] : Levels[:debug]
177
+ @log = options[:stream] || $stdout
178
+ @log.sync = true
179
+ @mutex = @@mutex[@log] ||= Mutex.new
180
+ @format_datetime = options[:format_datetime] || "%d/%b/%Y %H:%M:%S"
181
+ @format_message = options[:format_message] || "%s -%s%s"
182
+ @log_static = options.has_key?(:log_static) ? options[:log_static] : false
177
183
  end
178
184
 
179
185
  ##
180
186
  # Colorize our level
181
187
  #
182
- def colored_level(level)
183
- style = ColoredLevels[level.to_s.downcase.to_sym].join("")
184
- "#{style}#{level.to_s.upcase.rjust(7)}#{CLEAR}"
185
- end
186
-
187
- ##
188
- # Set a color for our string. Color can be a symbol/string
188
+ # @param [String, Symbol] level
189
+ #
190
+ # @see Padrino::Logger::ColoredLevels
189
191
  #
190
- def set_color(string, color, bold=false)
191
- color = self.class.const_get(color.to_s.upcase) if color.is_a?(Symbol)
192
- bold = bold ? BOLD : ""
193
- "#{bold}#{color}#{string}#{CLEAR}"
192
+ def colored_level(level)
193
+ style = ColoredLevels[level].map { |c| "\e[%dm" % String.colors[c] } * ''
194
+ [style, level.to_s.upcase.rjust(7), "\e[0m"] * ''
194
195
  end
195
196
 
196
197
  ##
@@ -206,6 +207,8 @@ module Padrino
206
207
  ##
207
208
  # Close and remove the current log object.
208
209
  #
210
+ # @return [NilClass]
211
+ #
209
212
  def close
210
213
  flush
211
214
  @log.close if @log.respond_to?(:close) && !@log.tty?
@@ -216,13 +219,47 @@ module Padrino
216
219
  # Appends a message to the log. The methods yield to an optional block and
217
220
  # the output of this block will be appended to the message.
218
221
  #
222
+ # @param [String] message
223
+ # The message that you want write to your stream
224
+ #
225
+ # @param [String] level
226
+ # The level one of :debug, :warn etc...
227
+ #
228
+ #
219
229
  def push(message = nil, level = nil)
220
- self << @format_message % [colored_level(level), set_color(Time.now.strftime(@format_datetime), :yellow), message.to_s.strip]
230
+ write @format_message % [colored_level(level), Time.now.strftime(@format_datetime).yellow, message.to_s.strip]
231
+ end
232
+
233
+ ##
234
+ # Append a to development logger a given action with time
235
+ #
236
+ # @param [string] action
237
+ # The action
238
+ #
239
+ # @param [float] time
240
+ # Time duration for the given action
241
+ #
242
+ # @param [message] string
243
+ # The message that you want to log
244
+ #
245
+ # @example
246
+ # logger.bench 'GET', started_at, '/blog/categories'
247
+ # # => DEBUG - GET (0.056ms) - /blog/categories
248
+ #
249
+ def bench(action, began_at, message, level=:debug, color=:yellow)
250
+ @_pad ||= 8
251
+ @_pad = action.to_s.size if action.to_s.size > @_pad
252
+ duration = Time.now - began_at
253
+ color = :red if duration > 1
254
+ push "%s (" % action.to_s.upcase.rjust(@_pad).send(color) + "%0.4fms".bold.send(color) % duration + ") %s" % message.to_s, level
221
255
  end
222
256
 
223
257
  ##
224
258
  # Directly append message to the log.
225
259
  #
260
+ # @param [String] message
261
+ # The message
262
+ #
226
263
  def <<(message = nil)
227
264
  message << "\n" unless message[-1] == ?\n
228
265
  @buffer << message
@@ -232,50 +269,21 @@ module Padrino
232
269
  alias :write :<<
233
270
 
234
271
  ##
235
- # Generate the logging methods for Padrino.logger for each log level.
272
+ # Generate the logging methods for {Padrino.logger} for each log level.
236
273
  #
237
274
  Levels.each_pair do |name, number|
238
- class_eval <<-LEVELMETHODS, __FILE__, __LINE__
239
- # Appends a message to the log if the log level is at least as high as
240
- # the log level of the logger.
241
- #
242
- # ==== Parameters
243
- # message:: The message to be logged. Defaults to nil.
244
- #
245
- # ==== Returns
246
- # self:: The logger object for chaining.
247
- def #{name}(message = nil)
248
- if #{number} >= level
249
- message = block_given? ? yield : message
250
- self.push(message, :#{name}) if #{number} >= level
251
- end
252
- self
253
- end
254
-
255
- # Appends a message to the log if the log level is at least as high as
256
- # the log level of the logger. The bang! version of the method also auto
257
- # flushes the log buffer to disk.
258
- #
259
- # ==== Parameters
260
- # message:: The message to be logged. Defaults to nil.
261
- #
262
- # ==== Returns
263
- # self:: The logger object for chaining.
264
- def #{name}!(message = nil)
265
- if #{number} >= level
266
- message = block_given? ? yield : message
267
- self.push(message, :#{name}) if #{number} >= level
268
- flush if #{number} >= level
275
+ define_method(name) do |*args|
276
+ return if number < level
277
+ if args.size > 1
278
+ bench(*args)
279
+ else
280
+ push(args * '', name)
269
281
  end
270
- self
271
282
  end
272
283
 
273
- # ==== Returns
274
- # Boolean:: True if this level will be logged by this logger.
275
- def #{name}?
276
- #{number} >= level
284
+ define_method(:"#{name}?") do
285
+ number >= level
277
286
  end
278
- LEVELMETHODS
279
287
  end
280
288
 
281
289
  ##
@@ -284,19 +292,13 @@ module Padrino
284
292
  # rack.errors by default.
285
293
  #
286
294
  class Rack
287
- ##
288
- # Common Log Format: http://httpd.apache.org/docs/1.3/logs.html#common
289
- # "lilith.local - - GET / HTTP/1.1 500 -"
290
- # %{%s - %s %s %s%s %s - %d %s %0.4f}
291
- #
292
- FORMAT = %{%s (%0.4fms) %s - %s %s%s%s %s - %d %s}
293
295
 
294
- def initialize(app, uri_root)
296
+ def initialize(app, uri_root) # @private
295
297
  @app = app
296
298
  @uri_root = uri_root.sub(/\/$/,"")
297
299
  end
298
300
 
299
- def call(env)
301
+ def call(env) # @private
300
302
  env['rack.logger'] = Padrino.logger
301
303
  env['rack.errors'] = Padrino.logger.log
302
304
  began_at = Time.now
@@ -307,31 +309,20 @@ module Padrino
307
309
 
308
310
  private
309
311
  def log(env, status, header, began_at)
310
- now = Time.now
311
- length = extract_content_length(header)
312
-
313
312
  return if env['sinatra.static_file'] and !logger.log_static
314
-
315
- logger.debug FORMAT % [
313
+ logger.bench(
316
314
  env["REQUEST_METHOD"],
317
- now - began_at,
318
- env['HTTP_X_FORWARDED_FOR'] || env["REMOTE_ADDR"] || "-",
319
- env["REMOTE_USER"] || "-",
320
- @uri_root || "",
321
- env["PATH_INFO"],
322
- env["QUERY_STRING"].empty? ? "" : "?" + env["QUERY_STRING"],
323
- env["HTTP_VERSION"],
324
- status.to_s[0..3],
325
- length]
326
- end
327
-
328
- def extract_content_length(headers)
329
- headers.each do |key, value|
330
- if key.downcase == 'content-length'
331
- return value.to_s == '0' ? '-' : value
332
- end
333
- end
334
- '-'
315
+ began_at,
316
+ [
317
+ @uri_root.to_s,
318
+ env["PATH_INFO"],
319
+ env["QUERY_STRING"].empty? ? "" : "?" + env["QUERY_STRING"],
320
+ ' - ',
321
+ status.to_s[0..3].bold
322
+ ] * '',
323
+ :debug,
324
+ :magenta
325
+ )
335
326
  end
336
327
  end # Rack
337
328
  end # Logger
@@ -3,8 +3,7 @@ module Padrino
3
3
  # Represents a particular mounted padrino application
4
4
  # Stores the name of the application (app folder name) and url mount path
5
5
  #
6
- # ==== Examples
7
- #
6
+ # @example
8
7
  # Mounter.new("blog_app", :app_class => "Blog").to("/blog")
9
8
  # Mounter.new("blog_app", :app_file => "/path/to/blog/app.rb").to("/blog")
10
9
  #
@@ -14,6 +13,16 @@ module Padrino
14
13
 
15
14
  attr_accessor :name, :uri_root, :app_file, :app_class, :app_root, :app_obj, :app_host
16
15
 
16
+ ##
17
+ # @param [String, Padrino::Application] name
18
+ # The app name or the {Padrino::Application} class
19
+ #
20
+ # @param [Hash] options
21
+ # @option options [Symbol] :app_class (Detected from name)
22
+ # @option options [Symbol] :app_file (Automatically detected)
23
+ # @option options [Symbol] :app_obj (Detected)
24
+ # @option options [Symbol] :app_root (Directory of :app_file)
25
+ #
17
26
  def initialize(name, options={})
18
27
  @name = name.to_s
19
28
  @app_class = options[:app_class] || @name.camelize
@@ -28,8 +37,10 @@ module Padrino
28
37
  ##
29
38
  # Registers the mounted application onto Padrino
30
39
  #
31
- # ==== Examples
40
+ # @param [String] mount_url
41
+ # Path where we mount the app
32
42
  #
43
+ # @example
33
44
  # Mounter.new("blog_app").to("/blog")
34
45
  #
35
46
  def to(mount_url)
@@ -41,8 +52,10 @@ module Padrino
41
52
  ##
42
53
  # Registers the mounted application onto Padrino for the given host
43
54
  #
44
- # ==== Examples
55
+ # @param [String] mount_host
56
+ # Host name
45
57
  #
58
+ # @example
46
59
  # Mounter.new("blog_app").to("/blog").host("blog.padrino.org")
47
60
  # Mounter.new("blog_app").host("blog.padrino.org")
48
61
  # Mounter.new("catch_all").host(/.*\.padrino.org/)
@@ -57,17 +70,22 @@ module Padrino
57
70
  # Maps Padrino application onto a Padrino::Router
58
71
  # For use in constructing a Rack application
59
72
  #
73
+ # @param [Padrino::Router]
74
+ #
75
+ # @return [Padrino::Router]
76
+ #
77
+ # @example
60
78
  # @app.map_onto(router)
61
79
  #
62
80
  def map_onto(router)
63
81
  app_data, app_obj = self, @app_obj
64
- app_obj.set :uri_root, app_data.uri_root
65
- app_obj.set :app_name, app_data.name
66
- app_obj.set :app_file, app_data.app_file unless ::File.exist?(app_obj.app_file)
67
- app_obj.set :root, app_data.app_root unless app_data.app_root.blank?
68
- app_obj.set :public, Padrino.root('public', app_data.uri_root) unless File.exists?(app_obj.public)
69
- app_obj.set :static, File.exist?(app_obj.public) if app_obj.nil?
70
- app_obj.setup_application! # We need to initialize here the app.
82
+ app_obj.set :uri_root, app_data.uri_root
83
+ app_obj.set :app_name, app_data.name
84
+ app_obj.set :app_file, app_data.app_file unless ::File.exist?(app_obj.app_file)
85
+ app_obj.set :root, app_data.app_root unless app_data.app_root.blank?
86
+ app_obj.set :public_folder, Padrino.root('public', app_data.uri_root) unless File.exists?(app_obj.public_folder)
87
+ app_obj.set :static, File.exist?(app_obj.public_folder) if app_obj.nil?
88
+ app_obj.setup_application! # Initializes the app here with above settings.
71
89
  router.map(:to => app_obj, :path => app_data.uri_root, :host => app_data.app_host)
72
90
  end
73
91
 
@@ -81,6 +99,8 @@ module Padrino
81
99
  ###
82
100
  # Returns the basic route information for each named route
83
101
  #
102
+ # @return [Array]
103
+ # Array of routes
84
104
  #
85
105
  def named_routes
86
106
  app_obj.routes.map { |route|
@@ -95,12 +115,15 @@ module Padrino
95
115
  ##
96
116
  # Makes two Mounters equal if they have the same name and uri_root
97
117
  #
118
+ # @param [Padrino::Mounter] other
119
+ #
98
120
  def ==(other)
99
121
  other.is_a?(Mounter) && self.app_class == other.app_class && self.uri_root == other.uri_root
100
122
  end
101
123
 
102
124
  ##
103
- # Returns the class object for the app if defined, nil otherwise
125
+ # @return [Padrino::Application]
126
+ # the class object for the app if defined, nil otherwise
104
127
  #
105
128
  def app_constant
106
129
  klass = Object
@@ -160,14 +183,18 @@ module Padrino
160
183
  attr_writer :mounted_root # Set root directory where padrino searches mounted apps
161
184
 
162
185
  ##
163
- # Returns the root to the mounted apps base directory
186
+ # @param [Array] args
187
+ #
188
+ # @return [String]
189
+ # the root to the mounted apps base directory
164
190
  #
165
191
  def mounted_root(*args)
166
192
  Padrino.root(@mounted_root ||= "", *args)
167
193
  end
168
194
 
169
195
  ##
170
- # Returns the mounted padrino applications (MountedApp objects)
196
+ # @return [Array]
197
+ # the mounted padrino applications (MountedApp objects)
171
198
  #
172
199
  def mounted_apps
173
200
  @mounted_apps ||= []
@@ -176,6 +203,8 @@ module Padrino
176
203
  ##
177
204
  # Inserts a Mounter object into the mounted applications (avoids duplicates)
178
205
  #
206
+ # @param [Padrino::Mounter] mounter
207
+ #
179
208
  def insert_mounted_app(mounter)
180
209
  Padrino.mounted_apps.push(mounter) unless Padrino.mounted_apps.include?(mounter)
181
210
  end
@@ -183,6 +212,9 @@ module Padrino
183
212
  ##
184
213
  # Mounts a new sub-application onto Padrino project
185
214
  #
215
+ # @see Padrino::Mounter#new
216
+ #
217
+ # @example
186
218
  # Padrino.mount("blog_app").to("/blog")
187
219
  #
188
220
  def mount(name, options={})
@@ -39,6 +39,7 @@ module Padrino
39
39
  def include_constants
40
40
  @_include_constants ||= []
41
41
  end
42
+
42
43
  ##
43
44
  # Reload all files with changes detected.
44
45
  #
@@ -107,6 +108,7 @@ module Padrino
107
108
  # A safe Kernel::require which issues the necessary hooks depending on results
108
109
  #
109
110
  def safe_load(file, options={})
111
+ began_at = Time.now
110
112
  force, file = options[:force], figure_path(file)
111
113
 
112
114
  # Check if file was changed or if force a reload
@@ -134,8 +136,8 @@ module Padrino
134
136
 
135
137
  # And finally load the specified file
136
138
  begin
137
- logger.devel "Loading #{file}" if !reload
138
- logger.debug "Reloading #{file}" if reload
139
+ logger.devel :loading, began_at, file if !reload
140
+ logger.debug :reload, began_at, file if reload
139
141
  $LOADED_FEATURES.delete(file)
140
142
  verbosity_was, $-v = $-v, nil
141
143
  loaded = false
@@ -143,7 +145,7 @@ module Padrino
143
145
  loaded = true
144
146
  MTIMES[file] = File.mtime(file)
145
147
  rescue SyntaxError => e
146
- logger.error "Cannot require #{file} because of syntax error: #{e.message}"
148
+ logger.error "Cannot require #{file} due to a syntax error: #{e.message}"
147
149
  ensure
148
150
  $-v = verbosity_was
149
151
  new_constants = (ObjectSpace.classes - klasses).uniq