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
|
@@ -21,7 +21,7 @@ module Padrino
|
|
|
21
21
|
#
|
|
22
22
|
attr_accessor :action, :cache, :cache_key, :cache_expires,
|
|
23
23
|
:parent, :use_layout, :controller, :user_agent, :path_for_generation, :default_values
|
|
24
|
-
|
|
24
|
+
|
|
25
25
|
##
|
|
26
26
|
# Constructs an instance of PathRouter::Route.
|
|
27
27
|
#
|
|
@@ -33,29 +33,29 @@ module Padrino
|
|
|
33
33
|
@block = block if block_given?
|
|
34
34
|
merge_with_options!(options)
|
|
35
35
|
end
|
|
36
|
-
|
|
36
|
+
|
|
37
37
|
##
|
|
38
38
|
# Calls the route block with arguments.
|
|
39
39
|
#
|
|
40
40
|
def call(app, *args)
|
|
41
41
|
@block.call(app, *args)
|
|
42
42
|
end
|
|
43
|
-
|
|
43
|
+
|
|
44
44
|
##
|
|
45
45
|
# Returns the route's verb as an array.
|
|
46
46
|
#
|
|
47
47
|
def request_methods
|
|
48
48
|
[verb.to_s.upcase]
|
|
49
49
|
end
|
|
50
|
-
|
|
50
|
+
|
|
51
51
|
##
|
|
52
52
|
# Returns the original path.
|
|
53
53
|
#
|
|
54
54
|
def original_path
|
|
55
55
|
@path
|
|
56
56
|
end
|
|
57
|
-
|
|
58
|
-
SIGNIFICANT_VARIABLES_REGEX = /(^|[^\\])[:*]([a-zA-Z0-9_]+)
|
|
57
|
+
|
|
58
|
+
SIGNIFICANT_VARIABLES_REGEX = /(^|[^\\])[:*]([a-zA-Z0-9_]+)/
|
|
59
59
|
|
|
60
60
|
##
|
|
61
61
|
# Returns signficant variable names.
|
|
@@ -64,18 +64,18 @@ module Padrino
|
|
|
64
64
|
@significant_variable_names ||=
|
|
65
65
|
if @path.is_a?(String)
|
|
66
66
|
@path.scan(SIGNIFICANT_VARIABLES_REGEX).map(&:last)
|
|
67
|
-
elsif @path.is_a?(Regexp)
|
|
67
|
+
elsif @path.is_a?(Regexp) && @path.respond_to?(:named_captures)
|
|
68
68
|
@path.named_captures.keys
|
|
69
69
|
else
|
|
70
70
|
[]
|
|
71
71
|
end
|
|
72
72
|
end
|
|
73
|
-
|
|
73
|
+
|
|
74
74
|
##
|
|
75
75
|
# Returns an instance of PathRouter::Matcher that is associated with the route.
|
|
76
76
|
#
|
|
77
77
|
def matcher
|
|
78
|
-
@matcher ||= Matcher.new(@path, :
|
|
78
|
+
@matcher ||= Matcher.new(@path, capture: @capture, default_values: default_values)
|
|
79
79
|
end
|
|
80
80
|
|
|
81
81
|
##
|
|
@@ -84,7 +84,7 @@ module Padrino
|
|
|
84
84
|
def match(pattern)
|
|
85
85
|
matcher.match(pattern)
|
|
86
86
|
end
|
|
87
|
-
|
|
87
|
+
|
|
88
88
|
##
|
|
89
89
|
# Associates a block with the route, and increments current order of the router.
|
|
90
90
|
#
|
|
@@ -93,7 +93,7 @@ module Padrino
|
|
|
93
93
|
@order = @router.current_order
|
|
94
94
|
@router.increment_order
|
|
95
95
|
end
|
|
96
|
-
|
|
96
|
+
|
|
97
97
|
##
|
|
98
98
|
# Expands the path by using parameters.
|
|
99
99
|
# @see PathRouter::Matcher#expand
|
|
@@ -120,7 +120,7 @@ module Padrino
|
|
|
120
120
|
def params_for(pattern, others = {})
|
|
121
121
|
matcher.params_for(pattern, others)
|
|
122
122
|
end
|
|
123
|
-
|
|
123
|
+
|
|
124
124
|
##
|
|
125
125
|
# Returns before_filters as an array.
|
|
126
126
|
#
|
|
@@ -138,7 +138,7 @@ module Padrino
|
|
|
138
138
|
@_after_filters << block if block_given?
|
|
139
139
|
@_after_filters
|
|
140
140
|
end
|
|
141
|
-
|
|
141
|
+
|
|
142
142
|
##
|
|
143
143
|
# Returns custom_conditions as an array.
|
|
144
144
|
#
|
|
@@ -156,7 +156,7 @@ module Padrino
|
|
|
156
156
|
end
|
|
157
157
|
|
|
158
158
|
private
|
|
159
|
-
|
|
159
|
+
|
|
160
160
|
##
|
|
161
161
|
# Set value to accessor if option name has been defined as an accessora.
|
|
162
162
|
#
|
|
@@ -166,7 +166,7 @@ module Padrino
|
|
|
166
166
|
accessor?(key) ? __send__("#{key}=", value) : (@options[key] = value)
|
|
167
167
|
end
|
|
168
168
|
end
|
|
169
|
-
|
|
169
|
+
|
|
170
170
|
##
|
|
171
171
|
# Returns true if name has been defined as an accessor.
|
|
172
172
|
#
|
|
@@ -57,11 +57,12 @@ module Padrino
|
|
|
57
57
|
def path(name, *args)
|
|
58
58
|
params = args.last.is_a?(Hash) ? args.pop : {}
|
|
59
59
|
candidates = @routes.select { |route| route.name == name }
|
|
60
|
-
|
|
60
|
+
raise InvalidRouteException if candidates.empty?
|
|
61
61
|
i = 0
|
|
62
|
-
route = candidates.sort_by!
|
|
62
|
+
route = candidates.sort_by! do |candidate|
|
|
63
63
|
# Tries to find the route that matches more, but with fewer names, in stable order
|
|
64
|
-
[(params.keys.map(&:to_s) - candidate.matcher.names).length, candidate.matcher.names.size, i += 1]
|
|
64
|
+
[(params.keys.map(&:to_s) - candidate.matcher.names).length, candidate.matcher.names.size, i += 1]
|
|
65
|
+
end.shift
|
|
65
66
|
matcher = route.matcher
|
|
66
67
|
params_for_expand = params.dup
|
|
67
68
|
if !args.empty? && matcher.mustermann?
|
|
@@ -13,8 +13,8 @@ module Padrino
|
|
|
13
13
|
|
|
14
14
|
def remove(name)
|
|
15
15
|
file = files[name] || return
|
|
16
|
-
file[:constants].each{ |constant| Reloader.remove_constant(constant) }
|
|
17
|
-
file[:features].each{ |feature| Reloader.remove_feature(feature) }
|
|
16
|
+
file[:constants].each { |constant| Reloader.remove_constant(constant) }
|
|
17
|
+
file[:features].each { |feature| Reloader.remove_feature(feature) }
|
|
18
18
|
files.delete(name)
|
|
19
19
|
end
|
|
20
20
|
|
|
@@ -22,18 +22,18 @@ module Padrino
|
|
|
22
22
|
file = remove(name)
|
|
23
23
|
@old_entries ||= {}
|
|
24
24
|
@old_entries[name] = {
|
|
25
|
-
:
|
|
26
|
-
:
|
|
25
|
+
constants: object_classes,
|
|
26
|
+
features: old_features = Set.new($LOADED_FEATURES.dup)
|
|
27
27
|
}
|
|
28
28
|
features = file && file[:features] || []
|
|
29
|
-
features.each{ |feature| Reloader.safe_load(feature, :
|
|
29
|
+
features.each { |feature| Reloader.safe_load(feature, force: true) }
|
|
30
30
|
Reloader.remove_feature(name) if old_features.include?(name)
|
|
31
31
|
end
|
|
32
32
|
|
|
33
33
|
def commit(name)
|
|
34
34
|
entry = {
|
|
35
|
-
:
|
|
36
|
-
:
|
|
35
|
+
constants: new_classes(@old_entries[name][:constants]),
|
|
36
|
+
features: Set.new($LOADED_FEATURES) - @old_entries[name][:features] - [name]
|
|
37
37
|
}
|
|
38
38
|
files[name] = entry
|
|
39
39
|
@old_entries.delete(name)
|
|
@@ -42,9 +42,10 @@ module Padrino
|
|
|
42
42
|
def rollback(name)
|
|
43
43
|
new_classes(@old_entries[name][:constants]).each do |klass|
|
|
44
44
|
loaded_in_name = files.each do |file, data|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
next if file == name
|
|
46
|
+
break if data[:constants].include?(klass)
|
|
47
|
+
end
|
|
48
|
+
|
|
48
49
|
Reloader.remove_constant(klass) if loaded_in_name
|
|
49
50
|
end
|
|
50
51
|
@old_entries.delete(name)
|
|
@@ -64,7 +65,7 @@ module Padrino
|
|
|
64
65
|
|
|
65
66
|
ObjectSpace.each_object(::Class).each do |klass|
|
|
66
67
|
if block_given?
|
|
67
|
-
if filtered_class = yield(klass)
|
|
68
|
+
if (filtered_class = yield(klass))
|
|
68
69
|
klasses << filtered_class
|
|
69
70
|
end
|
|
70
71
|
else
|
|
@@ -24,7 +24,7 @@ module Padrino
|
|
|
24
24
|
# Default excluded directories at Padrino.root are: test, spec, features, tmp, config, db and public
|
|
25
25
|
#
|
|
26
26
|
def exclude
|
|
27
|
-
@_exclude ||= Set.new(%w[test spec tmp features config public db].map{ |path| Padrino.root(path) })
|
|
27
|
+
@_exclude ||= Set.new(%w[test spec tmp features config public db].map { |path| Padrino.root(path) })
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
##
|
|
@@ -74,8 +74,7 @@ module Padrino
|
|
|
74
74
|
#
|
|
75
75
|
def lock!
|
|
76
76
|
klasses = Storage.send(:object_classes) do |klass|
|
|
77
|
-
|
|
78
|
-
original_klass_name.split('::').first if original_klass_name
|
|
77
|
+
constant_name(klass)&.split('::')&.first
|
|
79
78
|
end
|
|
80
79
|
klasses |= Padrino.mounted_apps.map(&:app_class)
|
|
81
80
|
exclude_constants.merge(klasses)
|
|
@@ -84,7 +83,7 @@ module Padrino
|
|
|
84
83
|
##
|
|
85
84
|
# A safe Kernel::require which issues the necessary hooks depending on results
|
|
86
85
|
#
|
|
87
|
-
def safe_load(file, options={})
|
|
86
|
+
def safe_load(file, options = {})
|
|
88
87
|
began_at = Time.now
|
|
89
88
|
file = figure_path(file)
|
|
90
89
|
return unless options[:force] || file_changed?(file)
|
|
@@ -93,12 +92,12 @@ module Padrino
|
|
|
93
92
|
Storage.prepare(file) # might call #safe_load recursively
|
|
94
93
|
logger.devel(file_new?(file) ? :loading : :reload, began_at, file)
|
|
95
94
|
begin
|
|
96
|
-
with_silence{ require(file) }
|
|
95
|
+
with_silence { require(file) }
|
|
97
96
|
Storage.commit(file)
|
|
98
97
|
update_modification_time(file)
|
|
99
|
-
rescue Exception =>
|
|
98
|
+
rescue Exception => e
|
|
100
99
|
unless options[:cyclic]
|
|
101
|
-
logger.exception
|
|
100
|
+
logger.exception e, :short
|
|
102
101
|
logger.error "Failed to load #{file}; removing partially defined constants"
|
|
103
102
|
end
|
|
104
103
|
Storage.rollback(file)
|
|
@@ -116,6 +115,7 @@ module Padrino
|
|
|
116
115
|
base.send :remove_const, object
|
|
117
116
|
logger.devel "Removed constant #{const} from #{base}"
|
|
118
117
|
rescue NameError
|
|
118
|
+
# no const to remove
|
|
119
119
|
end
|
|
120
120
|
|
|
121
121
|
##
|
|
@@ -157,7 +157,7 @@ module Padrino
|
|
|
157
157
|
# Reloads the file if it's special. For now it's only I18n locale files.
|
|
158
158
|
#
|
|
159
159
|
def reload_special(file)
|
|
160
|
-
return unless special_files.any?{ |special_file| File.identical?(special_file, file) }
|
|
160
|
+
return unless special_files.any? { |special_file| File.identical?(special_file, file) }
|
|
161
161
|
if defined?(I18n)
|
|
162
162
|
began_at = Time.now
|
|
163
163
|
I18n.reload!
|
|
@@ -237,14 +237,14 @@ module Padrino
|
|
|
237
237
|
# Tells if a feature should be excluded from Reloader tracking.
|
|
238
238
|
#
|
|
239
239
|
def feature_excluded?(file)
|
|
240
|
-
!file.start_with?(Padrino.root) || exclude.any?{ |excluded_path| file.start_with?(excluded_path) }
|
|
240
|
+
!file.start_with?(Padrino.root) || exclude.any? { |excluded_path| file.start_with?(excluded_path) }
|
|
241
241
|
end
|
|
242
242
|
|
|
243
243
|
##
|
|
244
244
|
# Tells if a constant should be excluded from Reloader routines.
|
|
245
245
|
#
|
|
246
246
|
def constant_excluded?(const)
|
|
247
|
-
external_constant?(const) || (exclude_constants - include_constants).any?{ |excluded_constant| constant_name(const).start_with?(excluded_constant) }
|
|
247
|
+
external_constant?(const) || (exclude_constants - include_constants).any? { |excluded_constant| constant_name(const).start_with?(excluded_constant) }
|
|
248
248
|
end
|
|
249
249
|
|
|
250
250
|
##
|
|
@@ -256,7 +256,7 @@ module Padrino
|
|
|
256
256
|
sources = object_sources(const)
|
|
257
257
|
# consider methodless constants not external
|
|
258
258
|
return false if sources.empty?
|
|
259
|
-
|
|
259
|
+
sources.none? { |source| source.start_with?(Padrino.root) }
|
|
260
260
|
end
|
|
261
261
|
|
|
262
262
|
##
|
|
@@ -267,18 +267,17 @@ module Padrino
|
|
|
267
267
|
def object_sources(target)
|
|
268
268
|
sources = Set.new
|
|
269
269
|
target.methods.each do |method_name|
|
|
270
|
-
next unless method_name.
|
|
270
|
+
next unless method_name.is_a?(Symbol)
|
|
271
|
+
|
|
271
272
|
method_object = target.method(method_name)
|
|
272
|
-
if method_object.owner == target.singleton_class
|
|
273
|
-
sources << method_object.source_location.first
|
|
274
|
-
end
|
|
273
|
+
sources << method_object.source_location.first if method_object.owner == target.singleton_class
|
|
275
274
|
end
|
|
275
|
+
|
|
276
276
|
target.instance_methods.each do |method_name|
|
|
277
|
-
next unless method_name.
|
|
277
|
+
next unless method_name.is_a?(Symbol)
|
|
278
|
+
|
|
278
279
|
method_object = target.instance_method(method_name)
|
|
279
|
-
if method_object.owner == target
|
|
280
|
-
sources << method_object.source_location.first
|
|
281
|
-
end
|
|
280
|
+
sources << method_object.source_location.first if method_object.owner == target
|
|
282
281
|
end
|
|
283
282
|
sources
|
|
284
283
|
end
|
data/lib/padrino-core/router.rb
CHANGED
|
@@ -14,13 +14,13 @@ module Padrino
|
|
|
14
14
|
# @example
|
|
15
15
|
#
|
|
16
16
|
# routes = Padrino::Router.new do
|
|
17
|
-
# map(:
|
|
18
|
-
# map(:
|
|
17
|
+
# map(path: '/', to: PadrinoWeb, host: 'padrino.local')
|
|
18
|
+
# map(path: '/', to: Admin, host: 'admin.padrino.local')
|
|
19
19
|
# end
|
|
20
20
|
# run routes
|
|
21
21
|
#
|
|
22
22
|
# routes = Padrino::Router.new do
|
|
23
|
-
# map(:
|
|
23
|
+
# map(path: '/', to: PadrinoWeb, host: /*.padrino.local/)
|
|
24
24
|
# end
|
|
25
25
|
# run routes
|
|
26
26
|
#
|
|
@@ -45,17 +45,17 @@ module Padrino
|
|
|
45
45
|
# The host to map the specified application.
|
|
46
46
|
#
|
|
47
47
|
# @example
|
|
48
|
-
# map(:
|
|
48
|
+
# map(path: '/', to: PadrinoWeb, host: 'padrino.local')
|
|
49
49
|
#
|
|
50
50
|
# @return [Array] The sorted route mappings.
|
|
51
51
|
# @api semipublic
|
|
52
|
-
def map(options={})
|
|
53
|
-
path = options[:path] ||
|
|
52
|
+
def map(options = {})
|
|
53
|
+
path = options[:path] || '/'
|
|
54
54
|
host = options[:host]
|
|
55
55
|
app = options[:to]
|
|
56
56
|
|
|
57
|
-
raise ArgumentError,
|
|
58
|
-
raise ArgumentError,
|
|
57
|
+
raise ArgumentError, 'paths need to start with /' if path[0] != '/'
|
|
58
|
+
raise ArgumentError, 'app is required' if app.nil?
|
|
59
59
|
|
|
60
60
|
path = path.chomp('/')
|
|
61
61
|
match = Regexp.new("^#{Regexp.quote(path).gsub('/', '/+')}(.*)", Regexp::NOENCODING)
|
|
@@ -67,17 +67,17 @@ module Padrino
|
|
|
67
67
|
# The call handler setup to route a request given the mappings specified.
|
|
68
68
|
def call(env)
|
|
69
69
|
began_at = Time.now
|
|
70
|
-
path_info = env[
|
|
70
|
+
path_info = env['PATH_INFO'].to_s
|
|
71
71
|
script_name = env['SCRIPT_NAME']
|
|
72
72
|
http_host = env['HTTP_HOST']
|
|
73
73
|
last_result = nil
|
|
74
74
|
|
|
75
75
|
@mapping.each do |host, path, match, app|
|
|
76
76
|
next unless host.nil? || http_host =~ host
|
|
77
|
-
next unless path_info =~ match && rest = ::Regexp.last_match(1)
|
|
78
|
-
next unless rest.empty? || rest[0] ==
|
|
77
|
+
next unless path_info =~ match && (rest = ::Regexp.last_match(1))
|
|
78
|
+
next unless rest.empty? || rest[0] == '/'
|
|
79
79
|
|
|
80
|
-
rest =
|
|
80
|
+
rest = '/' if rest.empty?
|
|
81
81
|
|
|
82
82
|
env['SCRIPT_NAME'] = script_name + path
|
|
83
83
|
env['PATH_INFO'] = rest
|
|
@@ -90,8 +90,8 @@ module Padrino
|
|
|
90
90
|
last_result || begin
|
|
91
91
|
env['SCRIPT_NAME'] = script_name
|
|
92
92
|
env['PATH_INFO'] = path_info
|
|
93
|
-
Padrino::Logger::Rack.new(nil,'/').send(:log, env, 404, {}, began_at) if logger.debug?
|
|
94
|
-
[404, {
|
|
93
|
+
Padrino::Logger::Rack.new(nil, '/').send(:log, env, 404, {}, began_at) if logger.debug?
|
|
94
|
+
[404, { 'content-type' => 'text/plain', 'x-cascade' => 'pass' }, ["Not Found: #{path_info}"]]
|
|
95
95
|
end
|
|
96
96
|
end
|
|
97
97
|
end
|
data/lib/padrino-core/server.rb
CHANGED
|
@@ -4,40 +4,37 @@ module Padrino
|
|
|
4
4
|
# thin, mongrel, or WEBrick in that order.
|
|
5
5
|
#
|
|
6
6
|
# @example
|
|
7
|
-
# Padrino.run! # with these defaults => host:
|
|
8
|
-
# Padrino.run!(
|
|
7
|
+
# Padrino.run! # with these defaults => host: '127.0.0.1', port: '3000', adapter: the first found
|
|
8
|
+
# Padrino.run!('0.0.0.0', '4000', 'mongrel') # use => host: '0.0.0.0', port: '4000', adapter: 'mongrel'
|
|
9
9
|
#
|
|
10
|
-
def self.run!(options={})
|
|
10
|
+
def self.run!(options = {})
|
|
11
11
|
Padrino.load!
|
|
12
12
|
Server.start(*detect_application(options))
|
|
13
13
|
end
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
#
|
|
17
|
-
#
|
|
18
15
|
def self.detect_application(options)
|
|
19
16
|
default_config_file = 'config.ru'
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
17
|
+
|
|
18
|
+
config_file = options.delete(:config)
|
|
19
|
+
config_file ||= default_config_file if File.file?(default_config_file)
|
|
20
|
+
return [Padrino.application, options] unless config_file
|
|
21
|
+
|
|
22
|
+
raise "Rack config file `#{config_file}` must have `.ru` extension" unless config_file =~ /\.ru$/
|
|
23
|
+
rack_app, rack_options = Rack::Builder.parse_file(config_file)
|
|
24
|
+
[rack_app, (rack_options || {}).merge(options)]
|
|
28
25
|
end
|
|
29
26
|
|
|
30
27
|
##
|
|
31
28
|
# This module builds a Padrino server to run the project based on available handlers.
|
|
32
29
|
#
|
|
33
30
|
class Server < Rackup::Server
|
|
34
|
-
DEFAULT_ADDRESS = { :
|
|
31
|
+
DEFAULT_ADDRESS = { Host: '127.0.0.1', Port: 3000 }
|
|
35
32
|
|
|
36
33
|
# Server Handlers
|
|
37
|
-
Handlers = [
|
|
34
|
+
Handlers = %i[thin puma spider-gazelle mongrel trinidad webrick]
|
|
38
35
|
|
|
39
36
|
# Starts the application on the available server with specified options.
|
|
40
|
-
def self.start(app, options={})
|
|
37
|
+
def self.start(app, options = {})
|
|
41
38
|
options = Utils.symbolize_keys(options.to_hash)
|
|
42
39
|
options.update(parse_server_options(options.delete(:options)))
|
|
43
40
|
options.update(detect_address(options))
|
|
@@ -55,21 +52,20 @@ module Padrino
|
|
|
55
52
|
# Starts the application on the available server with specified options.
|
|
56
53
|
def start
|
|
57
54
|
puts "=> Padrino/#{Padrino.version} has taken the stage #{Padrino.env} at http://#{options[:Host]}:#{options[:Port]}"
|
|
58
|
-
[
|
|
55
|
+
%i[INT TERM].each { |sig| trap(sig) { exit } }
|
|
59
56
|
super do |server|
|
|
60
57
|
server.threaded = true if server.respond_to?(:threaded=)
|
|
61
58
|
end
|
|
62
59
|
ensure
|
|
63
|
-
puts
|
|
60
|
+
puts '<= Padrino leaves the gun, takes the cannoli' unless options[:daemonize]
|
|
64
61
|
end
|
|
65
62
|
|
|
66
63
|
# The application the server will run.
|
|
67
64
|
attr_reader :app
|
|
68
|
-
alias
|
|
65
|
+
alias wrapped_app app
|
|
69
66
|
|
|
70
67
|
attr_reader :options
|
|
71
68
|
|
|
72
|
-
|
|
73
69
|
# Detects the supported handler to use.
|
|
74
70
|
#
|
|
75
71
|
# @example
|
|
@@ -81,7 +77,7 @@ module Padrino
|
|
|
81
77
|
rescue LoadError, NameError
|
|
82
78
|
# Ignored
|
|
83
79
|
end
|
|
84
|
-
|
|
80
|
+
raise "Server handler (#{Handlers.join(', ')}) not found."
|
|
85
81
|
end
|
|
86
82
|
|
|
87
83
|
# Prepares a directory for pid file.
|
|
@@ -95,14 +91,14 @@ module Padrino
|
|
|
95
91
|
# Parses an array of server options.
|
|
96
92
|
#
|
|
97
93
|
def self.parse_server_options(options)
|
|
98
|
-
parsed_server_options = Array(options).flat_map{ |option| option.split('=', 2) }
|
|
94
|
+
parsed_server_options = Array(options).flat_map { |option| option.split('=', 2) }
|
|
99
95
|
Utils.symbolize_keys(Hash[*parsed_server_options])
|
|
100
96
|
end
|
|
101
97
|
|
|
102
98
|
# Detects Host and Port for Rack server.
|
|
103
99
|
#
|
|
104
100
|
def self.detect_address(options)
|
|
105
|
-
address = DEFAULT_ADDRESS.merge(options.select{ |key| [
|
|
101
|
+
address = DEFAULT_ADDRESS.merge(options.select { |key| %i[Host Port].include?(key) })
|
|
106
102
|
address[:Host] = options[:host] if options[:host]
|
|
107
103
|
address[:Port] = options[:port] if options[:port]
|
|
108
104
|
address
|
data/lib/padrino-core/tasks.rb
CHANGED
data/lib/padrino-core/version.rb
CHANGED
data/lib/padrino-core.rb
CHANGED
|
@@ -16,12 +16,12 @@ require 'padrino-core/server'
|
|
|
16
16
|
require 'padrino-core/tasks'
|
|
17
17
|
require 'padrino-core/module'
|
|
18
18
|
|
|
19
|
-
if ENV[
|
|
19
|
+
if ENV['PADRINO_ENV'] || defined?(PADRINO_ENV)
|
|
20
20
|
warn 'Environment variable PADRINO_ENV is deprecated. Please, use RACK_ENV.'
|
|
21
|
-
ENV[
|
|
21
|
+
ENV['RACK_ENV'] ||= ENV['PADRINO_ENV'] ||= PADRINO_ENV
|
|
22
22
|
end
|
|
23
|
-
RACK_ENV = ENV[
|
|
24
|
-
PADRINO_ROOT = ENV[
|
|
23
|
+
RACK_ENV = ENV['RACK_ENV'] ||= 'development' unless defined?(RACK_ENV)
|
|
24
|
+
PADRINO_ROOT = ENV['PADRINO_ROOT'] ||= File.dirname(Padrino.first_caller) unless defined?(PADRINO_ROOT)
|
|
25
25
|
|
|
26
26
|
module Padrino
|
|
27
27
|
class ApplicationLoadError < RuntimeError # @private
|
|
@@ -89,8 +89,7 @@ module Padrino
|
|
|
89
89
|
# end
|
|
90
90
|
#
|
|
91
91
|
def configure_apps(&block)
|
|
92
|
-
|
|
93
|
-
global_configurations << block
|
|
92
|
+
global_configurations << block if block_given?
|
|
94
93
|
end
|
|
95
94
|
|
|
96
95
|
##
|
|
@@ -122,7 +121,7 @@ module Padrino
|
|
|
122
121
|
#
|
|
123
122
|
def add_middleware(router)
|
|
124
123
|
builder = Rack::Builder.new
|
|
125
|
-
middleware.each{ |mw,args,block| builder.use(mw, *args, &block) }
|
|
124
|
+
middleware.each { |mw, args, block| builder.use(mw, *args, &block) }
|
|
126
125
|
builder.run(router)
|
|
127
126
|
builder.to_app
|
|
128
127
|
end
|
|
@@ -160,8 +159,8 @@ module Padrino
|
|
|
160
159
|
# @yield []
|
|
161
160
|
# The given block will be passed to the initialized middleware.
|
|
162
161
|
#
|
|
163
|
-
def use(
|
|
164
|
-
middleware << [
|
|
162
|
+
def use(middleware_class, *args, &block)
|
|
163
|
+
middleware << [middleware_class, args, block]
|
|
165
164
|
end
|
|
166
165
|
|
|
167
166
|
##
|
|
@@ -178,7 +177,7 @@ module Padrino
|
|
|
178
177
|
#
|
|
179
178
|
# @returns The root path of the loaded gem
|
|
180
179
|
def gem(name, main_module)
|
|
181
|
-
_, spec = Gem.loaded_specs.find{|spec_pair| spec_pair[0] == name }
|
|
180
|
+
_, spec = Gem.loaded_specs.find { |spec_pair| spec_pair[0] == name }
|
|
182
181
|
gems << spec
|
|
183
182
|
modules << main_module
|
|
184
183
|
spec.full_gem_path
|
data/padrino-core.gemspec
CHANGED
|
@@ -2,27 +2,27 @@
|
|
|
2
2
|
require File.expand_path('lib/padrino-core/version.rb', __dir__)
|
|
3
3
|
|
|
4
4
|
Gem::Specification.new do |s|
|
|
5
|
-
s.name =
|
|
6
|
-
s.authors = [
|
|
7
|
-
s.email =
|
|
8
|
-
s.summary =
|
|
9
|
-
s.homepage =
|
|
10
|
-
s.description =
|
|
11
|
-
s.required_ruby_version =
|
|
12
|
-
s.required_rubygems_version =
|
|
5
|
+
s.name = 'padrino-core'
|
|
6
|
+
s.authors = ['Padrino Team', 'Nathan Esquenazi', "Davide D'Agostino", 'Arthur Chiu']
|
|
7
|
+
s.email = 'padrinorb@gmail.com'
|
|
8
|
+
s.summary = 'The required Padrino core gem'
|
|
9
|
+
s.homepage = 'http://www.padrinorb.com'
|
|
10
|
+
s.description = 'The Padrino core gem required for use of this framework'
|
|
11
|
+
s.required_ruby_version = '>= 2.7.8'
|
|
12
|
+
s.required_rubygems_version = '>= 1.3.6'
|
|
13
13
|
s.version = Padrino.version
|
|
14
|
-
s.date = Time.now.strftime(
|
|
15
|
-
s.license =
|
|
14
|
+
s.date = Time.now.strftime('%Y-%m-%d')
|
|
15
|
+
s.license = 'MIT'
|
|
16
16
|
|
|
17
|
-
s.extra_rdoc_files = Dir[
|
|
17
|
+
s.extra_rdoc_files = Dir['*.rdoc']
|
|
18
18
|
s.files = `git ls-files`.split("\n")
|
|
19
19
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
|
20
|
-
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
|
21
|
-
s.require_paths = [
|
|
22
|
-
s.rdoc_options = [
|
|
20
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
|
21
|
+
s.require_paths = ['lib']
|
|
22
|
+
s.rdoc_options = ['--charset=UTF-8']
|
|
23
23
|
|
|
24
|
-
s.add_dependency(
|
|
25
|
-
s.add_dependency(
|
|
26
|
-
s.add_dependency(
|
|
27
|
-
s.add_dependency(
|
|
24
|
+
s.add_dependency('padrino-support', Padrino.version)
|
|
25
|
+
s.add_dependency('rackup', '~> 2.1')
|
|
26
|
+
s.add_dependency('sinatra', '~> 4')
|
|
27
|
+
s.add_dependency('thor', '~> 1.0')
|
|
28
28
|
end
|
|
@@ -1,16 +1,17 @@
|
|
|
1
|
+
require 'English'
|
|
1
2
|
require File.expand_path('lib/app_gem/version', __dir__)
|
|
2
3
|
|
|
3
4
|
Gem::Specification.new do |gem|
|
|
4
|
-
gem.authors = [
|
|
5
|
-
gem.email = [
|
|
5
|
+
gem.authors = ['Florian Gilcher']
|
|
6
|
+
gem.email = ['florian.gilcher@asquera.de']
|
|
6
7
|
gem.description = 'TODO: Write a gem description'
|
|
7
8
|
gem.summary = 'TODO: Write a gem summary'
|
|
8
|
-
gem.homepage =
|
|
9
|
+
gem.homepage = ''
|
|
9
10
|
|
|
10
|
-
gem.files = `git ls-files`.split(
|
|
11
|
-
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
|
11
|
+
gem.files = `git ls-files`.split($OUTPUT_RECORD_SEPARATOR)
|
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
|
|
12
13
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
|
13
|
-
gem.name =
|
|
14
|
-
gem.require_paths = [
|
|
14
|
+
gem.name = 'app_gem'
|
|
15
|
+
gem.require_paths = %w[app lib]
|
|
15
16
|
gem.version = AppGem::VERSION
|
|
16
17
|
end
|