padrino-core 0.2.0 → 0.2.1
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.
- data/VERSION +1 -1
- data/lib/padrino-core/logger.rb +59 -18
- data/lib/padrino-core/server.rb +53 -0
- data/lib/padrino-core/support_lite/as_support.rb +10 -0
- data/lib/padrino-core/support_lite/extlib_support.rb +5 -0
- data/lib/padrino-core/support_lite.rb +1 -0
- data/lib/padrino-core/tasks/adapter.rb +4 -43
- data/lib/padrino-core/tasks/rake_tasks.rb +19 -0
- data/lib/padrino-core/tasks/test.rb +3 -2
- data/lib/padrino-core/tasks.rb +39 -15
- data/padrino-core.gemspec +7 -3
- data/test/fixtures/apps/complex.rb +1 -1
- data/test/fixtures/apps/simple.rb +3 -8
- data/test/helper.rb +13 -13
- data/test/test_logger.rb +55 -0
- data/test/test_padrino_core.rb +1 -3
- data/test/test_reloader_complex.rb +7 -3
- data/test/test_reloader_simple.rb +7 -3
- data/test/test_server.rb +37 -0
- metadata +6 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.1
|
data/lib/padrino-core/logger.rb
CHANGED
@@ -1,20 +1,9 @@
|
|
1
1
|
module Padrino
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
case Padrino.env
|
6
|
-
when :production
|
7
|
-
FileUtils.mkdir_p("#{Padrino.root}/log") unless File.exists?("#{Padrino.root}/log")
|
8
|
-
log = File.new("#{Padrino.root}/log/#{PADRINO_ENV.downcase}.log", "a+")
|
9
|
-
Thread.current[:padrino_logger] = Padrino::Logger.new(:log_level => :error, :stream => log)
|
10
|
-
when :development
|
11
|
-
Thread.current[:padrino_logger] = Padrino::Logger.new
|
12
|
-
when :test
|
13
|
-
Thread.current[:padrino_logger] = Padrino::Logger.new(:stream => StringIO.new)
|
14
|
-
end
|
15
|
-
Thread.current[:padrino_logger]
|
3
|
+
def self.logger
|
4
|
+
Thread.current[:padrino_logger] ||= Padrino::Logger.setup!
|
16
5
|
end
|
17
|
-
|
6
|
+
|
18
7
|
class Logger
|
19
8
|
|
20
9
|
attr_accessor :level
|
@@ -41,6 +30,55 @@ module Padrino
|
|
41
30
|
|
42
31
|
@@mutex = {}
|
43
32
|
|
33
|
+
# ==== Notes
|
34
|
+
# Configuration for a given environment, possible options are:
|
35
|
+
#
|
36
|
+
# :log_level:: Once of [:fatal, :error, :warn, :info, :debug]
|
37
|
+
# :stream:: Once of [:to_file, :null, :stdout, :stderr] our your custom stream
|
38
|
+
# :log_level::
|
39
|
+
# The log level from, e.g. :fatal or :info. Defaults to :debug in the
|
40
|
+
# production environment and :debug otherwise.
|
41
|
+
# :auto_flush::
|
42
|
+
# Whether the log should automatically flush after new messages are
|
43
|
+
# added. Defaults to true.
|
44
|
+
# :format_datetime:: Format of datetime. Defaults to: "%d/%b/%Y %H:%M:%S"
|
45
|
+
# :format_message:: Format of message. Defaults to: ""%s - - [%s] \"%s\"""
|
46
|
+
#
|
47
|
+
# Example:
|
48
|
+
#
|
49
|
+
# Padrino::Logger::Config[:development] = { :log_level => :debug, :to_file }
|
50
|
+
# # or you can edit our defaults
|
51
|
+
# Padrino::Logger::Config[:development][:log_level] = :error
|
52
|
+
# # or you can use your stream
|
53
|
+
# Padrino::Logger::Config[:development][:stream] = StringIO.new
|
54
|
+
#
|
55
|
+
# Defaults are:
|
56
|
+
#
|
57
|
+
# :production => { :log_level => :warn, :stream => :to_file }
|
58
|
+
# :development => { :log_level => :debug, :stream => :stdout }
|
59
|
+
# :test => { :log_level => :fatal, :stream => :null }
|
60
|
+
Config = {
|
61
|
+
:production => { :log_level => :warn, :stream => :to_file },
|
62
|
+
:development => { :log_level => :debug, :stream => :stdout },
|
63
|
+
:test => { :log_level => :debug, :stream => :null }
|
64
|
+
} unless const_defined?(:Config)
|
65
|
+
|
66
|
+
|
67
|
+
# Setup a new logger
|
68
|
+
def self.setup!
|
69
|
+
config = Config[Padrino.env] || Config[:test]
|
70
|
+
stream = case config[:stream]
|
71
|
+
when :to_file
|
72
|
+
FileUtils.mkdir_p(Padrino.root("log")) unless File.exists?(Padrino.root("log"))
|
73
|
+
File.new(Padrino.root("log", "#{Padrino.env}.log"), "a+")
|
74
|
+
when :null then StringIO.new
|
75
|
+
when :stdout then $stdout
|
76
|
+
when :stderr then $stderr
|
77
|
+
else config[:stream] # return itself, probabilly is a custom stream.
|
78
|
+
end
|
79
|
+
Thread.current[:padrino_logger] = Padrino::Logger.new(config.merge(:stream => stream))
|
80
|
+
end
|
81
|
+
|
44
82
|
public
|
45
83
|
|
46
84
|
# To initialize the logger you create a new object, proxies to set_log.
|
@@ -175,7 +213,7 @@ module Padrino
|
|
175
213
|
now = Time.now
|
176
214
|
length = extract_content_length(header)
|
177
215
|
|
178
|
-
logger.
|
216
|
+
logger.warn FORMAT % [
|
179
217
|
env['HTTP_X_FORWARDED_FOR'] || env["REMOTE_ADDR"] || "-",
|
180
218
|
env["REMOTE_USER"] || "-",
|
181
219
|
env["REQUEST_METHOD"],
|
@@ -198,7 +236,10 @@ module Padrino
|
|
198
236
|
end
|
199
237
|
end
|
200
238
|
|
201
|
-
|
202
|
-
|
203
|
-
|
239
|
+
module Kernel
|
240
|
+
|
241
|
+
# Define a logger available every where in our app
|
242
|
+
def logger
|
243
|
+
Padrino.logger
|
244
|
+
end
|
204
245
|
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module Padrino
|
2
|
+
|
3
|
+
def self.run!(*args)
|
4
|
+
Padrino.load! unless Padrino.loaded?
|
5
|
+
Server.build(*args)
|
6
|
+
end
|
7
|
+
|
8
|
+
module Server
|
9
|
+
|
10
|
+
class LoadError < RuntimeError; end
|
11
|
+
|
12
|
+
Handlers = %w[thin mongrel webrick] unless const_defined?(:Handlers)
|
13
|
+
|
14
|
+
private
|
15
|
+
def self.build(host="localhost", port=3000, adapter=nil)
|
16
|
+
handler_name = adapter ? adapter.to_s.capitalize : detect_handler.name.gsub(/.*::/, '')
|
17
|
+
|
18
|
+
begin
|
19
|
+
handler = Rack::Handler.get(handler_name.downcase)
|
20
|
+
rescue
|
21
|
+
raise LoadError, "#{handler_name} not supported yet, available adapters are: #{Handlers.inspect}"
|
22
|
+
exit
|
23
|
+
end
|
24
|
+
|
25
|
+
handler.run Padrino.application, :Host => host, :Port => port do |server|
|
26
|
+
trap(:INT) do
|
27
|
+
# Use thins' hard #stop! if available, otherwise just #stop
|
28
|
+
server.respond_to?(:stop!) ? server.stop! : server.stop
|
29
|
+
puts "<= Padrino has ended his set (crowd applauds)"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
rescue RuntimeError => e
|
33
|
+
if e.message =~ /no acceptor/
|
34
|
+
puts "=> Someone is already performing on port #{port}!"
|
35
|
+
else
|
36
|
+
raise e
|
37
|
+
end
|
38
|
+
rescue Errno::EADDRINUSE
|
39
|
+
puts "=> Someone is already performing on port #{port}!"
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.detect_handler
|
43
|
+
Handlers.each do |server_name|
|
44
|
+
begin
|
45
|
+
return Rack::Handler.get(server_name.downcase)
|
46
|
+
rescue LoadError
|
47
|
+
rescue NameError
|
48
|
+
end
|
49
|
+
end
|
50
|
+
raise LoadError, "Server handler (#{servers.join(',')}) not found."
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -1,12 +1,22 @@
|
|
1
1
|
# This requires necessary pieces of ActiveSupport for the dependencies required by Padrino
|
2
2
|
|
3
|
+
## ActiveSupport::Deprecation
|
4
|
+
unless defined?(ActiveSupport::Deprecation)
|
5
|
+
require 'active_support/core_ext/kernel' unless Kernel.method_defined?(:silence_warnings)
|
6
|
+
require 'active_support/core_ext/module' unless Module.method_defined?(:mattr_accessor)
|
7
|
+
require 'active_support/deprecation'
|
8
|
+
end
|
3
9
|
## Class#cattr_accessor
|
4
10
|
require 'active_support/core_ext/class/attribute_accessors' unless Class.method_defined?(:cattr_accessor)
|
5
11
|
## Hash#symbolize_keys, Hash#reverse_merge, Hash#reverse_merge!, Hash#extract_options!, Hash#slice!
|
6
12
|
require 'active_support/core_ext/hash' unless Hash.method_defined?(:reverse_merge)
|
13
|
+
## Hash#to_params
|
14
|
+
require 'active_support/core_ext/object' unless Object.method_defined?(:to_query)
|
15
|
+
class Hash; alias to_params to_query; end unless Hash.method_defined?(:to_params)
|
7
16
|
## String#inflectors
|
8
17
|
require 'active_support/inflector' unless String.method_defined?(:constantize)
|
9
18
|
## Object#blank?, Object#present?
|
19
|
+
require 'active_support/core_ext/object' unless Object.method_defined?(:blank?)
|
10
20
|
require 'active_support/core_ext/blank' unless Object.method_defined?(:blank?)
|
11
21
|
## Array#extract_options!
|
12
22
|
require 'active_support/core_ext/array' unless Array.method_defined?(:extract_options!)
|
@@ -37,6 +37,11 @@ unless Hash.method_defined?(:slice)
|
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
+
## Hash#to_params
|
41
|
+
unless Hash.method_defined?(:to_params)
|
42
|
+
require 'extlib/hash'
|
43
|
+
end
|
44
|
+
|
40
45
|
## Hash#reverse_merge, Hash#reverse_merge!
|
41
46
|
unless Hash.method_defined?(:present?)
|
42
47
|
class Hash
|
@@ -3,34 +3,18 @@ module Padrino
|
|
3
3
|
module Adapter
|
4
4
|
|
5
5
|
class << self
|
6
|
-
|
7
|
-
ADAPTERS = %w[thin mongrel webrick]
|
8
|
-
|
9
6
|
# Start for the given options a rackup handler
|
10
7
|
def start(options)
|
11
8
|
|
12
|
-
ENV["PADRINO_ENV"] = options.environment.to_s
|
13
|
-
|
14
|
-
boot = options.chdir ? File.join(options.chdir, options.boot) : options.boot
|
15
|
-
unless File.exist?(boot)
|
16
|
-
puts "=> Could not find boot file: #{boot.inspect} !!!"
|
17
|
-
exit
|
18
|
-
end
|
19
|
-
require boot
|
20
|
-
|
21
9
|
puts "=> Padrino/#{Padrino.version} has taken the stage #{options.environment} on port #{options.port}"
|
22
10
|
|
23
11
|
if options.daemonize?
|
24
|
-
unless fork
|
25
|
-
puts "=> Daemonized mode is not supported on your platform."
|
26
|
-
exit
|
27
|
-
end
|
28
12
|
|
29
13
|
stop # Need to stop a process if it exists
|
30
14
|
|
31
15
|
fork do
|
32
16
|
Process.setsid
|
33
|
-
|
17
|
+
return if fork
|
34
18
|
File.umask 0000
|
35
19
|
puts "=> Padrino server has been daemonized with pid #{Process.pid}"
|
36
20
|
STDIN.reopen "/dev/null"
|
@@ -42,38 +26,15 @@ module Padrino
|
|
42
26
|
|
43
27
|
if pid
|
44
28
|
File.open(pid, 'w'){ |f| f.write("#{Process.pid}") }
|
45
|
-
|
29
|
+
at_return { File.delete(pid) if File.exist?(pid) }
|
46
30
|
end
|
47
31
|
|
48
|
-
|
32
|
+
Padrino.run!(options.host, options.port, options.adapter)
|
49
33
|
|
50
34
|
end
|
51
35
|
else
|
52
|
-
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
# Method that run the Padrino.application
|
57
|
-
def run_app(options)
|
58
|
-
|
59
|
-
handler_name = options.adapter.to_s.capitalize
|
60
|
-
|
61
|
-
begin
|
62
|
-
handler = Rack::Handler.get(handler_name.downcase)
|
63
|
-
rescue
|
64
|
-
puts "#{handler_name} not supported yet, available adapters are: #{ADAPTERS.inspect}"
|
65
|
-
exit
|
66
|
-
end
|
67
|
-
|
68
|
-
handler.run Padrino.application, :Host => options.host, :Port => options.port do |server|
|
69
|
-
trap(:INT) do
|
70
|
-
# Use thins' hard #stop! if available, otherwise just #stop
|
71
|
-
server.respond_to?(:stop!) ? server.stop! : server.stop
|
72
|
-
puts "<= Padrino has ended his set (crowd applauds)"
|
73
|
-
end
|
36
|
+
Padrino.run!(options.host, options.port, options.adapter)
|
74
37
|
end
|
75
|
-
rescue Errno::EADDRINUSE
|
76
|
-
puts "=> Someone is already performing on port #{options.port}!"
|
77
38
|
end
|
78
39
|
|
79
40
|
# Method that stop (if exist) a running Padrino.application
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'rake/rdoctask'
|
4
|
+
|
5
|
+
Dir["lib/tasks/**/*.rake"].each { |ext| load(ext) }
|
6
|
+
|
7
|
+
# TODO: require here padrino-gen rake db:migrate, padrino-routes rake routes etc...
|
8
|
+
|
9
|
+
class Padrino::Tasks::RakeFile
|
10
|
+
cattr_accessor :boot_file
|
11
|
+
end
|
12
|
+
|
13
|
+
task :environment do
|
14
|
+
require Padrino::Tasks::RakeFile.boot_file
|
15
|
+
Padrino.mounted_apps.each do |app|
|
16
|
+
Padrino.require_dependency(app.app_file)
|
17
|
+
app.app_object.setup_application!
|
18
|
+
end
|
19
|
+
end
|
@@ -8,8 +8,9 @@ module Padrino
|
|
8
8
|
# It look for any spec/*_spec.rb and test/test_*.rb files in your app root.
|
9
9
|
def start
|
10
10
|
puts "=> Executing Tests..."
|
11
|
-
tests
|
12
|
-
tests << Dir['
|
11
|
+
tests = Dir['test/**/test_*.rb'] - ['test/test_helper.rb'] # TestUnit
|
12
|
+
tests << Dir['test/**/*_test.rb'] - ['test/test_config.rb'] # Bacon
|
13
|
+
tests << Dir['spec/**/*_spec.rb'] - Dir['spec/**/spec_helper.rb'] # Rspec
|
13
14
|
cmd = "ruby -rubygems -I.:lib -e'%w( #{tests.join(' ')} ).each { |file| require file }'"
|
14
15
|
system cmd
|
15
16
|
end
|
data/lib/padrino-core/tasks.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
require 'thor'
|
2
|
+
require 'thor/rake_compat'
|
2
3
|
require File.dirname(__FILE__) + "/tasks/helpers"
|
3
4
|
|
4
5
|
module Padrino
|
5
6
|
module Tasks
|
6
7
|
class Base < Thor
|
7
8
|
include Thor::Actions
|
9
|
+
include Thor::RakeCompat
|
8
10
|
include Padrino::Tasks::Helpers
|
9
11
|
|
10
12
|
class_option :chdir, :type => :string, :aliases => "-c"
|
@@ -16,44 +18,66 @@ module Padrino
|
|
16
18
|
method_option :port, :type => :numeric, :aliases => "-p", :required => true, :default => 3000
|
17
19
|
method_option :boot, :type => :string, :aliases => "-b", :required => true, :default => "config/boot.rb"
|
18
20
|
method_option :daemonize, :type => :boolean, :aliases => "-d"
|
19
|
-
|
20
21
|
def start
|
21
22
|
require File.dirname(__FILE__) + "/tasks/adapter"
|
22
|
-
|
23
|
+
boot = check_boot
|
24
|
+
return unless boot
|
25
|
+
require boot
|
23
26
|
Padrino::Tasks::Adapter.start(options)
|
24
27
|
end
|
25
28
|
|
26
29
|
desc "stop", "Stops the Padrino application"
|
27
30
|
def stop
|
28
31
|
require File.dirname(__FILE__) + "/tasks/adapter"
|
29
|
-
chdir(options.chdir)
|
30
32
|
Padrino::Tasks::Adapter.stop
|
31
33
|
end
|
32
34
|
|
33
35
|
desc "test", "Executes all the Padrino test files"
|
34
36
|
def test
|
35
37
|
require File.dirname(__FILE__) + "/tasks/test"
|
36
|
-
chdir(options.chdir)
|
37
38
|
Padrino::Tasks::Test.start
|
38
39
|
end
|
39
40
|
|
40
|
-
desc "
|
41
|
-
method_option :boot,
|
42
|
-
|
41
|
+
desc "rake", "Execute rake tasks in {Padrino.root}/lib/tasks"
|
42
|
+
method_option :boot, :type => :string, :aliases => "-b", :required => true, :default => "config/boot.rb"
|
43
|
+
method_option :environment, :type => :string, :aliases => "-e", :required => true, :default => :development
|
44
|
+
def rake
|
45
|
+
boot = check_boot
|
46
|
+
return unless boot
|
47
|
+
require 'rake'
|
48
|
+
puts "=> Executing Rake..."
|
49
|
+
Rake.application.init
|
50
|
+
load(File.dirname(__FILE__) + "/tasks/rake_tasks.rb")
|
51
|
+
Padrino::Tasks::RakeFile.boot_file = boot
|
52
|
+
Rake.application.top_level
|
53
|
+
end
|
54
|
+
|
55
|
+
desc "console", "Boots up the Padrino application irb console"
|
56
|
+
method_option :boot, :type => :string, :aliases => "-b", :required => true, :default => "config/boot.rb"
|
57
|
+
method_option :environment, :type => :string, :aliases => "-e", :required => true, :default => :development
|
58
|
+
def console
|
43
59
|
require File.dirname(__FILE__) + "/version"
|
44
|
-
boot =
|
45
|
-
unless
|
46
|
-
|
47
|
-
|
48
|
-
end
|
49
|
-
ENV["PADRINO_ENV"] ||= environment
|
50
|
-
puts "=> Loading #{environment} console (Padrino v.#{Padrino.version})"
|
60
|
+
boot = check_boot
|
61
|
+
return unless boot
|
62
|
+
ARGV.clear
|
63
|
+
puts "=> Loading #{options.environment} console (Padrino v.#{Padrino.version})"
|
51
64
|
require 'irb'
|
52
65
|
require "irb/completion"
|
53
66
|
require boot
|
54
67
|
require File.dirname(__FILE__) + '/tasks/console'
|
55
68
|
IRB.start
|
56
69
|
end
|
70
|
+
|
71
|
+
private
|
72
|
+
def check_boot
|
73
|
+
ENV["PADRINO_ENV"] ||= options.environment.to_s
|
74
|
+
chdir(options.chdir)
|
75
|
+
unless File.exist?(options.boot)
|
76
|
+
puts "=> Could not find boot file: #{options.boot.inspect} !!!"
|
77
|
+
return
|
78
|
+
end
|
79
|
+
options.boot
|
80
|
+
end
|
57
81
|
end
|
58
82
|
end
|
59
|
-
end
|
83
|
+
end
|
data/padrino-core.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{padrino-core}
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Padrino Team", "Nathan Esquenazi", "Davide D'Agostino", "Arthur Chiu"]
|
12
|
-
s.date = %q{2009-11-
|
12
|
+
s.date = %q{2009-11-30}
|
13
13
|
s.default_executable = %q{padrino}
|
14
14
|
s.description = %q{The Padrino core gem required for use of this framework}
|
15
15
|
s.email = %q{nesquena@gmail.com}
|
@@ -32,6 +32,7 @@ Gem::Specification.new do |s|
|
|
32
32
|
"lib/padrino-core/logger.rb",
|
33
33
|
"lib/padrino-core/mounter.rb",
|
34
34
|
"lib/padrino-core/reloader.rb",
|
35
|
+
"lib/padrino-core/server.rb",
|
35
36
|
"lib/padrino-core/stat.rb",
|
36
37
|
"lib/padrino-core/support_lite.rb",
|
37
38
|
"lib/padrino-core/support_lite/as_support.rb",
|
@@ -40,6 +41,7 @@ Gem::Specification.new do |s|
|
|
40
41
|
"lib/padrino-core/tasks/adapter.rb",
|
41
42
|
"lib/padrino-core/tasks/console.rb",
|
42
43
|
"lib/padrino-core/tasks/helpers.rb",
|
44
|
+
"lib/padrino-core/tasks/rake_tasks.rb",
|
43
45
|
"lib/padrino-core/tasks/test.rb",
|
44
46
|
"lib/padrino-core/version.rb",
|
45
47
|
"padrino-core.gemspec",
|
@@ -49,10 +51,12 @@ Gem::Specification.new do |s|
|
|
49
51
|
"test/fixtures/apps/simple.rb",
|
50
52
|
"test/helper.rb",
|
51
53
|
"test/test_application.rb",
|
54
|
+
"test/test_logger.rb",
|
52
55
|
"test/test_padrino_core.rb",
|
53
56
|
"test/test_padrino_mounter.rb",
|
54
57
|
"test/test_reloader_complex.rb",
|
55
|
-
"test/test_reloader_simple.rb"
|
58
|
+
"test/test_reloader_simple.rb",
|
59
|
+
"test/test_server.rb"
|
56
60
|
]
|
57
61
|
s.homepage = %q{http://github.com/padrino/padrino-framework/tree/master/padrino-core}
|
58
62
|
s.rdoc_options = ["--charset=UTF-8"]
|
@@ -3,12 +3,7 @@ PADRINO_ROOT = File.dirname(__FILE__) unless defined? PADRINO_ROOT
|
|
3
3
|
#
|
4
4
|
# require 'rubygems'
|
5
5
|
# require 'lib/padrino-core'
|
6
|
-
#
|
7
|
-
# Use this for prevent (when reload is in use) to re run the server.
|
8
|
-
#
|
9
|
-
# if Padrino.load!
|
10
|
-
# SingleDemo.run!
|
11
|
-
# end
|
6
|
+
#
|
12
7
|
|
13
8
|
class SimpleDemo < Padrino::Application
|
14
9
|
set :reload, true
|
@@ -16,8 +11,8 @@ end
|
|
16
11
|
|
17
12
|
SimpleDemo.controllers do
|
18
13
|
get "/" do
|
19
|
-
'The magick number is:
|
14
|
+
'The magick number is: 60!' # Change only the number!!!
|
20
15
|
end
|
21
16
|
end
|
22
17
|
|
23
|
-
Padrino.load! #
|
18
|
+
Padrino.load! # Replace this with Parino.run! unless Padrino.loaded? if you want to run the app standalone
|
data/test/helper.rb
CHANGED
@@ -11,6 +11,18 @@ require 'rack/test'
|
|
11
11
|
require 'rack'
|
12
12
|
require 'shoulda'
|
13
13
|
|
14
|
+
module Kernel
|
15
|
+
# Silences the output by redirecting to stringIO
|
16
|
+
# silence_logger { ...commands... } => "...output..."
|
17
|
+
def silence_logger(&block)
|
18
|
+
$stdout = log_buffer = StringIO.new
|
19
|
+
block.call
|
20
|
+
$stdout = STDOUT
|
21
|
+
log_buffer.string
|
22
|
+
end
|
23
|
+
alias :silence_stdout :silence_logger
|
24
|
+
end
|
25
|
+
|
14
26
|
class Padrino::Application
|
15
27
|
# Allow assertions in request context
|
16
28
|
include Test::Unit::Assertions
|
@@ -55,16 +67,4 @@ class Test::Unit::TestCase
|
|
55
67
|
end
|
56
68
|
|
57
69
|
alias :response :last_response
|
58
|
-
end
|
59
|
-
#
|
60
|
-
# class Object
|
61
|
-
# # Silences the output by redirecting to stringIO
|
62
|
-
# # silence_logger { ...commands... } => "...output..."
|
63
|
-
# def silence_logger(&block)
|
64
|
-
# orig_stdout = $stdout
|
65
|
-
# $stdout = log_buffer = StringIO.new
|
66
|
-
# block.call
|
67
|
-
# $stdout = orig_stdout
|
68
|
-
# log_buffer.rewind && log_buffer.read
|
69
|
-
# end
|
70
|
-
# end
|
70
|
+
end
|
data/test/test_logger.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/helper'
|
2
|
+
|
3
|
+
class TestPadrinoLogger < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
Padrino::Logger::Config[:test][:stream] = :null # The default
|
7
|
+
Padrino::Logger.setup!
|
8
|
+
end
|
9
|
+
|
10
|
+
def setup_logger(options={})
|
11
|
+
@log = StringIO.new
|
12
|
+
@logger = Padrino::Logger.new(options.merge(:stream => @log))
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'for logger functionality' do
|
16
|
+
|
17
|
+
context 'check stream config' do
|
18
|
+
|
19
|
+
should 'use stdout if stream is nil' do
|
20
|
+
Padrino::Logger::Config[:test][:stream] = nil
|
21
|
+
Padrino::Logger.setup!
|
22
|
+
assert_equal $stdout, Padrino.logger.log
|
23
|
+
end
|
24
|
+
|
25
|
+
should 'use StringIO as default for test' do
|
26
|
+
assert_instance_of StringIO, Padrino.logger.log
|
27
|
+
end
|
28
|
+
|
29
|
+
should 'use a custom stream' do
|
30
|
+
my_stream = StringIO.new
|
31
|
+
Padrino::Logger::Config[:test][:stream] = my_stream
|
32
|
+
Padrino::Logger.setup!
|
33
|
+
assert_equal my_stream, Padrino.logger.log
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
should 'log something' do
|
38
|
+
setup_logger(:log_level => :error)
|
39
|
+
@logger.error "You log this error?"
|
40
|
+
assert_match(/You log this error?/, @log.string)
|
41
|
+
@logger.debug "You don't log this error!"
|
42
|
+
assert_no_match(/You don't log this error!/, @log.string)
|
43
|
+
@logger << "Yep this can be logged"
|
44
|
+
assert_match(/Yep this can be logged/, @log.string)
|
45
|
+
end
|
46
|
+
|
47
|
+
should 'log an application' do
|
48
|
+
mock_app { get("/"){ "Foo" } }
|
49
|
+
get "/"
|
50
|
+
assert_equal "Foo", body
|
51
|
+
assert_match /GET \/ - 200/, Padrino.logger.log.string
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
data/test/test_padrino_core.rb
CHANGED
@@ -19,9 +19,7 @@ class TestPadrinoCore < Test::Unit::TestCase
|
|
19
19
|
|
20
20
|
should 'raise application error if I instantiate a new padrino application without mounted apps' do
|
21
21
|
Padrino.mounted_apps.clear
|
22
|
-
assert_raise
|
23
|
-
Padrino.application.tap { }
|
24
|
-
end
|
22
|
+
assert_raise(Padrino::ApplicationLoadError) { Padrino.application.new }
|
25
23
|
end
|
26
24
|
end
|
27
25
|
end
|
@@ -35,9 +35,10 @@ class TestComplexReloader < Test::Unit::TestCase
|
|
35
35
|
get "/complex_2_demo/old"
|
36
36
|
assert_equal 200, status
|
37
37
|
|
38
|
-
new_phrase =
|
39
|
-
buffer
|
40
|
-
|
38
|
+
new_phrase = "The magick number is: #{rand(100)}!"
|
39
|
+
buffer = File.read(Complex1Demo.app_file)
|
40
|
+
new_buffer = buffer.gsub(/The magick number is: \d+!/, new_phrase)
|
41
|
+
File.open(Complex1Demo.app_file, "w") { |f| f.write(new_buffer) }
|
41
42
|
sleep 1.2 # We need at least a cooldown of 1 sec.
|
42
43
|
get "/complex_2_demo"
|
43
44
|
assert_equal new_phrase, body
|
@@ -54,6 +55,9 @@ class TestComplexReloader < Test::Unit::TestCase
|
|
54
55
|
|
55
56
|
get "/complex_2_demo/old"
|
56
57
|
assert_equal 200, status
|
58
|
+
|
59
|
+
# Now we need to prevent to commit a new changed file so we revert it
|
60
|
+
File.open(Complex1Demo.app_file, "w") { |f| f.write(buffer) }
|
57
61
|
end
|
58
62
|
end
|
59
63
|
end
|
@@ -37,12 +37,16 @@ class TestSimpleReloader < Test::Unit::TestCase
|
|
37
37
|
@app = SimpleDemo
|
38
38
|
get "/"
|
39
39
|
assert_equal 200, status
|
40
|
-
new_phrase =
|
41
|
-
buffer
|
42
|
-
|
40
|
+
new_phrase = "The magick number is: #{rand(100)}!"
|
41
|
+
buffer = File.read(SimpleDemo.app_file)
|
42
|
+
new_buffer = buffer.gsub(/The magick number is: \d+!/, new_phrase)
|
43
|
+
File.open(SimpleDemo.app_file, "w") { |f| f.write(new_buffer) }
|
43
44
|
sleep 1.2 # We need at least a cooldown of 1 sec.
|
44
45
|
get "/"
|
45
46
|
assert_equal new_phrase, body
|
47
|
+
|
48
|
+
# Now we need to prevent to commit a new changed file so we revert it
|
49
|
+
File.open(SimpleDemo.app_file, "w") { |f| f.write(buffer) }
|
46
50
|
end
|
47
51
|
end
|
48
52
|
end
|
data/test/test_server.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/helper'
|
2
|
+
|
3
|
+
module Rack::Handler
|
4
|
+
class Mock
|
5
|
+
extend Test::Unit::Assertions
|
6
|
+
|
7
|
+
def self.run(app, options={})
|
8
|
+
assert_equal 9001, options[:Port]
|
9
|
+
assert_equal 'foo.local', options[:Host]
|
10
|
+
yield new
|
11
|
+
end
|
12
|
+
|
13
|
+
def stop
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
register 'mock', 'Rack::Handler::Mock'
|
18
|
+
Padrino::Server::Handlers << 'mock'
|
19
|
+
end
|
20
|
+
|
21
|
+
class ServerApp < Padrino::Application; end
|
22
|
+
|
23
|
+
class ServerTest < Test::Unit::TestCase
|
24
|
+
def setup
|
25
|
+
Padrino.mount_core("server_app")
|
26
|
+
end
|
27
|
+
|
28
|
+
context 'for server functionality' do
|
29
|
+
should "locates the appropriate Rack handler and calls ::run" do
|
30
|
+
Padrino.run!('foo.local', 9001, 'mock')
|
31
|
+
end
|
32
|
+
|
33
|
+
should "falls back on the next server handler when not found" do
|
34
|
+
assert_raise(Padrino::Server::LoadError) { Padrino.run!('foo.local', 9001, 'foo') }
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
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.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Padrino Team
|
@@ -12,7 +12,7 @@ autorequire:
|
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
14
|
|
15
|
-
date: 2009-11-
|
15
|
+
date: 2009-11-30 00:00:00 -08:00
|
16
16
|
default_executable: padrino
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
@@ -118,6 +118,7 @@ files:
|
|
118
118
|
- lib/padrino-core/logger.rb
|
119
119
|
- lib/padrino-core/mounter.rb
|
120
120
|
- lib/padrino-core/reloader.rb
|
121
|
+
- lib/padrino-core/server.rb
|
121
122
|
- lib/padrino-core/stat.rb
|
122
123
|
- lib/padrino-core/support_lite.rb
|
123
124
|
- lib/padrino-core/support_lite/as_support.rb
|
@@ -126,6 +127,7 @@ files:
|
|
126
127
|
- lib/padrino-core/tasks/adapter.rb
|
127
128
|
- lib/padrino-core/tasks/console.rb
|
128
129
|
- lib/padrino-core/tasks/helpers.rb
|
130
|
+
- lib/padrino-core/tasks/rake_tasks.rb
|
129
131
|
- lib/padrino-core/tasks/test.rb
|
130
132
|
- lib/padrino-core/version.rb
|
131
133
|
- padrino-core.gemspec
|
@@ -135,10 +137,12 @@ files:
|
|
135
137
|
- test/fixtures/apps/simple.rb
|
136
138
|
- test/helper.rb
|
137
139
|
- test/test_application.rb
|
140
|
+
- test/test_logger.rb
|
138
141
|
- test/test_padrino_core.rb
|
139
142
|
- test/test_padrino_mounter.rb
|
140
143
|
- test/test_reloader_complex.rb
|
141
144
|
- test/test_reloader_simple.rb
|
145
|
+
- test/test_server.rb
|
142
146
|
has_rdoc: true
|
143
147
|
homepage: http://github.com/padrino/padrino-framework/tree/master/padrino-core
|
144
148
|
licenses: []
|