padrino-core 0.6.3 → 0.6.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,10 +1,12 @@
1
1
  module Padrino
2
+ ##
2
3
  # High performant source reloader
3
4
  #
4
5
  # This class acts as Rack middleware.
5
6
  #
6
7
  # It is performing a check/reload cycle at the start of every request, but
7
8
  # also respects a cool down time, during which nothing will be done.
9
+ #
8
10
  class Reloader
9
11
 
10
12
  def initialize(app, cooldown = 1)
@@ -26,6 +28,6 @@ module Padrino
26
28
 
27
29
  @app.call(env)
28
30
  end
29
- end
30
- end
31
+ end # Reloader
32
+ end # Padrino
31
33
 
@@ -1,10 +1,22 @@
1
1
  module Padrino
2
2
 
3
+ ##
4
+ # Run the Padrino apps as a self-hosted server using:
5
+ # thin, mongrel, webrick in that order.
6
+ #
7
+ # Examples:
8
+ #
9
+ # Padrino.run! # with these defaults => host: "localhost", port: "3000", adapter: the first found
10
+ # Padrino.run!("localhost", "4000", "mongrel") # use => host: "localhost", port: "3000", adapter: "mongrel"
11
+ #
3
12
  def self.run!(*args)
4
13
  Padrino.load! unless Padrino.loaded?
5
14
  Server.build(*args)
6
15
  end
7
16
 
17
+ ##
18
+ # This module build a Padrino server
19
+ #
8
20
  module Server
9
21
 
10
22
  class LoadError < RuntimeError; end
@@ -49,5 +61,5 @@ module Padrino
49
61
  end
50
62
  raise LoadError, "Server handler (#{servers.join(',')}) not found."
51
63
  end
52
- end
53
- end
64
+ end # Server
65
+ end # Padrino
@@ -1,12 +1,14 @@
1
1
  require 'pathname'
2
2
 
3
3
  module Padrino
4
+ ##
4
5
  # What makes it especially suited for use in a any environment is that
5
6
  # any file will only be checked once and there will only be made one system
6
7
  # call stat(2).
7
8
  #
8
9
  # Please note that this will not reload files in the background, it does so
9
10
  # only when actively called.
11
+ #
10
12
  module Stat
11
13
  class << self
12
14
  CACHE = {}
@@ -28,7 +30,9 @@ module Padrino
28
30
  changed
29
31
  end
30
32
 
33
+ ##
31
34
  # A safe Kernel::load, issuing the hooks depending on the results
35
+ #
32
36
  def safe_load(file, mtime)
33
37
  logger.debug "Reloading #{file}"
34
38
  load(file)
@@ -41,7 +45,7 @@ module Padrino
41
45
 
42
46
  def rotation
43
47
  files = [$0, *$LOADED_FEATURES].uniq
44
- paths = ['./', *$LOAD_PATH].uniq
48
+ paths = ['./', *$:].uniq
45
49
 
46
50
  files.map{ |file|
47
51
  next if file =~ /\.(so|bundle)$/ # cannot reload compiled files
@@ -54,9 +58,11 @@ module Padrino
54
58
  }.compact
55
59
  end
56
60
 
61
+ ##
57
62
  # Takes a relative or absolute +file+ name, a couple possible +paths+ that
58
63
  # the +file+ might reside in. Returns the full path and File::Stat for the
59
64
  # path.
65
+ #
60
66
  def figure_path(file, paths)
61
67
  found = CACHE[file]
62
68
  found = file if !found and Pathname.new(file).absolute?
@@ -79,6 +85,6 @@ module Padrino
79
85
  rescue Errno::ENOENT, Errno::ENOTDIR
80
86
  CACHE.delete(file) and false
81
87
  end
82
- end
83
- end
84
- end
88
+ end # self
89
+ end # Stat
90
+ end # Padrino
@@ -1,36 +1,38 @@
1
- =begin
2
-
3
- This file determines if extlib or activesupport are already loaded, and then ensures
4
- the required objects and methods exist for Padrino to use.
5
-
6
- Required for Padrino to run:
7
-
8
- * Class#cattr_accessor
9
- * Module#alias_method_chain
10
- * String#inflectors (classify, underscore, camelize, etc)
11
- * Array#extract_options!
12
- * Object#blank?
13
- * Object#present?
14
- * Hash#slice, Hash#slice!
15
- * Hash#to_params
16
- * Hash#symbolize_keys, Hash.symbolize_keys!
17
- * Hash#reverse_merge, Hash#reverse_merge!
18
- * SupportLite::OrderedHash
19
-
20
- =end
1
+ ##
2
+ # This file determines if extlib or activesupport are already loaded, and then ensures
3
+ # the required objects and methods exist for Padrino to use.
4
+ #
5
+ # Required for Padrino to run:
6
+ #
7
+ # * Class#cattr_accessor
8
+ # * Module#alias_method_chain
9
+ # * String#inflectors (classify, underscore, camelize, etc)
10
+ # * Array#extract_options!
11
+ # * Object#blank?
12
+ # * Object#present?
13
+ # * Hash#slice, Hash#slice!
14
+ # * Hash#to_params
15
+ # * Hash#symbolize_keys, Hash.symbolize_keys!
16
+ # * Hash#reverse_merge, Hash#reverse_merge!
17
+ # * SupportLite::OrderedHash
18
+ #
21
19
  require 'i18n'
22
20
 
21
+ ##
23
22
  # Load our locales
23
+ #
24
24
  I18n.load_path += Dir["#{File.dirname(__FILE__)}/locale/*.yml"]
25
25
 
26
26
  module Padrino
27
+ ##
27
28
  # Return the current support used.
28
29
  # Can be one of: :extlib, :active_support
30
+ #
29
31
  def self.support
30
32
  @_padrino_support
31
33
  end
32
34
 
33
- end
35
+ end # Padrino
34
36
 
35
37
  if defined?(Extlib) # load if already using extlib
36
38
  Padrino.instance_variable_set(:@_padrino_support, :extlib)
@@ -1,6 +1,7 @@
1
1
  module Padrino
2
2
 
3
- # Ti module it's used for bootstrap with padrino rake
3
+ ##
4
+ # This module it's used for bootstrap with padrino rake
4
5
  # thirdy party tasks, in your gem/plugin/extension you
5
6
  # need only do this:
6
7
  #
@@ -8,10 +9,12 @@ module Padrino
8
9
  #
9
10
  module Tasks
10
11
 
12
+ ##
11
13
  # Returns a list of files to handle with padrino rake
14
+ #
12
15
  def self.files
13
16
  @files ||= []
14
17
  end
15
18
 
16
- end
17
- end
19
+ end # Tasks
20
+ end # Padrino
@@ -1,7 +1,13 @@
1
+ ##
1
2
  # Manages Padrino version from the VERSION file managed by Jeweler
2
-
3
+ # We put this in a separate file so you can get padrino version
4
+ # without include full padrino core.
5
+ #
3
6
  module Padrino
7
+ ##
8
+ # Return the current Padrino version
9
+ #
4
10
  def self.version
5
11
  @version ||= File.read(File.dirname(__FILE__) + '/../../VERSION').chomp
6
12
  end
7
- end
13
+ end # Padrino
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.6.3"
8
+ s.version = "0.6.7"
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{2010-01-15}
12
+ s.date = %q{2010-01-26}
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}
@@ -40,7 +40,6 @@ Gem::Specification.new do |s|
40
40
  "lib/padrino-core/logger.rb",
41
41
  "lib/padrino-core/mounter.rb",
42
42
  "lib/padrino-core/reloader.rb",
43
- "lib/padrino-core/routing.rb",
44
43
  "lib/padrino-core/server.rb",
45
44
  "lib/padrino-core/stat.rb",
46
45
  "lib/padrino-core/support_lite.rb",
@@ -53,9 +52,13 @@ Gem::Specification.new do |s|
53
52
  "test/fixtures/apps/.gitignore",
54
53
  "test/fixtures/apps/complex.rb",
55
54
  "test/fixtures/apps/simple.rb",
55
+ "test/fixtures/dependencies/a.rb",
56
+ "test/fixtures/dependencies/b.rb",
57
+ "test/fixtures/dependencies/c.rb",
56
58
  "test/helper.rb",
57
59
  "test/test_application.rb",
58
60
  "test/test_core.rb",
61
+ "test/test_dependencies.rb",
59
62
  "test/test_logger.rb",
60
63
  "test/test_mounter.rb",
61
64
  "test/test_reloader_complex.rb",
@@ -15,4 +15,10 @@ SimpleDemo.controllers do
15
15
  end
16
16
  end
17
17
 
18
- Padrino.load! # Replace this with Parino.run! unless Padrino.loaded? if you want to run the app standalone
18
+ ## If you want use this as a standalone app uncomment:
19
+ #
20
+ # Padrino.mount_core("SimpleDemo")
21
+ # Padrino.run! unless Padrino.loaded? # If you enable reloader prevent to re-run the app
22
+ #
23
+
24
+ Padrino.load!
@@ -0,0 +1,4 @@
1
+ A = "A"
2
+
3
+ # But here we need some of b.rb
4
+ A_result = [B, A]
@@ -0,0 +1,4 @@
1
+ B = "B"
2
+
3
+ # Here we need some of c.rb
4
+ B_result = [C, B]
@@ -0,0 +1 @@
1
+ C = "C"
data/test/helper.rb CHANGED
@@ -18,6 +18,14 @@ module Kernel
18
18
  log_buffer.string
19
19
  end
20
20
  alias :silence_stdout :silence_logger
21
+
22
+ def silence_warnings
23
+ old_verbose, $VERBOSE = $VERBOSE, nil
24
+ yield
25
+ ensure
26
+ $VERBOSE = old_verbose
27
+ end unless respond_to?(:silence_warnings)
28
+
21
29
  end
22
30
 
23
31
  class Class
data/test/test_core.rb CHANGED
@@ -5,8 +5,11 @@ class TestCore < Test::Unit::TestCase
5
5
  context 'for core functionality' do
6
6
 
7
7
  should 'check some global methods' do
8
- assert_respond_to Padrino, :env
9
8
  assert_respond_to Padrino, :root
9
+ assert_respond_to Padrino, :env
10
+ assert_respond_to Padrino, :application
11
+ assert_respond_to Padrino, :set_encoding
12
+ assert_respond_to Padrino, :require_dependencies!
10
13
  assert_respond_to Padrino, :load!
11
14
  assert_respond_to Padrino, :reload!
12
15
  assert_respond_to Padrino, :version
@@ -16,7 +19,20 @@ class TestCore < Test::Unit::TestCase
16
19
  assert_equal :test, Padrino.env
17
20
  assert_match /\/test/, Padrino.root
18
21
  end
19
-
22
+
23
+ should 'set correct utf-8 encoding' do
24
+ Padrino.set_encoding
25
+ if RUBY_VERSION >= '1.9'
26
+ assert_equal nil, $KCODE
27
+ else
28
+ assert_equal 'UTF8', $KCODE
29
+ end
30
+ end
31
+
32
+ should 'have load paths' do
33
+ assert_equal [Padrino.root('lib'), Padrino.root('models'), Padrino.root('shared')], Padrino.load_paths
34
+ end
35
+
20
36
  should 'raise application error if I instantiate a new padrino application without mounted apps' do
21
37
  Padrino.mounted_apps.clear
22
38
  assert_raise(Padrino::ApplicationLoadError) { Padrino.application.new }
@@ -0,0 +1,27 @@
1
+ require File.dirname(__FILE__) + '/helper'
2
+
3
+ class TestDependencies < Test::Unit::TestCase
4
+ context 'when we require a dependency that have another dependecy' do
5
+
6
+ should 'raise an error without padrino' do
7
+ assert_raise NameError do
8
+ require "fixtures/dependencies/a.rb"
9
+ require "fixtures/dependencies/b.rb"
10
+ require "fixtures/dependencies/c.rb"
11
+ end
12
+ end
13
+
14
+ should 'resolve dependency problems' do
15
+ silence_warnings do
16
+ Padrino.require_dependencies(
17
+ Padrino.root("fixtures/dependencies/a.rb"),
18
+ Padrino.root("fixtures/dependencies/b.rb"),
19
+ Padrino.root("fixtures/dependencies/c.rb")
20
+ )
21
+ end
22
+ assert_equal ["B", "A"], A_result
23
+ assert_equal ["C", "B"], B_result
24
+ end
25
+ end
26
+
27
+ 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.6.3
4
+ version: 0.6.7
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: 2010-01-15 00:00:00 +01:00
15
+ date: 2010-01-26 00:00:00 +01:00
16
16
  default_executable: padrino
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
@@ -146,7 +146,6 @@ files:
146
146
  - lib/padrino-core/logger.rb
147
147
  - lib/padrino-core/mounter.rb
148
148
  - lib/padrino-core/reloader.rb
149
- - lib/padrino-core/routing.rb
150
149
  - lib/padrino-core/server.rb
151
150
  - lib/padrino-core/stat.rb
152
151
  - lib/padrino-core/support_lite.rb
@@ -159,9 +158,13 @@ files:
159
158
  - test/fixtures/apps/.gitignore
160
159
  - test/fixtures/apps/complex.rb
161
160
  - test/fixtures/apps/simple.rb
161
+ - test/fixtures/dependencies/a.rb
162
+ - test/fixtures/dependencies/b.rb
163
+ - test/fixtures/dependencies/c.rb
162
164
  - test/helper.rb
163
165
  - test/test_application.rb
164
166
  - test/test_core.rb
167
+ - test/test_dependencies.rb
165
168
  - test/test_logger.rb
166
169
  - test/test_mounter.rb
167
170
  - test/test_reloader_complex.rb
File without changes