Module: Padrino
- Extended by:
- Configuration, Loader
- Defined in:
- lib/padrino-core/version.rb,
lib/padrino-core.rb,
lib/padrino-core/tasks.rb,
lib/padrino-core/caller.rb,
lib/padrino-core/filter.rb,
lib/padrino-core/loader.rb,
lib/padrino-core/logger.rb,
lib/padrino-core/module.rb,
lib/padrino-core/router.rb,
lib/padrino-core/server.rb,
lib/padrino-core/command.rb,
lib/padrino-core/mounter.rb,
lib/padrino-core/cli/base.rb,
lib/padrino-core/reloader.rb,
lib/padrino-core/application.rb,
lib/padrino-core/cli/adapter.rb,
lib/padrino-core/cli/binstub.rb,
lib/padrino-core/path_router.rb,
lib/padrino-core/cli/launcher.rb,
lib/padrino-core/configuration.rb,
lib/padrino-core/reloader/rack.rb,
lib/padrino-core/reloader/storage.rb,
lib/padrino-core/application/flash.rb,
lib/padrino-core/path_router/route.rb,
lib/padrino-core/application/routing.rb,
lib/padrino-core/path_router/matcher.rb,
lib/padrino-core/path_router/compiler.rb,
lib/padrino-core/path_router/error_handler.rb,
lib/padrino-core/application/show_exceptions.rb,
lib/padrino-core/application/application_setup.rb,
lib/padrino-core/application/params_protection.rb,
lib/padrino-core/mounter/application_extension.rb,
lib/padrino-core/application/authenticity_token.rb
Overview
Manages current Padrino version for use in gem generation.
We put this in a separate file so you can get padrino version without include full padrino core.
Defined Under Namespace
Modules: ApplicationSetup, Cli, Configuration, Flash, Loader, Module, ParamsProtection, PathRouter, Reloader, Routing, Tasks Classes: Application, ApplicationLoadError, AuthenticityToken, Filter, Logger, Mounter, Router, Server, ShowExceptions
Constant Summary collapse
- PADRINO_IGNORE_CALLERS =
List of callers in a Padrino application that should be ignored as part of a stack trace.
[ *Sinatra::Base.callers_to_ignore, # Inherit Sinatra's default ignore patterns Regexp.new(Regexp.escape(RbConfig::CONFIG['rubylibdir'])), # Ignore the Ruby standard lib path %r{lib/padrino-.*$}, %r{/padrino-.*/(lib|bin)}, %r{/bin/padrino$}, %r{lib/rack.*\.rb$}, %r{lib/mongrel.*\.rb$}, %r{lib/shotgun.*\.rb$}, %r{bin/shotgun$}, %r{shoulda/context\.rb$}, %r{mocha/integration}, %r{test/unit}, /rake_test_loader\.rb/, /custom_require\.rb$/, %r{/thor} ]
- VERSION =
The version constant for the current version of Padrino.
'0.16.0'
Class Attribute Summary collapse
-
.mounted_root(*args) ⇒ String
The root to the mounted apps base directory.
Class Method Summary collapse
-
.add_middleware(router) ⇒ Object
Creates Rack stack with the router added to the middleware chain.
-
.application ⇒ Padrino::Router
The resulting rack builder mapping each ‘mounted’ application.
-
.bin(*args) ⇒ Boolean
This method return the correct location of padrino bin or exec it using Kernel#system with the given args.
-
.caller_files ⇒ Array<String>
Like Kernel#caller but excluding certain magic entries and without line / method information; the resulting array contains filenames only.
-
.clear_middleware! ⇒ Array
Clears all previously configured middlewares.
-
.configure_apps { ... } ⇒ Object
Configure Global Project Settings for mounted apps.
- .detect_application(options) ⇒ Object
-
.env ⇒ Symbol
Helper method that return RACK_ENV.
-
.first_caller ⇒ String
The filename for the file that is the direct caller (first caller).
-
.gem(name, main_module) ⇒ Object
Registers a gem with padrino.
- .gems ⇒ Object
-
.global_configurations ⇒ Object
Stores global configuration blocks.
-
.insert_mounted_app(mounter) ⇒ Object
Inserts a Mounter object into the mounted applications (avoids duplicates).
- .logger ⇒ Padrino::Logger
-
.logger=(value) ⇒ Object
Set the padrino logger.
-
.middleware ⇒ Array<Array<Class, Array, Proc>>
A Rack::Builder object that allows to add middlewares in front of all Padrino applications.
- .modules ⇒ Object
-
.mount(name, options = {}) ⇒ Object
Mounts a new sub-application onto Padrino project.
-
.mounted_apps ⇒ Array
The mounted padrino applications (MountedApp objects).
-
.replace_with_binstub(executable) ⇒ Object
Replaces the current process with it’s binstub.
-
.root(*args) ⇒ String
Helper method for file references.
-
.ruby_command ⇒ String
Return the path to the ruby interpreter taking into account multiple installations and windows extensions.
-
.run!(options = {}) ⇒ Object
Runs the Padrino apps as a self-hosted server using: thin, mongrel, or WEBrick in that order.
-
.set_encoding ⇒ NilClass
Set
Encoding.default_internalandEncoding.default_externaltoEncoding::UFT_8. -
.use(middleware_class, *args) { ... } ⇒ Object
Convenience method for adding a Middleware to the whole padrino app.
-
.version ⇒ String
The current Padrino version.
Instance Method Summary collapse
-
#RUBY_IGNORE_CALLERS ⇒ Object
Add rubinius (and hopefully other VM implementations) ignore patterns …
Methods included from Configuration
Methods included from Loader
after_load, before_load, called_from, clear!, dependency_paths, load!, loaded?, precompile_all_routes!, reload!, require_dependencies
Class Attribute Details
.mounted_root(*args) ⇒ String
Returns the root to the mounted apps base directory.
236 237 238 |
# File 'lib/padrino-core/mounter.rb', line 236 def mounted_root(*args) Padrino.root(@mounted_root ||= '', *args) end |
Class Method Details
.add_middleware(router) ⇒ Object
Creates Rack stack with the router added to the middleware chain.
122 123 124 125 126 127 |
# File 'lib/padrino-core.rb', line 122 def add_middleware(router) builder = Rack::Builder.new middleware.each { |mw, args, block| builder.use(mw, *args, &block) } builder.run(router) builder.to_app end |
.application ⇒ Padrino::Router
The resulting rack builder mapping each ‘mounted’ application.
71 72 73 74 75 76 |
# File 'lib/padrino-core.rb', line 71 def application warn 'WARNING! No apps are mounted. Please, mount apps in `config/apps.rb`' if Padrino.mounted_apps.empty? router = Padrino::Router.new Padrino.mounted_apps.each { |app| app.map_onto(router) } middleware.empty? ? router : add_middleware(router) end |
.bin(*args) ⇒ Boolean
This method return the correct location of padrino bin or exec it using Kernel#system with the given args.
16 17 18 19 |
# File 'lib/padrino-core/command.rb', line 16 def self.bin(*args) @_padrino_bin ||= [self.ruby_command, File.('../../bin/padrino', __dir__)] args.empty? ? @_padrino_bin : system(args.unshift(@_padrino_bin).join(' ')) end |
.caller_files ⇒ Array<String>
Like Kernel#caller but excluding certain magic entries and without line / method information; the resulting array contains filenames only.
45 46 47 48 49 50 |
# File 'lib/padrino-core/caller.rb', line 45 def self.caller_files caller(1).each_with_object([]) do |line, result| file, = line.split(/:(?=\d|in )/)[0, 2] result << file unless PADRINO_IGNORE_CALLERS.any? { |pattern| file =~ pattern } end end |
.clear_middleware! ⇒ Array
Clears all previously configured middlewares.
146 147 148 |
# File 'lib/padrino-core.rb', line 146 def clear_middleware! @middleware = [] end |
.configure_apps { ... } ⇒ Object
Configure Global Project Settings for mounted apps. These can be overloaded in each individual app’s own personal configuration. This can be used like:
91 92 93 |
# File 'lib/padrino-core.rb', line 91 def configure_apps(&block) global_configurations << block if block_given? end |
.detect_application(options) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/padrino-core/server.rb', line 15 def self.detect_application() default_config_file = 'config.ru' config_file = .delete(:config) config_file ||= default_config_file if File.file?(default_config_file) return [Padrino.application, ] unless config_file raise "Rack config file `#{config_file}` must have `.ru` extension" unless config_file =~ /\.ru$/ rack_app, = Rack::Builder.parse_file(config_file) [rack_app, ( || {}).merge()] end |
.env ⇒ Symbol
Helper method that return RACK_ENV.
58 59 60 |
# File 'lib/padrino-core.rb', line 58 def env @_env ||= RACK_ENV.to_s.downcase.to_sym end |
.first_caller ⇒ String
The filename for the file that is the direct caller (first caller).
34 35 36 |
# File 'lib/padrino-core/caller.rb', line 34 def self.first_caller caller_files.first end |
.gem(name, main_module) ⇒ Object
Registers a gem with padrino. This relieves the caller from setting up loadpaths by itself and enables Padrino to look up apps in gem folder.
The name given has to be the proper gem name as given in the gemspec.
179 180 181 182 183 184 |
# File 'lib/padrino-core.rb', line 179 def gem(name, main_module) _, spec = Gem.loaded_specs.find { |spec_pair| spec_pair[0] == name } gems << spec modules << main_module spec.full_gem_path end |
.gems ⇒ Object
188 189 190 |
# File 'lib/padrino-core.rb', line 188 def gems @gems ||= [] end |
.global_configurations ⇒ Object
Stores global configuration blocks.
98 99 100 |
# File 'lib/padrino-core.rb', line 98 def global_configurations @_global_configurations ||= [] end |
.insert_mounted_app(mounter) ⇒ Object
Inserts a Mounter object into the mounted applications (avoids duplicates).
253 254 255 |
# File 'lib/padrino-core/mounter.rb', line 253 def insert_mounted_app(mounter) Padrino.mounted_apps.push(mounter) unless Padrino.mounted_apps.include?(mounter) end |
.logger ⇒ Padrino::Logger
18 19 20 |
# File 'lib/padrino-core/logger.rb', line 18 def self.logger Padrino::Logger.logger end |
.logger=(value) ⇒ Object
Set the padrino logger.
48 49 50 |
# File 'lib/padrino-core/logger.rb', line 48 def self.logger=(value) Padrino::Logger.logger = value end |
.middleware ⇒ Array<Array<Class, Array, Proc>>
A Rack::Builder object that allows to add middlewares in front of all Padrino applications.
136 137 138 |
# File 'lib/padrino-core.rb', line 136 def middleware @middleware ||= [] end |
.modules ⇒ Object
194 195 196 |
# File 'lib/padrino-core.rb', line 194 def modules @modules ||= [] end |
.mount(name, options = {}) ⇒ Object
Mounts a new sub-application onto Padrino project.
265 266 267 |
# File 'lib/padrino-core/mounter.rb', line 265 def mount(name, = {}) Mounter.new(name, ) end |
.mounted_apps ⇒ Array
Returns the mounted padrino applications (MountedApp objects).
244 245 246 |
# File 'lib/padrino-core/mounter.rb', line 244 def mounted_apps @mounted_apps ||= [] end |
.replace_with_binstub(executable) ⇒ Object
Replaces the current process with it’s binstub.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/padrino-core/cli/binstub.rb', line 5 def self.replace_with_binstub(executable) begin return if Bundler.definition.missing_specs.empty? rescue NameError, NoMethodError, Bundler::GemfileNotFound # Move forward end project_root = Dir.pwd until project_root.empty? break if File.file?(File.join(project_root, 'Gemfile')) project_root = project_root.rpartition('/').first end return unless %w[Gemfile .components].all? { |file| File.file?(File.join(project_root, file)) } binstub = File.join(project_root, 'bin', executable) if File.file?(binstub) exec Gem.ruby, binstub, *ARGV else puts 'Please run `bundle install --binstubs` from your project root to generate bundle-specific executables' exit! end end |
.root(*args) ⇒ String
Helper method for file references.
48 49 50 |
# File 'lib/padrino-core.rb', line 48 def root(*args) File.(File.join(PADRINO_ROOT, *args)) end |
.ruby_command ⇒ String
Return the path to the ruby interpreter taking into account multiple installations and windows extensions.
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/padrino-core/command.rb', line 28 def self.ruby_command @ruby_command ||= begin ruby = File.join(RbConfig::CONFIG['bindir'], RbConfig::CONFIG['ruby_install_name']) ruby << RbConfig::CONFIG['EXEEXT'] # escape string in case path to ruby executable contain spaces. ruby.sub!(/.*\s.*/m, '"\&"') ruby end end |
.run!(options = {}) ⇒ Object
Runs the Padrino apps as a self-hosted server using: thin, mongrel, or WEBrick in that order.
10 11 12 13 |
# File 'lib/padrino-core/server.rb', line 10 def self.run!( = {}) Padrino.load! Server.start(*detect_application()) end |
.set_encoding ⇒ NilClass
Set Encoding.default_internal and Encoding.default_external to Encoding::UFT_8.
Please note that in 1.9.2 with some template engines like haml you should turn off Encoding.default_internal to prevent problems.
113 114 115 116 117 |
# File 'lib/padrino-core.rb', line 113 def set_encoding # remove after 0.15 warn 'Warning! Padrino.set_encoding is deprecated. Padrino no longer manages ruby default encodings' nil end |
.use(middleware_class, *args) { ... } ⇒ Object
Convenience method for adding a Middleware to the whole padrino app.
162 163 164 |
# File 'lib/padrino-core.rb', line 162 def use(middleware_class, *args, &block) middleware << [middleware_class, args, block] end |
.version ⇒ String
The current Padrino version.
17 18 19 |
# File 'lib/padrino-core/version.rb', line 17 def self.version VERSION end |
Instance Method Details
#RUBY_IGNORE_CALLERS ⇒ Object
Add rubinius (and hopefully other VM implementations) ignore patterns …
25 |
# File 'lib/padrino-core/caller.rb', line 25 PADRINO_IGNORE_CALLERS.concat(RUBY_IGNORE_CALLERS) |