padrino-core 0.16.0.pre4 → 0.16.0
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.
- checksums.yaml +4 -4
- data/README.rdoc +8 -8
- data/Rakefile +1 -1
- data/bin/padrino +1 -1
- data/lib/padrino-core/application/application_setup.rb +28 -26
- data/lib/padrino-core/application/authenticity_token.rb +3 -2
- data/lib/padrino-core/application/flash.rb +4 -5
- data/lib/padrino-core/application/params_protection.rb +34 -37
- data/lib/padrino-core/application/routing.rb +165 -164
- data/lib/padrino-core/application/show_exceptions.rb +5 -7
- data/lib/padrino-core/application.rb +4 -4
- data/lib/padrino-core/caller.rb +6 -7
- data/lib/padrino-core/cli/adapter.rb +4 -4
- data/lib/padrino-core/cli/base.rb +31 -32
- data/lib/padrino-core/cli/binstub.rb +9 -8
- data/lib/padrino-core/cli/console.rb +1 -1
- data/lib/padrino-core/cli/launcher.rb +45 -42
- data/lib/padrino-core/cli/rake.rb +16 -14
- data/lib/padrino-core/cli/rake_tasks.rb +18 -20
- data/lib/padrino-core/command.rb +1 -1
- data/lib/padrino-core/ext/sinatra.rb +3 -2
- data/lib/padrino-core/filter.rb +3 -3
- data/lib/padrino-core/loader.rb +10 -12
- data/lib/padrino-core/logger.rb +85 -77
- data/lib/padrino-core/mounter/application_extension.rb +2 -2
- data/lib/padrino-core/mounter.rb +33 -34
- data/lib/padrino-core/path_router/compiler.rb +8 -8
- data/lib/padrino-core/path_router/matcher.rb +11 -11
- data/lib/padrino-core/path_router/route.rb +15 -15
- data/lib/padrino-core/path_router.rb +4 -3
- data/lib/padrino-core/reloader/rack.rb +1 -1
- data/lib/padrino-core/reloader/storage.rb +12 -11
- data/lib/padrino-core/reloader.rb +18 -19
- data/lib/padrino-core/router.rb +14 -14
- data/lib/padrino-core/server.rb +20 -24
- data/lib/padrino-core/tasks.rb +0 -1
- data/lib/padrino-core/version.rb +1 -1
- data/lib/padrino-core.rb +9 -10
- data/padrino-core.gemspec +18 -18
- data/test/fixtures/app_gem/app_gem.gemspec +8 -7
- data/test/fixtures/app_gem/lib/app_gem/version.rb +1 -1
- data/test/fixtures/apps/complex.rb +6 -6
- data/test/fixtures/apps/concerned/app.rb +1 -1
- data/test/fixtures/apps/custom_dependencies/custom_dependencies.rb +3 -3
- data/test/fixtures/apps/demo_app.rb +1 -1
- data/test/fixtures/apps/demo_demo.rb +1 -1
- data/test/fixtures/apps/demo_project/api/app.rb +1 -1
- data/test/fixtures/apps/demo_project/app.rb +1 -1
- data/test/fixtures/apps/helpers/class_methods_helpers.rb +1 -0
- data/test/fixtures/apps/helpers/instance_methods_helpers.rb +1 -0
- data/test/fixtures/apps/helpers/system_helpers.rb +0 -1
- data/test/fixtures/apps/lib/myklass/mysubklass.rb +2 -2
- data/test/fixtures/apps/mountable_apps/rack_apps.rb +7 -7
- data/test/fixtures/apps/precompiled_app.rb +6 -5
- data/test/fixtures/apps/simple.rb +5 -5
- data/test/fixtures/apps/static.rb +2 -2
- data/test/fixtures/apps/stealthy/app.rb +1 -1
- data/test/fixtures/apps/stealthy/helpers/stealthy_class_helpers.rb +1 -1
- data/test/fixtures/apps/system.rb +1 -1
- data/test/fixtures/apps/system_class_methods_demo.rb +1 -1
- data/test/fixtures/apps/system_instance_methods_demo.rb +1 -1
- data/test/fixtures/dependencies/a.rb +1 -1
- data/test/fixtures/dependencies/b.rb +1 -1
- data/test/fixtures/dependencies/c.rb +1 -1
- data/test/fixtures/dependencies/circular/e.rb +2 -1
- data/test/fixtures/dependencies/d.rb +1 -1
- data/test/fixtures/dependencies/linear/i.rb +1 -1
- data/test/fixtures/dependencies/nested/l.rb +2 -2
- data/test/fixtures/dependencies/nested/m.rb +1 -1
- data/test/fixtures/dependencies/nested/qqq.rb +2 -2
- data/test/fixtures/dependencies/nested/rrr.rb +1 -1
- data/test/fixtures/dependencies/nested/sss.rb +1 -1
- data/test/fixtures/reloadable_apps/external/app/app.rb +0 -1
- data/test/fixtures/reloadable_apps/external/app/controllers/base.rb +1 -2
- data/test/fixtures/reloadable_apps/main/app.rb +2 -2
- data/test/helper.rb +2 -2
- data/test/test_application.rb +59 -60
- data/test/test_configuration.rb +2 -2
- data/test/test_core.rb +13 -13
- data/test/test_csrf_protection.rb +67 -63
- data/test/test_dependencies.rb +33 -34
- data/test/test_filters.rb +46 -47
- data/test/test_flash.rb +14 -14
- data/test/test_locale.rb +2 -2
- data/test/test_logger.rb +64 -64
- data/test/test_mounter.rb +133 -123
- data/test/test_params_protection.rb +40 -40
- data/test/test_reloader_complex.rb +23 -23
- data/test/test_reloader_external.rb +10 -10
- data/test/test_reloader_simple.rb +26 -23
- data/test/test_reloader_storage.rb +9 -12
- data/test/test_reloader_system.rb +29 -29
- data/test/test_restful_routing.rb +19 -19
- data/test/test_router.rb +126 -145
- data/test/test_routing.rb +882 -894
- metadata +6 -6
|
@@ -7,14 +7,12 @@ module Padrino
|
|
|
7
7
|
private
|
|
8
8
|
|
|
9
9
|
def frame_class(frame)
|
|
10
|
-
if frame.filename =~ /
|
|
11
|
-
|
|
12
|
-
elsif (defined?(Gem) && frame.filename.include?(Gem.dir)) ||
|
|
13
|
-
|
|
14
|
-
frame.filename =~ /Ruby\/Gems/
|
|
15
|
-
"system"
|
|
10
|
+
if frame.filename =~ %r{lib/sinatra.*\.rb|lib/padrino.*\.rb}
|
|
11
|
+
'framework'
|
|
12
|
+
elsif (defined?(Gem) && frame.filename.include?(Gem.dir)) || frame.filename =~ %r{/bin/(\w+)$|Ruby/Gems}
|
|
13
|
+
'system'
|
|
16
14
|
else
|
|
17
|
-
|
|
15
|
+
'app'
|
|
18
16
|
end
|
|
19
17
|
end
|
|
20
18
|
end
|
|
@@ -54,7 +54,7 @@ module Padrino
|
|
|
54
54
|
logger.devel "Reloading application #{settings}"
|
|
55
55
|
reset!
|
|
56
56
|
reset_router!
|
|
57
|
-
Padrino.require_dependencies(settings.app_file, :
|
|
57
|
+
Padrino.require_dependencies(settings.app_file, force: true)
|
|
58
58
|
require_dependencies
|
|
59
59
|
default_routes
|
|
60
60
|
default_errors
|
|
@@ -112,7 +112,7 @@ module Padrino
|
|
|
112
112
|
#
|
|
113
113
|
# @see Padrino::Server#start
|
|
114
114
|
#
|
|
115
|
-
def run!(options={})
|
|
115
|
+
def run!(options = {})
|
|
116
116
|
return unless Padrino.load!
|
|
117
117
|
Padrino.mount(settings.to_s).to('/')
|
|
118
118
|
Padrino.run!(options)
|
|
@@ -139,7 +139,7 @@ module Padrino
|
|
|
139
139
|
'controllers.rb',
|
|
140
140
|
'helpers/**/*.rb',
|
|
141
141
|
'helpers.rb'
|
|
142
|
-
].flat_map{ |file| Dir.glob(File.join(settings.root, file)) }
|
|
142
|
+
].flat_map { |file| Dir.glob(File.join(settings.root, file)) }
|
|
143
143
|
end
|
|
144
144
|
|
|
145
145
|
##
|
|
@@ -171,7 +171,7 @@ module Padrino
|
|
|
171
171
|
# Requires all files within the application load paths.
|
|
172
172
|
#
|
|
173
173
|
def require_dependencies
|
|
174
|
-
Padrino.require_dependencies(dependencies, :
|
|
174
|
+
Padrino.require_dependencies(dependencies, force: true)
|
|
175
175
|
end
|
|
176
176
|
end
|
|
177
177
|
end
|
data/lib/padrino-core/caller.rb
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
module Padrino
|
|
2
|
-
|
|
3
2
|
unless defined?(PADRINO_IGNORE_CALLERS)
|
|
4
3
|
# List of callers in a Padrino application that should be ignored as part of a stack trace.
|
|
5
4
|
PADRINO_IGNORE_CALLERS = [
|
|
@@ -15,8 +14,8 @@ module Padrino
|
|
|
15
14
|
%r{shoulda/context\.rb$},
|
|
16
15
|
%r{mocha/integration},
|
|
17
16
|
%r{test/unit},
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
/rake_test_loader\.rb/,
|
|
18
|
+
/custom_require\.rb$/,
|
|
20
19
|
%r{/thor}
|
|
21
20
|
]
|
|
22
21
|
|
|
@@ -44,9 +43,9 @@ module Padrino
|
|
|
44
43
|
# The files of the calling methods.
|
|
45
44
|
#
|
|
46
45
|
def self.caller_files
|
|
47
|
-
caller(1).
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
46
|
+
caller(1).each_with_object([]) do |line, result|
|
|
47
|
+
file, = line.split(/:(?=\d|in )/)[0, 2]
|
|
48
|
+
result << file unless PADRINO_IGNORE_CALLERS.any? { |pattern| file =~ pattern }
|
|
49
|
+
end
|
|
51
50
|
end
|
|
52
51
|
end
|
|
@@ -17,11 +17,11 @@ module Padrino
|
|
|
17
17
|
puts "=> Sending INT to process with pid #{pid}"
|
|
18
18
|
begin
|
|
19
19
|
Process.kill(2, pid)
|
|
20
|
-
rescue Errno::ESRCH, RangeError =>
|
|
21
|
-
puts
|
|
20
|
+
rescue Errno::ESRCH, RangeError => e
|
|
21
|
+
puts e.message
|
|
22
22
|
exit
|
|
23
|
-
rescue Errno::EPERM =>
|
|
24
|
-
puts
|
|
23
|
+
rescue Errno::EPERM => e
|
|
24
|
+
puts e.message
|
|
25
25
|
abort
|
|
26
26
|
end
|
|
27
27
|
else
|
|
@@ -3,16 +3,16 @@ require 'padrino-core/cli/launcher'
|
|
|
3
3
|
module Padrino
|
|
4
4
|
module Cli
|
|
5
5
|
class Base < Launcher
|
|
6
|
-
desc
|
|
7
|
-
method_option :environment, :
|
|
8
|
-
method_option :list, :
|
|
9
|
-
method_option :trace, :
|
|
6
|
+
desc 'rake', 'Execute rake tasks.'
|
|
7
|
+
method_option :environment, type: :string, aliases: '-e'
|
|
8
|
+
method_option :list, type: :string, aliases: '-T', desc: 'Display the tasks (matching optional PATTERN) with descriptions, then exit.'
|
|
9
|
+
method_option :trace, type: :boolean, aliases: '-t', desc: 'Turn on invoke/execute tracing, enable full backtrace.'
|
|
10
10
|
def rake(*args)
|
|
11
11
|
prepare :rake
|
|
12
|
-
args <<
|
|
13
|
-
args << options[:list]
|
|
14
|
-
args <<
|
|
15
|
-
args <<
|
|
12
|
+
args << '-T' if options[:list]
|
|
13
|
+
args << options[:list] unless options[:list].nil? || options[:list].to_s == 'list'
|
|
14
|
+
args << '--trace' if options[:trace]
|
|
15
|
+
args << '--verbose' if options[:verbose]
|
|
16
16
|
ARGV.clear
|
|
17
17
|
ARGV.concat(args)
|
|
18
18
|
puts "=> Executing Rake #{ARGV.join(' ')} ..."
|
|
@@ -23,8 +23,8 @@ module Padrino
|
|
|
23
23
|
Rake.application.top_level
|
|
24
24
|
end
|
|
25
25
|
|
|
26
|
-
desc
|
|
27
|
-
map
|
|
26
|
+
desc 'console', "Boots up the Padrino application irb console (alternatively use 'c')."
|
|
27
|
+
map 'c' => :console
|
|
28
28
|
def console(*args)
|
|
29
29
|
prepare :console
|
|
30
30
|
require File.expand_path('../version', __dir__)
|
|
@@ -37,44 +37,43 @@ module Padrino
|
|
|
37
37
|
else
|
|
38
38
|
require 'irb'
|
|
39
39
|
begin
|
|
40
|
-
require
|
|
40
|
+
require 'irb/completion'
|
|
41
41
|
rescue LoadError
|
|
42
|
+
# do nothing
|
|
42
43
|
end
|
|
43
44
|
IRB.start
|
|
44
45
|
end
|
|
45
46
|
end
|
|
46
47
|
|
|
47
|
-
desc
|
|
48
|
-
map [
|
|
48
|
+
desc 'generate', "Executes the Padrino generator with given options (alternatively use 'gen' or 'g')."
|
|
49
|
+
map %w[gen g] => :generate
|
|
49
50
|
def generate(*args)
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
puts "<= You need padrino-gen! Run: gem install padrino-gen"
|
|
61
|
-
|
|
51
|
+
# We try to load the vendored padrino-gen if exist
|
|
52
|
+
padrino_gen_path = File.expand_path('../../../../padrino-gen/lib', __dir__)
|
|
53
|
+
$LOAD_PATH.unshift(padrino_gen_path) if File.directory?(padrino_gen_path) && !$LOAD_PATH.include?(padrino_gen_path)
|
|
54
|
+
require 'padrino-core/command'
|
|
55
|
+
require 'padrino-gen/command'
|
|
56
|
+
ARGV.shift
|
|
57
|
+
ARGV << 'help' if ARGV.empty?
|
|
58
|
+
Padrino.bin_gen(*ARGV)
|
|
59
|
+
rescue StandardError
|
|
60
|
+
puts '<= You need padrino-gen! Run: gem install padrino-gen'
|
|
62
61
|
end
|
|
63
62
|
|
|
64
|
-
desc
|
|
65
|
-
map [
|
|
63
|
+
desc 'version', 'Show current Padrino version.'
|
|
64
|
+
map ['-v', '--version'] => :version
|
|
66
65
|
def version
|
|
67
66
|
require 'padrino-core/version'
|
|
68
67
|
puts "Padrino v. #{Padrino.version}"
|
|
69
68
|
end
|
|
70
69
|
|
|
71
|
-
desc
|
|
72
|
-
map [
|
|
70
|
+
desc 'runner', "Run a piece of code in the Padrino application environment (alternatively use 'run' or 'r')."
|
|
71
|
+
map %w[run r] => :runner
|
|
73
72
|
def runner(*args)
|
|
74
73
|
prepare :runner
|
|
75
74
|
|
|
76
75
|
code_or_file = args.shift
|
|
77
|
-
abort
|
|
76
|
+
abort 'Please specify code or file' if code_or_file.nil?
|
|
78
77
|
|
|
79
78
|
require File.expand_path('config/boot.rb')
|
|
80
79
|
|
|
@@ -87,7 +86,7 @@ module Padrino
|
|
|
87
86
|
|
|
88
87
|
protected
|
|
89
88
|
|
|
90
|
-
def self.banner(task=nil, *args)
|
|
89
|
+
def self.banner(task = nil, *args)
|
|
91
90
|
"padrino #{task.name}"
|
|
92
91
|
end
|
|
93
92
|
|
|
@@ -103,7 +102,7 @@ module Padrino
|
|
|
103
102
|
|
|
104
103
|
result
|
|
105
104
|
end
|
|
106
|
-
alias
|
|
105
|
+
alias silence capture
|
|
107
106
|
end
|
|
108
107
|
end
|
|
109
108
|
end
|
|
@@ -6,6 +6,7 @@ module Padrino
|
|
|
6
6
|
begin
|
|
7
7
|
return if Bundler.definition.missing_specs.empty?
|
|
8
8
|
rescue NameError, NoMethodError, Bundler::GemfileNotFound
|
|
9
|
+
# Move forward
|
|
9
10
|
end
|
|
10
11
|
|
|
11
12
|
project_root = Dir.pwd
|
|
@@ -14,14 +15,14 @@ module Padrino
|
|
|
14
15
|
project_root = project_root.rpartition('/').first
|
|
15
16
|
end
|
|
16
17
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
18
|
+
return unless %w[Gemfile .components].all? { |file| File.file?(File.join(project_root, file)) }
|
|
19
|
+
|
|
20
|
+
binstub = File.join(project_root, 'bin', executable)
|
|
21
|
+
if File.file?(binstub)
|
|
22
|
+
exec Gem.ruby, binstub, *ARGV
|
|
23
|
+
else
|
|
24
|
+
puts 'Please run `bundle install --binstubs` from your project root to generate bundle-specific executables'
|
|
25
|
+
exit!
|
|
25
26
|
end
|
|
26
27
|
end
|
|
27
28
|
end
|
|
@@ -7,7 +7,7 @@ end
|
|
|
7
7
|
def applications
|
|
8
8
|
puts "==== List of Mounted Applications ====\n\n"
|
|
9
9
|
Padrino.mounted_apps.each do |app|
|
|
10
|
-
puts
|
|
10
|
+
puts format(' * %-10s mapped to %s', app.name, app.uri_root)
|
|
11
11
|
end
|
|
12
12
|
puts
|
|
13
13
|
Padrino.mounted_apps.map { |app| "#{app.name} => #{app.uri_root}" }
|
|
@@ -5,20 +5,23 @@ module Padrino
|
|
|
5
5
|
class Launcher < Thor
|
|
6
6
|
include Thor::Actions
|
|
7
7
|
|
|
8
|
-
class_option :chdir, :
|
|
9
|
-
class_option :environment, :
|
|
10
|
-
class_option :help, :
|
|
11
|
-
|
|
12
|
-
desc
|
|
13
|
-
map
|
|
14
|
-
method_option :server,
|
|
15
|
-
method_option :host,
|
|
16
|
-
method_option :port,
|
|
17
|
-
method_option :daemonize,
|
|
18
|
-
method_option :pid,
|
|
19
|
-
method_option :debug,
|
|
20
|
-
method_option :options,
|
|
21
|
-
|
|
8
|
+
class_option :chdir, type: :string, aliases: '-c', desc: 'Change to dir before starting.'
|
|
9
|
+
class_option :environment, type: :string, aliases: '-e', desc: 'Padrino Environment.'
|
|
10
|
+
class_option :help, type: :boolean, desc: 'Show help usage'
|
|
11
|
+
|
|
12
|
+
desc 'start', "Starts the Padrino application (alternatively use 's')."
|
|
13
|
+
map 's' => :start
|
|
14
|
+
method_option :server, type: :string, aliases: '-a', desc: 'Rack Handler (default: autodetect)'
|
|
15
|
+
method_option :host, type: :string, aliases: '-h', desc: 'Bind to HOST address (default: 127.0.0.1)'
|
|
16
|
+
method_option :port, type: :numeric, aliases: '-p', desc: 'Use PORT (default: 3000)'
|
|
17
|
+
method_option :daemonize, type: :boolean, aliases: '-d', desc: 'Run daemonized in the background.'
|
|
18
|
+
method_option :pid, type: :string, aliases: '-i', desc: 'File to store pid.'
|
|
19
|
+
method_option :debug, type: :boolean, desc: 'Set debugging flags.'
|
|
20
|
+
method_option :options, type: :array, aliases: '-O', desc: <<~DESC.chomp
|
|
21
|
+
--options NAME=VALUE NAME2=VALUE2'. pass VALUE to the server as option NAME. If no VALUE, sets it to true. Run '#{$PROGRAM_NAME} --server_options
|
|
22
|
+
DESC
|
|
23
|
+
method_option :server_options, type: :boolean, desc: "Tells the current server handler's options that can be used with --options"
|
|
24
|
+
|
|
22
25
|
def start(*args)
|
|
23
26
|
prepare :start
|
|
24
27
|
require File.expand_path('adapter', __dir__)
|
|
@@ -27,13 +30,13 @@ module Padrino
|
|
|
27
30
|
if options[:server_options]
|
|
28
31
|
puts server_options(options)
|
|
29
32
|
else
|
|
30
|
-
Padrino::Cli::Adapter.start(args.last ? options.merge(:
|
|
33
|
+
Padrino::Cli::Adapter.start(args.last ? options.merge(config: args.last).freeze : options)
|
|
31
34
|
end
|
|
32
35
|
end
|
|
33
36
|
|
|
34
|
-
desc
|
|
35
|
-
map
|
|
36
|
-
method_option :pid, :
|
|
37
|
+
desc 'stop', "Stops the Padrino application (alternatively use 'st')."
|
|
38
|
+
map 'st' => :stop
|
|
39
|
+
method_option :pid, type: :string, aliases: '-p', desc: 'File to store pid', default: 'tmp/pids/server.pid'
|
|
37
40
|
def stop
|
|
38
41
|
prepare :stop
|
|
39
42
|
require File.expand_path('adapter', __dir__)
|
|
@@ -44,25 +47,23 @@ module Padrino
|
|
|
44
47
|
|
|
45
48
|
# https://github.com/rack/rack/blob/master/lib/rack/server.rb\#L100
|
|
46
49
|
def server_options(options)
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
has_options = true
|
|
59
|
-
end
|
|
60
|
-
return "" unless has_options
|
|
50
|
+
info = []
|
|
51
|
+
server = Rack::Handler.get(options[:server]) || Rack::Handler.default(options)
|
|
52
|
+
if server.respond_to?(:valid_options)
|
|
53
|
+
info << ''
|
|
54
|
+
info << "Server-specific options for #{server.name}:"
|
|
55
|
+
|
|
56
|
+
has_options = false
|
|
57
|
+
server.valid_options.each do |name, description|
|
|
58
|
+
next if name.to_s.match(/^(Host|Port)[^a-zA-Z]/) # ignore handler's host and port options, we do our own.
|
|
59
|
+
info << format(' -O %-21s %s', name, description)
|
|
60
|
+
has_options = true
|
|
61
61
|
end
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
62
|
+
return '' unless has_options
|
|
63
|
+
end
|
|
64
|
+
info.join("\n")
|
|
65
|
+
rescue NameError
|
|
66
|
+
"Warning: Could not find handler specified (#{options[:server] || 'default'}) to determine handler-specific options"
|
|
66
67
|
end
|
|
67
68
|
|
|
68
69
|
protected
|
|
@@ -72,16 +73,18 @@ module Padrino
|
|
|
72
73
|
help(task.to_s)
|
|
73
74
|
exit
|
|
74
75
|
end
|
|
76
|
+
|
|
75
77
|
if options.environment
|
|
76
|
-
ENV[
|
|
78
|
+
ENV['RACK_ENV'] = options.environment.to_s
|
|
77
79
|
else
|
|
78
|
-
ENV[
|
|
80
|
+
ENV['RACK_ENV'] ||= 'development'
|
|
79
81
|
end
|
|
82
|
+
|
|
80
83
|
chdir(options.chdir)
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
84
|
+
return if File.exist?('config/boot.rb')
|
|
85
|
+
|
|
86
|
+
puts "=> Could not find boot file in: #{options.chdir}/config/boot.rb !!!"
|
|
87
|
+
abort
|
|
85
88
|
end
|
|
86
89
|
|
|
87
90
|
def chdir(dir)
|
|
@@ -6,15 +6,17 @@ require 'securerandom' unless defined?(SecureRandom)
|
|
|
6
6
|
begin
|
|
7
7
|
require 'padrino-gen'
|
|
8
8
|
rescue LoadError
|
|
9
|
+
# do nothing if padrino-gen is not available
|
|
9
10
|
end
|
|
10
11
|
|
|
11
12
|
module PadrinoTasks
|
|
12
|
-
def self.init(init=false)
|
|
13
|
-
Padrino::Tasks.files.flatten.uniq.each
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
def self.init(init = false)
|
|
14
|
+
Padrino::Tasks.files.flatten.uniq.each do |rakefile|
|
|
15
|
+
Rake.application.add_import(rakefile)
|
|
16
|
+
rescue StandardError
|
|
17
|
+
puts "<= Failed load #{ext}"
|
|
18
|
+
end
|
|
19
|
+
|
|
18
20
|
load(File.expand_path('rake_tasks.rb', __dir__))
|
|
19
21
|
Rake.application.load_imports
|
|
20
22
|
end
|
|
@@ -29,18 +31,18 @@ module PadrinoTasks
|
|
|
29
31
|
|
|
30
32
|
def self.load?(task, constant_present)
|
|
31
33
|
if constant_present && !PadrinoTasks.tasks.include?(task)
|
|
32
|
-
warn
|
|
33
|
-
Loading #{task} tasks automatically.
|
|
34
|
-
This functionality will be disabled in future versions. Please put
|
|
34
|
+
warn <<~WARNING
|
|
35
|
+
Loading #{task} tasks automatically.
|
|
36
|
+
This functionality will be disabled in future versions. Please put
|
|
35
37
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
+
PadrinoTasks.use(#{task.inspect})
|
|
39
|
+
PadrinoTasks.init
|
|
38
40
|
|
|
39
|
-
and remove
|
|
41
|
+
and remove
|
|
40
42
|
|
|
41
|
-
|
|
43
|
+
require File.expand_path('../config/boot.rb', __FILE__)
|
|
42
44
|
|
|
43
|
-
in you Rakefile instead.
|
|
45
|
+
in you Rakefile instead.
|
|
44
46
|
WARNING
|
|
45
47
|
end
|
|
46
48
|
|
|
@@ -11,36 +11,36 @@ end
|
|
|
11
11
|
task :skeleton do
|
|
12
12
|
PADRINO_ROOT ||= Rake.application.original_dir
|
|
13
13
|
require 'padrino-core'
|
|
14
|
-
Padrino.send(:dependency_paths).reject!{ |path| path.include?('/models/') }
|
|
14
|
+
Padrino.send(:dependency_paths).reject! { |path| path.include?('/models/') }
|
|
15
15
|
require File.expand_path('config/boot.rb', Rake.application.original_dir)
|
|
16
16
|
end
|
|
17
17
|
|
|
18
|
-
desc
|
|
18
|
+
desc 'Generate a secret key'
|
|
19
19
|
task :secret do
|
|
20
20
|
shell.say SecureRandom.hex(32)
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
def list_app_routes(app, args)
|
|
24
24
|
app_routes = app.named_routes
|
|
25
|
-
app_routes.
|
|
25
|
+
app_routes.select! { |r| r.identifier.to_s =~ /#{args.query}/ } if args.query && !args.query.empty?
|
|
26
26
|
app_routes.map! { |r| [r.verb, r.name, r.path] }
|
|
27
27
|
return if app_routes.empty?
|
|
28
28
|
shell.say "\nApplication: #{app.app_class}", :yellow
|
|
29
|
-
app_routes.unshift([
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
app_routes.unshift(%w[REQUEST URL PATH])
|
|
30
|
+
max_col1 = app_routes.max { |a, b| a[0].size <=> b[0].size }[0].size
|
|
31
|
+
max_col2 = app_routes.max { |a, b| a[1].size <=> b[1].size }[1].size
|
|
32
32
|
app_routes.each_with_index do |row, i|
|
|
33
|
-
message = [row[1].ljust(
|
|
34
|
-
shell.say("
|
|
33
|
+
message = [row[1].ljust(max_col2 + 2), row[0].center(max_col1 + 2), row[2]]
|
|
34
|
+
shell.say(" #{message.join(' ')}", i.zero? ? :bold : nil)
|
|
35
35
|
end
|
|
36
36
|
end
|
|
37
37
|
|
|
38
38
|
def env_migration_version
|
|
39
|
-
version = ENV[
|
|
40
|
-
if version.nil? && ENV[
|
|
39
|
+
version = ENV['MIGRATION_VERSION']
|
|
40
|
+
if version.nil? && ENV['VERSION']
|
|
41
41
|
deprecated = true
|
|
42
|
-
warn
|
|
43
|
-
version = ENV[
|
|
42
|
+
warn 'Environment variable VERSION is deprecated, use MIGRATION_VERSION'
|
|
43
|
+
version = ENV['VERSION']
|
|
44
44
|
end
|
|
45
45
|
version ? Integer(version) : nil
|
|
46
46
|
rescue ArgumentError
|
|
@@ -48,14 +48,14 @@ rescue ArgumentError
|
|
|
48
48
|
nil
|
|
49
49
|
end
|
|
50
50
|
|
|
51
|
-
desc
|
|
51
|
+
desc 'Displays a listing of the named routes within a project, optionally only those matched by [query]'
|
|
52
52
|
task :routes, [:query] => :environment do |_t, args|
|
|
53
53
|
Padrino.mounted_apps.each do |app|
|
|
54
54
|
list_app_routes(app, args)
|
|
55
55
|
end
|
|
56
56
|
end
|
|
57
57
|
|
|
58
|
-
desc
|
|
58
|
+
desc 'Displays a listing of the named routes a given app [app]'
|
|
59
59
|
namespace :routes do
|
|
60
60
|
task :app, [:app] => :environment do |_t, args|
|
|
61
61
|
app = Padrino.mounted_apps.find { |app| app.app_class == args.app }
|
|
@@ -63,10 +63,8 @@ namespace :routes do
|
|
|
63
63
|
end
|
|
64
64
|
end
|
|
65
65
|
|
|
66
|
-
Dir[
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
warn "#{file}: #{e.message}"
|
|
71
|
-
|
|
66
|
+
Dir['{lib/tasks/**,tasks/**,test,spec}/*.rake'].each do |file|
|
|
67
|
+
load(File.expand_path(file))
|
|
68
|
+
rescue LoadError => e
|
|
69
|
+
warn "#{file}: #{e.message}"
|
|
72
70
|
end
|
data/lib/padrino-core/command.rb
CHANGED
|
@@ -15,7 +15,7 @@ module Padrino
|
|
|
15
15
|
#
|
|
16
16
|
def self.bin(*args)
|
|
17
17
|
@_padrino_bin ||= [self.ruby_command, File.expand_path('../../bin/padrino', __dir__)]
|
|
18
|
-
args.empty? ? @_padrino_bin : system(args.unshift(@_padrino_bin).join(
|
|
18
|
+
args.empty? ? @_padrino_bin : system(args.unshift(@_padrino_bin).join(' '))
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
##
|
data/lib/padrino-core/filter.rb
CHANGED
|
@@ -27,7 +27,7 @@ module Padrino
|
|
|
27
27
|
private
|
|
28
28
|
|
|
29
29
|
def scoped_controller_name
|
|
30
|
-
@scoped_controller_name ||= Array(@scoped_controller).join(
|
|
30
|
+
@scoped_controller_name ||= Array(@scoped_controller).join('_')
|
|
31
31
|
end
|
|
32
32
|
|
|
33
33
|
def match_with_arguments?(request)
|
|
@@ -37,7 +37,7 @@ module Padrino
|
|
|
37
37
|
if argument.instance_of?(Symbol)
|
|
38
38
|
next unless route
|
|
39
39
|
name = route.name
|
|
40
|
-
argument == name || name == [scoped_controller_name, argument].join(
|
|
40
|
+
argument == name || name == [scoped_controller_name, argument].join(' ').to_sym
|
|
41
41
|
else
|
|
42
42
|
argument === path
|
|
43
43
|
end
|
|
@@ -46,7 +46,7 @@ module Padrino
|
|
|
46
46
|
|
|
47
47
|
def match_with_options?(request)
|
|
48
48
|
user_agent = request.user_agent
|
|
49
|
-
@options.any?{|name, value| value === (name == :agent ? user_agent : request.send(name)) }
|
|
49
|
+
@options.any? { |name, value| value === (name == :agent ? user_agent : request.send(name)) }
|
|
50
50
|
end
|
|
51
51
|
end
|
|
52
52
|
end
|
data/lib/padrino-core/loader.rb
CHANGED
|
@@ -142,24 +142,22 @@ module Padrino
|
|
|
142
142
|
# require_dependencies("#{Padrino.root}/lib/**/*.rb")
|
|
143
143
|
#
|
|
144
144
|
def require_dependencies(*paths)
|
|
145
|
-
options = { :
|
|
145
|
+
options = { cyclic: true }.update(paths.last.is_a?(Hash) ? paths.pop : {})
|
|
146
146
|
|
|
147
|
-
files = paths.flatten.flat_map{ |path| Dir.glob(path).sort_by{ |filename| filename.count('/') } }.uniq
|
|
147
|
+
files = paths.flatten.flat_map { |path| Dir.glob(path).sort_by { |filename| filename.count('/') } }.uniq
|
|
148
148
|
|
|
149
149
|
until files.empty?
|
|
150
150
|
error = fatal = loaded = nil
|
|
151
151
|
|
|
152
152
|
files.dup.each do |file|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
break
|
|
162
|
-
|
|
153
|
+
Reloader.safe_load(file, options)
|
|
154
|
+
files.delete(file)
|
|
155
|
+
loaded = true
|
|
156
|
+
rescue NameError, LoadError => error
|
|
157
|
+
raise if Reloader.exclude.any? { |path| file.start_with?(path) } || options[:cyclic] == false
|
|
158
|
+
logger.devel "Cyclic dependency reload for #{error.class}: #{error.message}"
|
|
159
|
+
rescue Exception => fatal
|
|
160
|
+
break
|
|
163
161
|
end
|
|
164
162
|
|
|
165
163
|
next unless fatal || !loaded
|