Module: Pancake
- Extended by:
- Middleware
- Defined in:
- lib/pancake/logger.rb,
lib/pancake.rb,
lib/pancake/paths.rb,
lib/pancake/errors.rb,
lib/pancake/master.rb,
lib/pancake/router.rb,
lib/pancake/constants.rb,
lib/pancake/stack/app.rb,
lib/pancake/middleware.rb,
lib/pancake/mime_types.rb,
lib/pancake/mixins/url.rb,
lib/pancake/bootloaders.rb,
lib/pancake/stack/stack.rb,
lib/pancake/stack/router.rb,
lib/pancake/configuration.rb,
lib/pancake/mixins/render.rb,
lib/pancake/test/matchers.rb,
lib/pancake/mixins/publish.rb,
lib/pancake/generators/base.rb,
lib/pancake/hooks/on_inherit.rb,
lib/pancake/stack/bootloader.rb,
lib/pancake/middlewares/logger.rb,
lib/pancake/middlewares/static.rb,
lib/pancake/stacks/short/stack.rb,
lib/pancake/mixins/stack_helper.rb,
lib/pancake/stack/configuration.rb,
lib/pancake/mixins/render/render.rb,
lib/pancake/mixins/request_helper.rb,
lib/pancake/mixins/render/template.rb,
lib/pancake/mixins/response_helper.rb,
lib/pancake/stacks/short/controller.rb,
lib/pancake/generators/micro_generator.rb,
lib/pancake/generators/short_generator.rb,
lib/pancake/generators/stack_generator.rb,
lib/pancake/mixins/render/view_context.rb,
lib/pancake/mixins/publish/action_options.rb,
lib/pancake/hooks/inheritable_inner_classes.rb
Overview
require “time” # httpdate
Public Pancake Logger API
To replace an existing logger with a new one:
Pancake::Logger.set_log(log{String, IO},level{Symbol, String})
Available logging levels are
Pancake::Logger::{ Fatal, Error, Warn, Info, Debug }
Logging via:
Pancake.logger.fatal(<String>,&block)
Pancake.logger.error(<String>,&block)
Pancake.logger.warn(<String>,&block)
Pancake.logger.info(<String>,&block)
Pancake.logger.debug(<String>,&block)
Logging with autoflush:
Pancake.logger.fatal!(<String>,&block)
Pancake.logger.error!(<String>,&block)
Pancake.logger.warn!(<String>,&block)
Pancake.logger.info!(<String>,&block)
Pancake.logger.debug!(<String>,&block)
Flush the buffer to
Pancake.logger.flush
Remove the current log object
Pancake.logger.close
Private Pancake Logger API
To initialize the logger you create a new object, proxies to set_log.
Pancake::Logger.new(log{String, IO},level{Symbol, String})
Defined Under Namespace
Modules: BootLoaderMixin, Constants, Errors, Generators, Hooks, Middleware, Middlewares, MimeTypes, Mixins, Paths, Stacks, Test, Url Classes: Configuration, Logger, PancakeConfig, Router, Stack
Constant Summary collapse
- OK_APP =
A simple rack application
lambda{|env| Rack::Response.new("OK", 200, {"Content-Type" => "text/plain"}).finish}
- MISSING_APP =
lambda{|env| Rack::Response.new("NOT FOUND", 404, {"Content-Type" => "text/plain"}).finish}
Class Attribute Summary collapse
-
.root ⇒ Object
Returns the value of attribute root.
Class Method Summary collapse
- .base_url_for(app_name, opts = {}) ⇒ Object
- .configuration ⇒ Object
- .default_error_handling! ⇒ Object
-
.env ⇒ String
Provides the environment for the currently running pancake.
-
.get_root(file, *args) ⇒ String
A helper method to get the expanded directory name of a __FILE__.
- .handle_errors!(*args) ⇒ Object
- .handle_errors? ⇒ Boolean
- .logger ⇒ Object
- .logger=(logr) ⇒ Object
- .reset_configuration ⇒ Object
-
.stack_labels ⇒ Array<Symbol>
Labels that specify what kind of stack you’re intending on loading.
-
.stack_labels=(*labels) ⇒ Object
Sets the stack labels to activate the associated middleware.
-
.start(opts, &block) ⇒ Object
Start Pancake.
-
.url(app_name, name_or_opts, opts = {}) ⇒ Object
Generate a url for any pancake configuration that has a router.
Methods included from Middleware
build, extended, middlewares, stack, use
Class Attribute Details
.root ⇒ Object
Returns the value of attribute root.
9 10 11 |
# File 'lib/pancake/master.rb', line 9 def root @root end |
Class Method Details
.base_url_for(app_name, opts = {}) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/pancake/router.rb', line 24 def self.base_url_for(app_name, opts={}) config = Pancake.configuration.configs(app_name) the_router = if config && config.router config.router elsif app_name.respond_to?(:router) raise Pancake::Errors::UnknownRouter end the_router.base_url(opts) end |
.configuration ⇒ Object
136 137 138 |
# File 'lib/pancake/configuration.rb', line 136 def self.configuration @configuration ||= PancakeConfig.new end |
.default_error_handling! ⇒ Object
111 112 113 |
# File 'lib/pancake/master.rb', line 111 def default_error_handling! @handle_errors = nil end |
.env ⇒ String
Provides the environment for the currently running pancake
35 36 37 |
# File 'lib/pancake/master.rb', line 35 def env ENV['RACK_ENV'] ||= "development" end |
.get_root(file, *args) ⇒ String
A helper method to get the expanded directory name of a __FILE__
44 45 46 |
# File 'lib/pancake/master.rb', line 44 def get_root(file, *args) File.(File.join(File.dirname(file), *args)) end |
.handle_errors!(*args) ⇒ Object
86 87 88 89 90 91 92 93 94 |
# File 'lib/pancake/master.rb', line 86 def handle_errors!(*args) @handle_errors = begin if args.size > 1 args.flatten else args.first end end end |
.handle_errors? ⇒ Boolean
96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/pancake/master.rb', line 96 def handle_errors? if @handle_errors.nil? !(Pancake.env == "development") else case @handle_errors when Array @handle_errors.include?(Pancake.env) when TrueClass, FalseClass @handle_errors when String Pancake.env == @handle_errors end end end |
.logger ⇒ Object
115 116 117 |
# File 'lib/pancake/master.rb', line 115 def logger @logger ||= Pancake::Logger.new end |
.logger=(logr) ⇒ Object
119 120 121 |
# File 'lib/pancake/master.rb', line 119 def logger=(logr) @logger = logr end |
.reset_configuration ⇒ Object
140 141 142 |
# File 'lib/pancake/configuration.rb', line 140 def self.reset_configuration @configuration = nil end |
.stack_labels ⇒ Array<Symbol>
Labels that specify what kind of stack you’re intending on loading. This is a simliar concept to environments but it is in fact seperate conceptually.
The reasoning is that you may want to use a particular stack type or types. By using stack labels, you can define middleware to be active.
66 67 68 69 |
# File 'lib/pancake/master.rb', line 66 def stack_labels return @stack_labels unless @stack_labels.nil? || @stack_labels.empty? self.stack_labels = [:production] end |
.stack_labels=(*labels) ⇒ Object
Sets the stack labels to activate the associated middleware
82 83 84 |
# File 'lib/pancake/master.rb', line 82 def stack_labels=(*labels) @stack_labels = labels.flatten.compact end |
.start(opts, &block) ⇒ Object
Start Pancake. This provides a full pancake stack to use inside a rack application
21 22 23 24 25 26 27 28 |
# File 'lib/pancake/master.rb', line 21 def start(opts, &block) raise "You must specify a root directory for pancake" unless opts[:root] self.root = opts[:root] # Build Pancake the_app = instance_eval(&block) Pancake::Middleware.build(the_app, middlewares) end |
.url(app_name, name_or_opts, opts = {}) ⇒ Object
Generate a url for any pancake configuration that has a router
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/pancake/router.rb', line 12 def self.url(app_name, name_or_opts, opts = {}) config = Pancake.configuration.configs(app_name) the_router = if config && config.router config.router elsif app_name.respond_to?(:router) app_name.router else raise Pancake::Errors::UnknownRouter end the_router.url(name_or_opts, opts) end |