Module: Padrino
- Extended by:
- Configuration, Loader
- Defined in:
- padrino-core/lib/padrino-core/version.rb,
padrino-gen/lib/padrino-gen.rb,
padrino-core/lib/padrino-core.rb,
padrino-admin/lib/padrino-admin.rb,
padrino-cache/lib/padrino-cache.rb,
padrino-mailer/lib/padrino-mailer.rb,
padrino-performance/lib/suites/mem.rb,
padrino-core/lib/padrino-core/tasks.rb,
padrino-gen/lib/padrino-gen/command.rb,
padrino-helpers/lib/padrino-helpers.rb,
padrino-performance/lib/suites/json.rb,
padrino-core/lib/padrino-core/caller.rb,
padrino-core/lib/padrino-core/filter.rb,
padrino-core/lib/padrino-core/loader.rb,
padrino-core/lib/padrino-core/logger.rb,
padrino-core/lib/padrino-core/module.rb,
padrino-core/lib/padrino-core/router.rb,
padrino-core/lib/padrino-core/server.rb,
padrino-core/lib/padrino-core/command.rb,
padrino-core/lib/padrino-core/mounter.rb,
padrino-helpers/lib/padrino/rendering.rb,
padrino-core/lib/padrino-core/reloader.rb,
padrino-mailer/lib/padrino-mailer/base.rb,
padrino-mailer/lib/padrino-mailer/mime.rb,
padrino-helpers/lib/padrino/safe_buffer.rb,
padrino-core/lib/padrino-core/application.rb,
padrino-core/lib/padrino-core/path_router.rb,
padrino-mailer/lib/padrino-mailer/helpers.rb,
padrino-support/lib/padrino-support/utils.rb,
padrino-gen/lib/padrino-gen/generators/app.rb,
padrino-gen/lib/padrino-gen/generators/cli.rb,
padrino-core/lib/padrino-core/configuration.rb,
padrino-core/lib/padrino-core/reloader/rack.rb,
padrino-gen/lib/padrino-gen/generators/task.rb,
padrino-cache/lib/padrino-cache/helpers/page.rb,
padrino-gen/lib/padrino-gen/generators/model.rb,
padrino-gen/lib/padrino-gen/generators/helper.rb,
padrino-gen/lib/padrino-gen/generators/mailer.rb,
padrino-gen/lib/padrino-gen/generators/plugin.rb,
padrino-gen/lib/padrino-gen/generators/runner.rb,
padrino-admin/lib/padrino-admin/access_control.rb,
padrino-admin/lib/padrino-admin/generators/orm.rb,
padrino-core/lib/padrino-core/reloader/storage.rb,
padrino-gen/lib/padrino-gen/generators/actions.rb,
padrino-gen/lib/padrino-gen/generators/project.rb,
padrino-performance/lib/padrino-performance/os.rb,
padrino-core/lib/padrino-core/application/flash.rb,
padrino-core/lib/padrino-core/path_router/route.rb,
padrino-helpers/lib/padrino-helpers/tag_helpers.rb,
padrino-support/lib/padrino-support/inflections.rb,
padrino-cache/lib/padrino-cache/helpers/fragment.rb,
padrino-gen/lib/padrino-gen/generators/component.rb,
padrino-gen/lib/padrino-gen/generators/migration.rb,
padrino-helpers/lib/padrino-helpers/form_helpers.rb,
padrino-core/lib/padrino-core/application/routing.rb,
padrino-core/lib/padrino-core/path_router/matcher.rb,
padrino-gen/lib/padrino-gen/generators/controller.rb,
padrino-admin/lib/padrino-admin/generators/actions.rb,
padrino-core/lib/padrino-core/path_router/compiler.rb,
padrino-helpers/lib/padrino-helpers/format_helpers.rb,
padrino-helpers/lib/padrino-helpers/number_helpers.rb,
padrino-helpers/lib/padrino-helpers/output_helpers.rb,
padrino-helpers/lib/padrino-helpers/render_helpers.rb,
padrino-helpers/lib/padrino/rendering/erb_template.rb,
padrino-cache/lib/padrino-cache/helpers/cache_store.rb,
padrino-helpers/lib/padrino/rendering/haml_template.rb,
padrino-helpers/lib/padrino/rendering/slim_template.rb,
padrino-performance/lib/padrino-performance/version.rb,
padrino-admin/lib/padrino-admin/generators/admin_app.rb,
padrino-admin/lib/padrino-admin/helpers/view_helpers.rb,
padrino-cache/lib/padrino-cache/helpers/cache_object.rb,
padrino-helpers/lib/padrino/rendering/erubi_template.rb,
padrino-admin/lib/padrino-admin/generators/admin_page.rb,
padrino-helpers/lib/padrino-helpers/asset_tag_helpers.rb,
padrino-helpers/lib/padrino/rendering/erubis_template.rb,
padrino-helpers/lib/padrino/rendering/hamlit_template.rb,
padrino-core/lib/padrino-core/path_router/error_handler.rb,
padrino-helpers/lib/padrino-helpers/form_helpers/errors.rb,
padrino-helpers/lib/padrino-helpers/translation_helpers.rb,
padrino-support/lib/padrino-support/default_inflections.rb,
padrino-helpers/lib/padrino-helpers/form_helpers/options.rb,
padrino-core/lib/padrino-core/application/show_exceptions.rb,
padrino-helpers/lib/padrino-helpers/form_helpers/security.rb,
padrino-core/lib/padrino-core/application/application_setup.rb,
padrino-core/lib/padrino-core/application/params_protection.rb,
padrino-core/lib/padrino-core/mounter/application_extension.rb,
padrino-core/lib/padrino-core/application/authenticity_token.rb,
padrino-admin/lib/padrino-admin/helpers/authentication_helpers.rb,
padrino-helpers/lib/padrino-helpers/output_helpers/erb_handler.rb,
padrino-helpers/lib/padrino-helpers/output_helpers/haml_handler.rb,
padrino-helpers/lib/padrino-helpers/output_helpers/slim_handler.rb,
padrino-helpers/lib/padrino-helpers/output_helpers/abstract_handler.rb,
padrino-helpers/lib/padrino-helpers/form_builder/abstract_form_builder.rb,
padrino-helpers/lib/padrino-helpers/form_builder/standard_form_builder.rb
Overview
This module is based on Sequel 5.4.0 sequel-5.4.0/lib/sequel/model/default_inflections.rb
Defined Under Namespace
Modules: Admin, ApplicationSetup, Cache, Configuration, Flash, Generators, Helpers, Inflections, Loader, Mailer, Module, ParamsProtection, PathRouter, Performance, Reloader, Rendering, Routing, Tasks, Utils Classes: Application, AuthenticityToken, Filter, Logger, Mounter, Router, SafeBuffer, Server
Constant Summary collapse
- PADRINO_IGNORE_CALLERS =
List of callers in a Padrino application that should be ignored as part of a stack trace.
[ %r{lib/padrino-.*$}, %r{/padrino-.*/(lib|bin)}, %r{/bin/padrino$}, %r{/sinatra(/(base|main|show_?exceptions))?\.rb$}, %r{lib/tilt.*\.rb$}, %r{lib/rack.*\.rb$}, %r{lib/mongrel.*\.rb$}, %r{lib/shotgun.*\.rb$}, %r{bin/shotgun$}, %r{\(.*\)}, %r{shoulda/context\.rb$}, %r{mocha/integration}, %r{test/unit}, %r{rake_test_loader\.rb}, %r{custom_require\.rb$}, %r{active_support}, %r{/thor}, %r{/lib/bundler} ]
- VERSION =
The version constant for the current version of Padrino.
'0.16.0.pre3'
- DEFAULT_INFLECTIONS_PROC =
Proc that is instance evaled to create the default inflections for both the model inflector and the inflector extension.
proc do plural(/$/, 's') plural(/s$/i, 's') plural(/(alias|(?:stat|octop|vir|b)us)$/i, '\1es') plural(/(buffal|tomat)o$/i, '\1oes') plural(/([ti])um$/i, '\1a') plural(/sis$/i, 'ses') plural(/(?:([^f])fe|([lr])f)$/i, '\1\2ves') plural(/(hive)$/i, '\1s') plural(/([^aeiouy]|qu)y$/i, '\1ies') plural(/(x|ch|ss|sh)$/i, '\1es') plural(/(matr|vert|ind)ix|ex$/i, '\1ices') plural(/([m|l])ouse$/i, '\1ice') singular(/s$/i, '') singular(/([ti])a$/i, '\1um') singular(/(analy|ba|cri|diagno|parenthe|progno|synop|the)ses$/i, '\1sis') singular(/([^f])ves$/i, '\1fe') singular(/([h|t]ive)s$/i, '\1') singular(/([lr])ves$/i, '\1f') singular(/([^aeiouy]|qu)ies$/i, '\1y') singular(/(m)ovies$/i, '\1ovie') singular(/(x|ch|ss|sh)es$/i, '\1') singular(/([m|l])ice$/i, '\1ouse') singular(/buses$/i, 'bus') singular(/oes$/i, 'o') singular(/shoes$/i, 'shoe') singular(/(alias|(?:stat|octop|vir|b)us)es$/i, '\1') singular(/(vert|ind)ices$/i, '\1ex') singular(/matrices$/i, 'matrix') irregular('person', 'people') irregular('man', 'men') irregular('child', 'children') irregular('sex', 'sexes') irregular('move', 'moves') irregular('quiz', 'quizzes') irregular('testis', 'testes') uncountable(%w(equipment information rice money species series fish sheep news)) end
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.
- .after_load(&block) ⇒ Object
-
.application ⇒ Padrino::Router
The resulting rack builder mapping each ‘mounted’ application.
- .before_load(&block) ⇒ Object
-
.bin(*args) ⇒ Boolean
This method return the correct location of padrino bin or exec it using Kernel#system with the given args.
-
.bin_gen(*args) ⇒ Object
This method return the correct location of padrino-gen bin or exec it using Kernel#system with the given args.
-
.cache ⇒ Object
Returns the caching engine.
-
.cache=(value) ⇒ Object
Set the caching engine.
-
.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).
- .perf_memusage_command ⇒ Object
-
.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_internal
andEncoding.default_external
toEncoding::UFT_8
. -
.use(mw, *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
Class Method Details
.add_middleware(router) ⇒ Object
Creates Rack stack with the router added to the middleware chain.
123 124 125 126 127 128 |
# File 'padrino-core/lib/padrino-core.rb', line 123 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 |
.after_load(&block) ⇒ Object
9 10 11 12 13 |
# File 'padrino-performance/lib/suites/mem.rb', line 9 def after_load(&block) @_after_load ||= [] @_after_load << block if block_given? @_after_load end |
.application ⇒ Padrino::Router
The resulting rack builder mapping each ‘mounted’ application.
71 72 73 74 75 76 |
# File 'padrino-core/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 |
.before_load(&block) ⇒ Object
3 4 5 6 7 |
# File 'padrino-performance/lib/suites/mem.rb', line 3 def before_load(&block) @_before_load ||= [] @_before_load << block if block_given? @_before_load 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 'padrino-core/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 |
.bin_gen(*args) ⇒ Object
This method return the correct location of padrino-gen bin or exec it using Kernel#system with the given args.
14 15 16 17 |
# File 'padrino-gen/lib/padrino-gen/command.rb', line 14 def self.bin_gen(*args) @_padrino_gen_bin ||= [Padrino.ruby_command, File.("../../../bin/padrino-gen", __FILE__)] system *@_padrino_gen_bin, *args end |
.cache ⇒ Object
Returns the caching engine.
19 20 21 |
# File 'padrino-cache/lib/padrino-cache.rb', line 19 def cache @_cache end |
.cache=(value) ⇒ Object
Set the caching engine.
48 49 50 |
# File 'padrino-cache/lib/padrino-cache.rb', line 48 def cache=(value) @_cache= value end |
.caller_files ⇒ Array<String>
Like Kernel#caller but excluding certain magic entries and without line / method information; the resulting array contains filenames only.
47 48 49 50 51 52 |
# File 'padrino-core/lib/padrino-core/caller.rb', line 47 def self.caller_files caller(1). map { |line| line.split(/:(?=\d|in )/)[0,2] }. reject { |file,_line| PADRINO_IGNORE_CALLERS.any? { |pattern| file =~ pattern } }. map { |file,_line| file } end |
.clear_middleware! ⇒ Array
Clears all previously configured middlewares.
147 148 149 |
# File 'padrino-core/lib/padrino-core.rb', line 147 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 94 |
# File 'padrino-core/lib/padrino-core.rb', line 91 def configure_apps(&block) return unless block_given? global_configurations << block end |
.detect_application(options) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'padrino-core/lib/padrino-core/server.rb', line 18 def self.detect_application() default_config_file = 'config.ru' if (config_file = .delete(:config)) || File.file?(default_config_file) config_file ||= default_config_file fail "Rack config file `#{config_file}` must have `.ru` extension" unless config_file =~ /\.ru$/ rack_app, = Rack::Builder.parse_file(config_file) [rack_app, ( || {}).merge()] else [Padrino.application, ] end end |
.env ⇒ Symbol
Helper method that return RACK_ENV.
58 59 60 |
# File 'padrino-core/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).
36 37 38 |
# File 'padrino-core/lib/padrino-core/caller.rb', line 36 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.
180 181 182 183 184 185 |
# File 'padrino-core/lib/padrino-core.rb', line 180 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
189 190 191 |
# File 'padrino-core/lib/padrino-core.rb', line 189 def gems @gems ||= [] end |
.global_configurations ⇒ Object
Stores global configuration blocks.
99 100 101 |
# File 'padrino-core/lib/padrino-core.rb', line 99 def global_configurations @_global_configurations ||= [] end |
.insert_mounted_app(mounter) ⇒ Object
Inserts a Mounter object into the mounted applications (avoids duplicates).
254 255 256 |
# File 'padrino-core/lib/padrino-core/mounter.rb', line 254 def insert_mounted_app(mounter) Padrino.mounted_apps.push(mounter) unless Padrino.mounted_apps.include?(mounter) end |
.logger ⇒ Padrino::Logger
17 18 19 |
# File 'padrino-core/lib/padrino-core/logger.rb', line 17 def self.logger Padrino::Logger.logger end |
.logger=(value) ⇒ Object
Set the padrino logger.
47 48 49 |
# File 'padrino-core/lib/padrino-core/logger.rb', line 47 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.
137 138 139 |
# File 'padrino-core/lib/padrino-core.rb', line 137 def middleware @middleware ||= [] end |
.modules ⇒ Object
195 196 197 |
# File 'padrino-core/lib/padrino-core.rb', line 195 def modules @modules ||= [] end |
.mount(name, options = {}) ⇒ Object
Mounts a new sub-application onto Padrino project.
266 267 268 |
# File 'padrino-core/lib/padrino-core/mounter.rb', line 266 def mount(name, ={}) Mounter.new(name, ) end |
.mounted_apps ⇒ Array
Returns the mounted padrino applications (MountedApp objects).
245 246 247 |
# File 'padrino-core/lib/padrino-core/mounter.rb', line 245 def mounted_apps @mounted_apps ||= [] end |
.perf_memusage_command ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'padrino-performance/lib/suites/mem.rb', line 15 def perf_memusage_command if Performance::OS.mac? "vmmap #{$$} | tail -5" elsif Performance::OS.linux? "pmap #{$$} | tail -1" elsif Performance::OS.windows? "tasklist /FI \"PID eq #{$$}\"" end end |
.root(*args) ⇒ String
Helper method for file references.
48 49 50 |
# File 'padrino-core/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 'padrino-core/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 'padrino-core/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.
114 115 116 117 118 |
# File 'padrino-core/lib/padrino-core.rb', line 114 def set_encoding # remove after 0.15 warn 'Warning! Padrino.set_encoding is deprecated. Padrino no longer manages ruby default encodings' nil end |
.use(mw, *args) { ... } ⇒ Object
Convenience method for adding a Middleware to the whole padrino app.
163 164 165 |
# File 'padrino-core/lib/padrino-core.rb', line 163 def use(mw, *args, &block) middleware << [mw, args, block] end |
Instance Method Details
#RUBY_IGNORE_CALLERS ⇒ Object
Add rubinius (and hopefully other VM implementations) ignore patterns …
28 |
# File 'padrino-core/lib/padrino-core/caller.rb', line 28 PADRINO_IGNORE_CALLERS.concat(RUBY_IGNORE_CALLERS) |