padrino-core 0.12.8.1 → 0.12.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +13 -5
  2. data/Rakefile +1 -5
  3. data/bin/padrino +1 -1
  4. data/lib/padrino-core/application/application_setup.rb +2 -0
  5. data/lib/padrino-core/application/params_protection.rb +1 -7
  6. data/lib/padrino-core/application/routing.rb +15 -5
  7. data/lib/padrino-core/caller.rb +2 -1
  8. data/lib/padrino-core/cli/adapter.rb +11 -2
  9. data/lib/padrino-core/cli/base.rb +12 -8
  10. data/lib/padrino-core/cli/launcher.rb +12 -4
  11. data/lib/padrino-core/cli/rake_tasks.rb +24 -14
  12. data/lib/padrino-core/configuration.rb +40 -0
  13. data/lib/padrino-core/loader.rb +1 -2
  14. data/lib/padrino-core/logger.rb +71 -11
  15. data/lib/padrino-core/mounter/application_extension.rb +55 -0
  16. data/lib/padrino-core/mounter.rb +21 -62
  17. data/lib/padrino-core/reloader/rack.rb +4 -1
  18. data/lib/padrino-core/reloader/storage.rb +31 -3
  19. data/lib/padrino-core/reloader.rb +4 -2
  20. data/lib/padrino-core/version.rb +1 -1
  21. data/lib/padrino-core.rb +2 -0
  22. data/padrino-core.gemspec +1 -7
  23. data/test/fixtures/apps/custom_dependencies/custom_dependencies.rb +11 -0
  24. data/test/fixtures/apps/custom_dependencies/my_dependencies/my_dependency.rb +0 -0
  25. data/test/fixtures/apps/external_apps/fake_lib.rb +1 -0
  26. data/test/fixtures/apps/external_apps/fake_root.rb +2 -0
  27. data/test/fixtures/apps/rack_apps.rb +4 -0
  28. data/test/fixtures/apps/simple.rb +0 -1
  29. data/test/fixtures/apps/system.rb +2 -0
  30. data/test/helper.rb +4 -26
  31. data/test/test_application.rb +8 -0
  32. data/test/test_configuration.rb +29 -0
  33. data/test/test_core.rb +12 -0
  34. data/test/test_csrf_protection.rb +7 -6
  35. data/test/test_logger.rb +93 -0
  36. data/test/test_mounter.rb +15 -0
  37. data/test/test_params_protection.rb +15 -15
  38. data/test/test_reloader_simple.rb +2 -2
  39. data/test/test_reloader_storage.rb +51 -0
  40. data/test/test_reloader_system.rb +20 -0
  41. data/test/test_routing.rb +31 -2
  42. metadata +49 -46
  43. data/test/fixtures/apps/helpers/support.rb +0 -1
checksums.yaml CHANGED
@@ -1,7 +1,15 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 425a55cbc0605fb327daf1966a465f91d1625f27
4
- data.tar.gz: cec37ed3c36d612e541c28368d43970f2f45a47d
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ Zjc3MmQyN2MyYjcyOTU2N2YyYTE0YWJmZTExM2MxODAwZTYwNTEyMg==
5
+ data.tar.gz: !binary |-
6
+ ZGYwNjcyNDY1YTRkMjFlOGU5YTUwNjZiNTUwNzhjNTljNDczMzkwOA==
5
7
  SHA512:
6
- metadata.gz: 63e08191427c3a2f6c0054122efd63e1161f2d7563e14354fbcef1251bfff0971ca554532eaf4277b4b5101704a17b3cacfdad6d2d69e8e1d85802c63a12b9e8
7
- data.tar.gz: 3bdd7a9d40c00e9815115bbad4d032b6271addee919cb48a794922f82a3764b3249cf26efcdbe8dbd8aaf6341c0320ba7bf5c3380f0ae802d787d30c01cd9fe8
8
+ metadata.gz: !binary |-
9
+ YTM0ZjYxOThkNGViZjhmYzI1YzdmYjk4MTBjOTIxOGQzYTYyYWM3ODczMjlj
10
+ MTkzOTM5ZDQ0YjMzMWQ2Nzg0YjkwN2Q2ZGMyMTE3ZTQ2NzdkMTg5NDA0MTdm
11
+ N2Y1Mzk0YTgwMmYyN2Y2MTRhODhlNjliMjUzZDI1MjU0NmExNmM=
12
+ data.tar.gz: !binary |-
13
+ OTRhOTFhZGYzN2M2MmZjYzBjNTIxNzdhNWE2MWFlM2E5MTY1YjExM2ZmNDUw
14
+ ODgyODU1NmZhNjZlMjZmNTNkMjE3ZTQ1OWUxMGNlY2E2NzFkODU0MWUzNGFi
15
+ NmZlZjc4NDYyZmY4ODdlNTBkMDZiNGQzNjllYjMzMmM5MDFjYmY=
data/Rakefile CHANGED
@@ -1,5 +1 @@
1
- # coding:utf-8
2
- RAKE_ROOT = __FILE__
3
-
4
- require 'rubygems'
5
- require File.expand_path(File.dirname(__FILE__) + '/../gem_rake_helper')
1
+ require File.expand_path(File.dirname(__FILE__) + '/../gem_rake_helper')
data/bin/padrino CHANGED
@@ -6,4 +6,4 @@ padrino_core_path = File.expand_path('../../lib', __FILE__)
6
6
  $:.unshift(padrino_core_path) if File.directory?(padrino_core_path) && !$:.include?(padrino_core_path)
7
7
 
8
8
  require 'padrino-core/cli/base'
9
- Padrino::Cli::Base.start(ARGV)
9
+ Padrino::Cli::Base.start(ARGV)
@@ -57,6 +57,7 @@ module Padrino
57
57
  set :uri_root, '/'
58
58
  set :public_folder, proc { Padrino.root('public', uri_root) }
59
59
  set :images_path, proc { File.join(public_folder, 'images') }
60
+ set :base_url, 'http://localhost'
60
61
  end
61
62
 
62
63
  def default_security
@@ -97,6 +98,7 @@ module Padrino
97
98
  # Also initializes the application after setting up the middleware.
98
99
  def setup_default_middleware(builder)
99
100
  setup_sessions builder
101
+ builder.use Sinatra::ExtendedRack if defined?(EventMachine)
100
102
  builder.use Padrino::ShowExceptions if show_exceptions?
101
103
  builder.use Padrino::Logger::Rack, uri_root if Padrino.logger && logging?
102
104
  builder.use Padrino::Reloader::Rack if reload?
@@ -1,9 +1,3 @@
1
- begin
2
- require 'active_support/core_ext/object/deep_dup' # AS 4.1
3
- rescue LoadError
4
- require 'active_support/core_ext/hash/deep_dup' # AS >= 3.1
5
- end
6
-
7
1
  module Padrino
8
2
  ##
9
3
  # Padrino application module providing means for mass-assignment protection.
@@ -45,7 +39,7 @@ module Padrino
45
39
  def params(*allowed_params)
46
40
  allowed_params = prepare_allowed_params(allowed_params)
47
41
  condition do
48
- @original_params = params.deep_dup
42
+ @original_params = Utils.deep_dup(params)
49
43
  filter_params!(params, allowed_params)
50
44
  end
51
45
  end
@@ -340,6 +340,14 @@ module Padrino
340
340
  end
341
341
  alias :url_for :url
342
342
 
343
+ ##
344
+ # Returns absolute url. By default adds 'http://localhost' before generated url.
345
+ # To change that `set :base_url, 'http://example.com'` in your app.
346
+ #
347
+ def absolute_url(*args)
348
+ base_url + url(*args)
349
+ end
350
+
343
351
  def get(path, *args, &block)
344
352
  conditions = @conditions.dup
345
353
  route('GET', path, *args, &block)
@@ -562,6 +570,7 @@ module Padrino
562
570
  # controllers, parents, 'with' parameters, and other options.
563
571
  #
564
572
  def parse_route(path, options, verb)
573
+ path = path.dup if path.kind_of?(String)
565
574
  route_options = {}
566
575
 
567
576
  if options[:params] == true
@@ -714,7 +723,7 @@ module Padrino
714
723
 
715
724
  accept_format = CONTENT_TYPE_ALIASES[type] || type
716
725
  if types.include?(accept_format)
717
- content_type(accept_format || :html, :charset => 'utf-8')
726
+ content_type(accept_format || :html)
718
727
  else
719
728
  catch_all ? true : halt(406)
720
729
  end
@@ -734,7 +743,7 @@ module Padrino
734
743
  mime_types = types.map{ |type| mime_type(CONTENT_TYPE_ALIASES[type] || type) }
735
744
  condition do
736
745
  halt 406 unless mime_types.include?(request.media_type)
737
- content_type(mime_symbol(request.media_type), :charset => 'utf-8')
746
+ content_type(mime_symbol(request.media_type))
738
747
  end
739
748
  end
740
749
 
@@ -877,7 +886,6 @@ module Padrino
877
886
  #
878
887
  def content_type(type=nil, params={})
879
888
  return @_content_type unless type
880
- params.delete(:charset) if type == :json
881
889
  super(type, params)
882
890
  @_content_type = type
883
891
  end
@@ -887,7 +895,7 @@ module Padrino
887
895
  def provides_any?(formats)
888
896
  accepted_format = formats.first
889
897
  type = accepted_format ? mime_symbol(accepted_format) : :html
890
- content_type(CONTENT_TYPE_ALIASES[type] || type, :charset => 'utf-8')
898
+ content_type(CONTENT_TYPE_ALIASES[type] || type)
891
899
  end
892
900
 
893
901
  def provides_format?(types, format)
@@ -897,7 +905,7 @@ module Padrino
897
905
  halt 406 if settings.respond_to?(:treat_format_as_accept) && settings.treat_format_as_accept
898
906
  false
899
907
  else
900
- content_type(format || :html, :charset => 'utf-8')
908
+ content_type(format || :html)
901
909
  end
902
910
  end
903
911
 
@@ -910,6 +918,8 @@ module Padrino
910
918
  end
911
919
 
912
920
  def dispatch!
921
+ @params = defined?(Sinatra::IndifferentHash) ? Sinatra::IndifferentHash[@request.params] : indifferent_params(@request.params)
922
+ force_encoding(@params)
913
923
  invoke do
914
924
  static! if settings.static? && (request.get? || request.head?)
915
925
  route!
@@ -18,7 +18,8 @@ module Padrino
18
18
  %r{rake_test_loader\.rb},
19
19
  %r{custom_require\.rb$},
20
20
  %r{active_support},
21
- %r{/thor}
21
+ %r{/thor},
22
+ %r{/lib/bundler},
22
23
  ] unless defined?(PADRINO_IGNORE_CALLERS)
23
24
 
24
25
  ##
@@ -12,10 +12,19 @@ module Padrino
12
12
  options.symbolize_keys!
13
13
  if File.exist?(options[:pid])
14
14
  pid = File.read(options[:pid]).to_i
15
- print "=> Sending INT to process with pid #{pid} wait "
16
- Process.kill(2, pid) rescue nil
15
+ puts "=> Sending INT to process with pid #{pid}"
16
+ begin
17
+ Process.kill(2, pid)
18
+ rescue Errno::ESRCH, RangeError => error
19
+ puts error.message
20
+ exit
21
+ rescue Errno::EPERM => error
22
+ puts error.message
23
+ abort
24
+ end
17
25
  else
18
26
  puts "=> #{options[:pid]} not found!"
27
+ abort
19
28
  end
20
29
  end
21
30
  end
@@ -4,7 +4,7 @@ module Padrino
4
4
  module Cli
5
5
  class Base < Launcher
6
6
  desc "rake", "Execute rake tasks."
7
- method_option :environment, :type => :string, :aliases => "-e", :required => true, :default => :development
7
+ method_option :environment, :type => :string, :aliases => "-e"
8
8
  method_option :list, :type => :string, :aliases => "-T", :desc => "Display the tasks (matching optional PATTERN) with descriptions, then exit."
9
9
  method_option :trace, :type => :boolean, :aliases => "-t", :desc => "Turn on invoke/execute tracing, enable full backtrace."
10
10
  def rake(*args)
@@ -28,16 +28,20 @@ module Padrino
28
28
  def console(*args)
29
29
  prepare :console
30
30
  require File.expand_path("../../version", __FILE__)
31
- ARGV.clear
32
- require 'irb'
33
- begin
34
- require "irb/completion"
35
- rescue LoadError
36
- end
37
31
  require File.expand_path('config/boot.rb')
38
32
  puts "=> Loading #{Padrino.env} console (Padrino v.#{Padrino.version})"
39
33
  require File.expand_path('../console', __FILE__)
40
- IRB.start
34
+ ARGV.clear
35
+ if defined? Pry
36
+ Pry.start
37
+ else
38
+ require 'irb'
39
+ begin
40
+ require "irb/completion"
41
+ rescue LoadError
42
+ end
43
+ IRB.start
44
+ end
41
45
  end
42
46
 
43
47
  desc "generate", "Executes the Padrino generator with given options (alternatively use 'gen' or 'g')."
@@ -6,7 +6,7 @@ module Padrino
6
6
  include Thor::Actions
7
7
 
8
8
  class_option :chdir, :type => :string, :aliases => "-c", :desc => "Change to dir before starting."
9
- class_option :environment, :type => :string, :aliases => "-e", :required => true, :default => :development, :desc => "Padrino Environment."
9
+ class_option :environment, :type => :string, :aliases => "-e", :desc => "Padrino Environment."
10
10
  class_option :help, :type => :boolean, :desc => "Show help usage"
11
11
 
12
12
  desc "start", "Starts the Padrino application (alternatively use 's')."
@@ -70,13 +70,17 @@ module Padrino
70
70
  def prepare(task)
71
71
  if options.help?
72
72
  help(task.to_s)
73
- raise SystemExit
73
+ exit
74
+ end
75
+ if options.environment
76
+ ENV["RACK_ENV"] = options.environment.to_s
77
+ else
78
+ ENV["RACK_ENV"] ||= 'development'
74
79
  end
75
- ENV["RACK_ENV"] ||= options.environment.to_s
76
80
  chdir(options.chdir)
77
81
  unless File.exist?('config/boot.rb')
78
82
  puts "=> Could not find boot file in: #{options.chdir}/config/boot.rb !!!"
79
- raise SystemExit
83
+ abort
80
84
  end
81
85
  end
82
86
 
@@ -90,6 +94,10 @@ module Padrino
90
94
  puts "=> Specified Padrino root '#{dir}' cannot be accessed by the current user!"
91
95
  end
92
96
  end
97
+
98
+ def self.exit_on_failure?
99
+ true
100
+ end
93
101
  end
94
102
  end
95
103
  end
@@ -1,11 +1,3 @@
1
- Dir["{lib/tasks/**,tasks/**,test,spec}/*.rake"].each do |file|
2
- begin
3
- load(File.expand_path(file))
4
- rescue LoadError => e
5
- warn "#{file}: #{e.message}"
6
- end
7
- end
8
-
9
1
  # Loads the Padrino applications mounted within the project.
10
2
  # Setting up the required environment for Padrino.
11
3
  task :environment do
@@ -16,13 +8,10 @@ task :environment do
16
8
  end
17
9
  end
18
10
 
19
- # Loads skeleton Padrino environment, no models, no application settings.
20
11
  task :skeleton do
21
- module Padrino::Reloader
22
- def self.safe_load(file, options)
23
- super unless file.include?('/models/')
24
- end
25
- end
12
+ PADRINO_ROOT ||= Rake.application.original_dir
13
+ require 'padrino-core'
14
+ Padrino.send(:dependency_paths).reject!{ |path| path.include?('/models/') }
26
15
  require File.expand_path('config/boot.rb', Rake.application.original_dir)
27
16
  end
28
17
 
@@ -46,6 +35,19 @@ def list_app_routes(app, args)
46
35
  end
47
36
  end
48
37
 
38
+ def env_migration_version
39
+ version = ENV["MIGRATION_VERSION"]
40
+ if version.nil? && ENV["VERSION"]
41
+ deprecated = true
42
+ warn "Environment variable VERSION is deprecated, use MIGRATION_VERSION"
43
+ version = ENV["VERSION"]
44
+ end
45
+ version ? Integer(version) : nil
46
+ rescue ArgumentError
47
+ warn "Environment variable #{deprecated ? '' : 'MIGRATION_'}VERSION=#{version} should be non-existant or Integer"
48
+ nil
49
+ end
50
+
49
51
  desc "Displays a listing of the named routes within a project, optionally only those matched by [query]"
50
52
  task :routes, [:query] => :environment do |t, args|
51
53
  Padrino.mounted_apps.each do |app|
@@ -60,3 +62,11 @@ namespace :routes do
60
62
  list_app_routes(app, args) if app
61
63
  end
62
64
  end
65
+
66
+ Dir["{lib/tasks/**,tasks/**,test,spec}/*.rake"].each do |file|
67
+ begin
68
+ load(File.expand_path(file))
69
+ rescue LoadError => e
70
+ warn "#{file}: #{e.message}"
71
+ end
72
+ end
@@ -0,0 +1,40 @@
1
+ require 'ostruct'
2
+
3
+ module Padrino
4
+ ##
5
+ # Padrino simple configuration module
6
+ #
7
+ module Configuration
8
+ ##
9
+ # Returns the configuration structure allowing to get and set it's values.
10
+ # Padrino.config is a simple Ruby OpenStruct object with no additional magic.
11
+ #
12
+ # Example:
13
+ #
14
+ # Padrino.config.value1 = 42
15
+ # exit if Padrino.config.exiting
16
+ #
17
+ def config
18
+ @config ||= OpenStruct.new
19
+ end
20
+
21
+ ##
22
+ # Allows to configure different environments differently. Requires a block.
23
+ #
24
+ # Example:
25
+ #
26
+ # Padrino.configure :development do |config|
27
+ # config.value2 = 'only development'
28
+ # end
29
+ # Padrino.configure :development, :production do |config|
30
+ # config.value2 = 'both development and production'
31
+ # end
32
+ # Padrino.configure do |config|
33
+ # config.value2 = 'any environment'
34
+ # end
35
+ #
36
+ def configure(*environments)
37
+ yield(config) if environments.empty? || environments.include?(Padrino.env)
38
+ end
39
+ end
40
+ end
@@ -193,8 +193,7 @@ module Padrino
193
193
  "#{root}/config/database.rb",
194
194
  "#{root}/lib/**/*.rb",
195
195
  "#{root}/models/**/*.rb",
196
- "#{root}/shared/lib/**/*.rb",
197
- "#{root}/shared/models/**/*.rb",
196
+ "#{root}/shared/**/*.rb",
198
197
  "#{root}/config/apps.rb",
199
198
  ]
200
199
  end
@@ -1,3 +1,5 @@
1
+ require 'pathname'
2
+
1
3
  # Defines the log level for a Padrino project.
2
4
  PADRINO_LOG_LEVEL = ENV['PADRINO_LOG_LEVEL'] unless defined?(PADRINO_LOG_LEVEL)
3
5
 
@@ -70,6 +72,9 @@ module Padrino
70
72
  if args.size > 1
71
73
  bench(args[0], args[1], args[2], name)
72
74
  else
75
+ if location = resolve_source_location(caller(1).shift)
76
+ args.unshift(location)
77
+ end if enable_source_location?
73
78
  push(args * '', name)
74
79
  end
75
80
  end
@@ -79,6 +84,28 @@ module Padrino
79
84
  end
80
85
  end
81
86
 
87
+ SOURCE_LOCATION_REGEXP = /^(.*?):(\d+?)(?::in `.+?')?$/.freeze
88
+
89
+ ##
90
+ # Returns true if :source_location is set to true.
91
+ #
92
+ def enable_source_location?
93
+ respond_to?(:source_location?) && source_location?
94
+ end
95
+
96
+ ##
97
+ # Resolves a filename and line-number from caller.
98
+ #
99
+ def resolve_source_location(message)
100
+ path, line = *message.scan(SOURCE_LOCATION_REGEXP).first
101
+ return unless path && line
102
+ root = Padrino.root
103
+ path = File.realpath(path) if Pathname.new(path).relative?
104
+ if path.start_with?(root) && !path.start_with?(Padrino.root("vendor"))
105
+ "[#{path.gsub("#{root}/", "")}:#{line}] "
106
+ end
107
+ end
108
+
82
109
  ##
83
110
  # Append a to development logger a given action with time.
84
111
  #
@@ -237,6 +264,9 @@ module Padrino
237
264
  #
238
265
  # :log_level:: Once of [:fatal, :error, :warn, :info, :debug]
239
266
  # :stream:: Once of [:to_file, :null, :stdout, :stderr] our your custom stream
267
+ # :log_path:: Defines log file path or directory if :stream is :to_file
268
+ # If it's a file, its location is created by mkdir_p.
269
+ # If it's a directory, it must exist. In this case log name is '<env>.log'
240
270
  # :log_level::
241
271
  # The log level from, e.g. :fatal or :info. Defaults to :warn in the
242
272
  # production environment and :debug otherwise.
@@ -252,6 +282,10 @@ module Padrino
252
282
  # Padrino::Logger::Config[:development] = { :log_level => :debug, :stream => :to_file }
253
283
  # # or you can edit our defaults
254
284
  # Padrino::Logger::Config[:development][:log_level] = :error
285
+ # # or change log file path
286
+ # Padrino::Logger::Config[:development][:log_path] = 'logs/app-development.txt'
287
+ # # or change log file directory
288
+ # Padrino::Logger::Config[:development][:log_path] = '/var/logs/padrino'
255
289
  # # or you can use your stream
256
290
  # Padrino::Logger::Config[:development][:stream] = StringIO.new
257
291
  #
@@ -302,8 +336,18 @@ module Padrino
302
336
 
303
337
  stream = case config[:stream]
304
338
  when :to_file
305
- FileUtils.mkdir_p(Padrino.root('log')) unless File.exist?(Padrino.root('log'))
306
- File.new(Padrino.root('log', "#{Padrino.env}.log"), 'a+')
339
+ if filename = config[:log_path]
340
+ filename = Padrino.root(filename) unless Pathname.new(filename).absolute?
341
+ if File.directory?(filename)
342
+ filename = File.join(filename, "#{Padrino.env}.log")
343
+ else
344
+ FileUtils.mkdir_p(File.dirname(filename))
345
+ end
346
+ File.new(filename, 'a+')
347
+ else
348
+ FileUtils.mkdir_p(Padrino.root('log')) unless File.exist?(Padrino.root('log'))
349
+ File.new(Padrino.root('log', "#{Padrino.env}.log"), 'a+')
350
+ end
307
351
  when :null then StringIO.new
308
352
  when :stdout then $stdout
309
353
  when :stderr then $stderr
@@ -341,26 +385,42 @@ module Padrino
341
385
  # @option options [Symbol] :colorize_logging (true)
342
386
  # Whether or not to colorize log messages. Defaults to: true.
343
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
+ #
344
394
  def initialize(options={})
345
- @buffer = []
346
- @auto_flush = options.has_key?(:auto_flush) ? options[:auto_flush] : true
347
- @level = options[:log_level] ? Padrino::Logger::Levels[options[:log_level]] : Padrino::Logger::Levels[:debug]
348
- @log = options[:stream] || $stdout
349
- @log.sync = true
350
- @format_datetime = options[:format_datetime] || "%d/%b/%Y %H:%M:%S"
351
- @format_message = options[:format_message] || "%s - %s %s"
352
- @log_static = options.has_key?(:log_static) ? options[:log_static] : false
395
+ @buffer = []
396
+ @auto_flush = options.has_key?(:auto_flush) ? options[:auto_flush] : true
397
+ @level = options[:log_level] ? Padrino::Logger::Levels[options[:log_level]] : Padrino::Logger::Levels[:debug]
398
+ @log = options[:stream] || $stdout
399
+ @log.sync = true
400
+ @format_datetime = options[:format_datetime] || "%d/%b/%Y %H:%M:%S"
401
+ @format_message = options[:format_message] || "%s - %s %s"
402
+ @log_static = options.has_key?(:log_static) ? options[:log_static] : false
353
403
  @colorize_logging = options.has_key?(:colorize_logging) ? options[:colorize_logging] : true
404
+ @source_location = options[:source_location]
405
+ @sanitize_encoding = options[:sanitize_encoding] || false
406
+ @sanitize_encoding = Encoding.default_external if @sanitize_encoding == true
354
407
  colorize! if @colorize_logging
355
408
  end
356
409
 
410
+ def source_location?
411
+ !!@source_location
412
+ end
413
+
357
414
  ##
358
415
  # Flush the entire buffer to the log object.
359
416
  #
360
417
  def flush
361
418
  return unless @buffer.size > 0
362
419
  @@mutex.synchronize do
363
- @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
364
424
  @buffer.clear
365
425
  end
366
426
  end
@@ -0,0 +1,55 @@
1
+ module Padrino
2
+ class Mounter
3
+ module ApplicationExtension
4
+ attr_accessor :uri_root, :mounter_options
5
+ attr_writer :public_folder
6
+
7
+ def dependencies
8
+ @__dependencies ||= Dir.glob("#{root}/**/*.rb").delete_if { |path| path == app_file }
9
+ end
10
+
11
+ def prerequisites
12
+ @__prerequisites ||= []
13
+ end
14
+
15
+ def app_file
16
+ @__app_file ||= trace_method(:app_file) { mounter_options[:app_file] }
17
+ end
18
+
19
+ def root
20
+ @__root ||= trace_method(:root) { File.expand_path("#{app_file}/../") }
21
+ end
22
+
23
+ def public_folder
24
+ @public_folder ||= trace_method(:public_folder) { "" }
25
+ end
26
+
27
+ def app_name
28
+ @__app_name ||= mounter_options[:app_name] || self.to_s.underscore.to_sym
29
+ end
30
+
31
+ def setup_application!
32
+ @configured ||= trace_method(:setup_application!) do
33
+ $LOAD_PATH.concat(prerequisites)
34
+ require_dependencies if root.start_with?(Padrino.root)
35
+ true
36
+ end
37
+ end
38
+
39
+ private
40
+
41
+ def require_dependencies
42
+ Padrino.require_dependencies(dependencies, :force => true)
43
+ end
44
+
45
+ def trace_method(method_name)
46
+ value = baseclass.send(method_name) if baseclass != self && baseclass.respond_to?(method_name)
47
+ value || yield
48
+ end
49
+
50
+ def baseclass
51
+ @__baseclass ||= respond_to?(:superclass) ? superclass : self
52
+ end
53
+ end
54
+ end
55
+ end