padrino-core 0.13.0.beta3 → 0.13.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/padrino-core.rb +2 -0
- data/lib/padrino-core/application/routing.rb +5 -6
- data/lib/padrino-core/caller.rb +2 -1
- data/lib/padrino-core/configuration.rb +40 -0
- data/lib/padrino-core/logger.rb +19 -2
- data/lib/padrino-core/mounter.rb +15 -10
- data/lib/padrino-core/version.rb +1 -1
- data/test/test_configuration.rb +29 -0
- data/test/test_logger.rb +23 -0
- data/test/test_routing.rb +16 -1
- metadata +10 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: df73d4a14b1d5ad90c0cee78699bfb08addd30f4
|
4
|
+
data.tar.gz: 7307777a18f4d046f27bbc3296afcb26bab98757
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c951c3160d9354c1d0cef4c195f90cfc9e725661d235033ce930cc0fc2a3c47f34db0dda0dc02d9ee23fd6af7485f3c87e2389554f7330ac1df41572dbd21582
|
7
|
+
data.tar.gz: bd1cd61aec6fd3de5c26c1f1e52695fb7dd4649f5d18a89a943f695b6b11f566483ec227362876800a987a7889f818fee8a74cd55bb0f3356735ae1b30b8fa9a
|
data/lib/padrino-core.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'sinatra/base'
|
2
2
|
require 'padrino-core/version'
|
3
3
|
require 'padrino-support'
|
4
|
+
require 'padrino-core/configuration'
|
4
5
|
require 'padrino-core/application'
|
5
6
|
|
6
7
|
require 'padrino-core/caller'
|
@@ -25,6 +26,7 @@ module Padrino
|
|
25
26
|
class ApplicationLoadError < RuntimeError # @private
|
26
27
|
end
|
27
28
|
|
29
|
+
extend Configuration
|
28
30
|
extend Loader
|
29
31
|
|
30
32
|
class << self
|
@@ -407,7 +407,7 @@ module Padrino
|
|
407
407
|
replace_instance_variable(:@_controller, args)
|
408
408
|
replace_instance_variable(:@_defaults, options)
|
409
409
|
replace_instance_variable(:@filters, :before => @filters[:before].dup, :after => @filters[:after].dup)
|
410
|
-
replace_instance_variable(:@layout,
|
410
|
+
replace_instance_variable(:@layout, @layout)
|
411
411
|
|
412
412
|
yield
|
413
413
|
|
@@ -731,7 +731,7 @@ module Padrino
|
|
731
731
|
|
732
732
|
accept_format = CONTENT_TYPE_ALIASES[type] || type
|
733
733
|
if types.include?(accept_format)
|
734
|
-
content_type(accept_format || :html
|
734
|
+
content_type(accept_format || :html)
|
735
735
|
else
|
736
736
|
catch_all ? true : halt(406)
|
737
737
|
end
|
@@ -751,7 +751,7 @@ module Padrino
|
|
751
751
|
mime_types = types.map{ |type| mime_type(CONTENT_TYPE_ALIASES[type] || type) }
|
752
752
|
condition do
|
753
753
|
halt 406 unless mime_types.include?(request.media_type)
|
754
|
-
content_type(mime_symbol(request.media_type)
|
754
|
+
content_type(mime_symbol(request.media_type))
|
755
755
|
end
|
756
756
|
end
|
757
757
|
|
@@ -894,7 +894,6 @@ module Padrino
|
|
894
894
|
#
|
895
895
|
def content_type(type=nil, params={})
|
896
896
|
return @_content_type unless type
|
897
|
-
params.delete(:charset) if type == :json
|
898
897
|
super(type, params)
|
899
898
|
@_content_type = type
|
900
899
|
end
|
@@ -904,7 +903,7 @@ module Padrino
|
|
904
903
|
def provides_any?(formats)
|
905
904
|
accepted_format = formats.first
|
906
905
|
type = accepted_format ? mime_symbol(accepted_format) : :html
|
907
|
-
content_type(CONTENT_TYPE_ALIASES[type] || type
|
906
|
+
content_type(CONTENT_TYPE_ALIASES[type] || type)
|
908
907
|
end
|
909
908
|
|
910
909
|
def provides_format?(types, format)
|
@@ -914,7 +913,7 @@ module Padrino
|
|
914
913
|
halt 406 if settings.respond_to?(:treat_format_as_accept) && settings.treat_format_as_accept
|
915
914
|
false
|
916
915
|
else
|
917
|
-
content_type(format || :html
|
916
|
+
content_type(format || :html)
|
918
917
|
end
|
919
918
|
end
|
920
919
|
|
data/lib/padrino-core/caller.rb
CHANGED
@@ -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
|
data/lib/padrino-core/logger.rb
CHANGED
@@ -264,6 +264,9 @@ module Padrino
|
|
264
264
|
#
|
265
265
|
# :log_level:: Once of [:fatal, :error, :warn, :info, :debug]
|
266
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'
|
267
270
|
# :log_level::
|
268
271
|
# The log level from, e.g. :fatal or :info. Defaults to :warn in the
|
269
272
|
# production environment and :debug otherwise.
|
@@ -279,6 +282,10 @@ module Padrino
|
|
279
282
|
# Padrino::Logger::Config[:development] = { :log_level => :debug, :stream => :to_file }
|
280
283
|
# # or you can edit our defaults
|
281
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'
|
282
289
|
# # or you can use your stream
|
283
290
|
# Padrino::Logger::Config[:development][:stream] = StringIO.new
|
284
291
|
#
|
@@ -329,8 +336,18 @@ module Padrino
|
|
329
336
|
|
330
337
|
stream = case config[:stream]
|
331
338
|
when :to_file
|
332
|
-
|
333
|
-
|
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
|
334
351
|
when :null then StringIO.new
|
335
352
|
when :stdout then $stdout
|
336
353
|
when :stderr then $stderr
|
data/lib/padrino-core/mounter.rb
CHANGED
@@ -96,20 +96,23 @@ module Padrino
|
|
96
96
|
def map_onto(router)
|
97
97
|
app_data = self
|
98
98
|
app_obj = @app_obj
|
99
|
+
|
100
|
+
uri_root = app_data.uri_root
|
101
|
+
public_folder_exists = File.exist?(app_obj.public_folder)
|
102
|
+
|
99
103
|
if padrino_application?
|
100
|
-
app_obj.set :uri_root,
|
101
|
-
app_obj.set :app_name,
|
102
|
-
app_obj.set :
|
103
|
-
app_obj.set :root,
|
104
|
-
app_obj.set :
|
105
|
-
app_obj.set :static, File.exist?(app_obj.public_folder) if app_obj.nil?
|
104
|
+
app_obj.set :uri_root, uri_root
|
105
|
+
app_obj.set :app_name, app_obj.app_name.to_s
|
106
|
+
app_obj.set :root, app_data.app_root
|
107
|
+
app_obj.set :public_folder, Padrino.root('public', uri_root) unless public_folder_exists
|
108
|
+
app_obj.set :static, public_folder_exists
|
106
109
|
app_obj.set :cascade, app_data.cascade
|
107
110
|
else
|
108
|
-
app_obj.uri_root =
|
109
|
-
app_obj.public_folder = Padrino.root('public',
|
111
|
+
app_obj.uri_root = uri_root
|
112
|
+
app_obj.public_folder = Padrino.root('public', uri_root) unless public_folder_exists
|
110
113
|
end
|
111
114
|
app_obj.setup_application! # Initializes the app here with above settings.
|
112
|
-
router.map(:to => app_obj, :path =>
|
115
|
+
router.map(:to => app_obj, :path => uri_root, :host => app_data.app_host)
|
113
116
|
end
|
114
117
|
|
115
118
|
###
|
@@ -185,8 +188,10 @@ module Padrino
|
|
185
188
|
# Returns the determined location of the mounted application main file.
|
186
189
|
#
|
187
190
|
def locate_app_file
|
191
|
+
app_const = app_constant
|
192
|
+
|
188
193
|
candidates = []
|
189
|
-
candidates <<
|
194
|
+
candidates << app_const.app_file if app_const.respond_to?(:app_file)
|
190
195
|
candidates << Padrino.first_caller if File.identical?(Padrino.first_caller.to_s, Padrino.called_from.to_s)
|
191
196
|
candidates << Padrino.mounted_root(name.downcase, "app.rb")
|
192
197
|
simple_name = name.split("::").last.downcase
|
data/lib/padrino-core/version.rb
CHANGED
@@ -0,0 +1,29 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/helper')
|
2
|
+
|
3
|
+
describe "PadrinoConfiguration" do
|
4
|
+
it 'should be able to store values' do
|
5
|
+
Padrino.config.val1 = 12345
|
6
|
+
assert_equal 12345, Padrino.config.val1
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'should be able to configure with block' do
|
10
|
+
Padrino.configure do |config|
|
11
|
+
config.val2 = 54321
|
12
|
+
end
|
13
|
+
assert_equal 54321, Padrino.config.val2
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should be able to configure with block' do
|
17
|
+
Padrino.configure :test do |config|
|
18
|
+
config.test1 = 54321
|
19
|
+
end
|
20
|
+
Padrino.configure :development do |config|
|
21
|
+
config.test1 = 12345
|
22
|
+
end
|
23
|
+
Padrino.configure :test, :development do |config|
|
24
|
+
config.both1 = 54321
|
25
|
+
end
|
26
|
+
assert_equal 54321, Padrino.config.test1
|
27
|
+
assert_equal 54321, Padrino.config.both1
|
28
|
+
end
|
29
|
+
end
|
data/test/test_logger.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
#coding:utf-8
|
2
2
|
require File.expand_path(File.dirname(__FILE__) + '/helper')
|
3
3
|
require 'logger'
|
4
|
+
require 'tempfile'
|
4
5
|
|
5
6
|
describe "PadrinoLogger" do
|
6
7
|
before do
|
@@ -37,6 +38,28 @@ describe "PadrinoLogger" do
|
|
37
38
|
Padrino::Logger.setup!
|
38
39
|
assert_equal my_stream, Padrino.logger.log
|
39
40
|
end
|
41
|
+
|
42
|
+
it 'should use a custom file path' do
|
43
|
+
tempfile = Tempfile.new('app.txt')
|
44
|
+
path = tempfile.path
|
45
|
+
tempfile.unlink
|
46
|
+
Padrino::Logger::Config[:test][:stream] = :to_file
|
47
|
+
Padrino::Logger::Config[:test][:log_path] = path
|
48
|
+
Padrino::Logger.setup!
|
49
|
+
assert_file_exists path
|
50
|
+
File.unlink(path)
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'should use a custom log directory' do
|
54
|
+
tmpdir = Dir.mktmpdir
|
55
|
+
Padrino::Logger::Config[:test][:stream] = :to_file
|
56
|
+
Padrino::Logger::Config[:test][:log_path] = tmpdir
|
57
|
+
Padrino::Logger.setup!
|
58
|
+
log_path = File.join(tmpdir, 'test.log')
|
59
|
+
assert_file_exists log_path
|
60
|
+
File.unlink(log_path)
|
61
|
+
Dir.rmdir(tmpdir)
|
62
|
+
end
|
40
63
|
end
|
41
64
|
|
42
65
|
it 'should log something' do
|
data/test/test_routing.rb
CHANGED
@@ -766,12 +766,27 @@ describe "Routing" do
|
|
766
766
|
assert_equal 'application/json', response["Content-Type"]
|
767
767
|
get "/a.foo"
|
768
768
|
assert_equal "foo", body
|
769
|
-
assert_equal 'application/foo
|
769
|
+
assert_equal 'application/foo', response["Content-Type"]
|
770
770
|
get "/a"
|
771
771
|
assert_equal "html", body
|
772
772
|
assert_equal 'text/html;charset=utf-8', response["Content-Type"]
|
773
773
|
end
|
774
774
|
|
775
|
+
it 'should not drop json charset' do
|
776
|
+
mock_app do
|
777
|
+
get '/' do
|
778
|
+
content_type :json, :charset => 'utf-16'
|
779
|
+
end
|
780
|
+
get '/a' do
|
781
|
+
content_type :json, 'charset' => 'utf-16'
|
782
|
+
end
|
783
|
+
end
|
784
|
+
get '/'
|
785
|
+
assert_equal 'application/json;charset=utf-16', response["Content-Type"]
|
786
|
+
get '/a'
|
787
|
+
assert_equal 'application/json;charset=utf-16', response["Content-Type"]
|
788
|
+
end
|
789
|
+
|
775
790
|
it 'should use controllers' do
|
776
791
|
mock_app do
|
777
792
|
controller "/admin" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: padrino-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.13.0
|
4
|
+
version: 0.13.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Padrino Team
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2015-
|
14
|
+
date: 2015-10-11 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: padrino-support
|
@@ -19,14 +19,14 @@ dependencies:
|
|
19
19
|
requirements:
|
20
20
|
- - '='
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: 0.13.0
|
22
|
+
version: 0.13.0
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
27
|
- - '='
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: 0.13.0
|
29
|
+
version: 0.13.0
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: sinatra
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
@@ -128,6 +128,7 @@ files:
|
|
128
128
|
- lib/padrino-core/cli/rake.rb
|
129
129
|
- lib/padrino-core/cli/rake_tasks.rb
|
130
130
|
- lib/padrino-core/command.rb
|
131
|
+
- lib/padrino-core/configuration.rb
|
131
132
|
- lib/padrino-core/ext/sinatra.rb
|
132
133
|
- lib/padrino-core/filter.rb
|
133
134
|
- lib/padrino-core/images/404.png
|
@@ -194,6 +195,7 @@ files:
|
|
194
195
|
- test/fixtures/reloadable_apps/main/app.rb
|
195
196
|
- test/helper.rb
|
196
197
|
- test/test_application.rb
|
198
|
+
- test/test_configuration.rb
|
197
199
|
- test/test_core.rb
|
198
200
|
- test/test_csrf_protection.rb
|
199
201
|
- test/test_dependencies.rb
|
@@ -226,12 +228,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
226
228
|
version: '0'
|
227
229
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
228
230
|
requirements:
|
229
|
-
- - '
|
231
|
+
- - '>='
|
230
232
|
- !ruby/object:Gem::Version
|
231
|
-
version: 1.3.
|
233
|
+
version: 1.3.6
|
232
234
|
requirements: []
|
233
235
|
rubyforge_project: padrino-core
|
234
|
-
rubygems_version: 2.
|
236
|
+
rubygems_version: 2.4.8
|
235
237
|
signing_key:
|
236
238
|
specification_version: 4
|
237
239
|
summary: The required Padrino core gem
|
@@ -280,6 +282,7 @@ test_files:
|
|
280
282
|
- test/fixtures/reloadable_apps/main/app.rb
|
281
283
|
- test/helper.rb
|
282
284
|
- test/test_application.rb
|
285
|
+
- test/test_configuration.rb
|
283
286
|
- test/test_core.rb
|
284
287
|
- test/test_csrf_protection.rb
|
285
288
|
- test/test_dependencies.rb
|