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/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(message<String>,&block)
Pancake.logger.error(message<String>,&block)
Pancake.logger.warn(message<String>,&block)
Pancake.logger.info(message<String>,&block)
Pancake.logger.debug(message<String>,&block)
Logging with autoflush:
Pancake.logger.fatal!(message<String>,&block)
Pancake.logger.error!(message<String>,&block)
Pancake.logger.warn!(message<String>,&block)
Pancake.logger.info!(message<String>,&block)
Pancake.logger.debug!(message<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_base_template(opts = {}) ⇒ Object
provides access to the default base template via the Pancake.master_templates 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
-
.master_stack ⇒ Object
The stack to use as the master stack.
-
.master_stack=(stack) ⇒ Object
set the master stack.
-
.master_templates ⇒ Object
Used as the definitive source of shared templates for the whole pancake graph.
-
.master_templates=(stack) ⇒ Object
Set the master templates to control the default templates for the stack.
- .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
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_base_template(opts = {}) ⇒ Object
provides access to the default base template via the Pancake.master_templates object
156 157 158 159 |
# File 'lib/pancake/master.rb', line 156 def default_base_template(opts = {}) raise "Master Templates not set" unless master_templates master_templates.template(master_templates.base_template_name) 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 |
.master_stack ⇒ Object
The stack to use as the master stack. Can be nil! The master stack is assumed to be the stack that is the controlling stack for the group of pancake stacks
126 127 128 |
# File 'lib/pancake/master.rb', line 126 def master_stack @master_stack end |
.master_stack=(stack) ⇒ Object
set the master stack. This also sets the master_templates as this stack if that hasn’t yet been set.
133 134 135 136 |
# File 'lib/pancake/master.rb', line 133 def master_stack=(stack) self.master_templates ||= stack @master_stack = stack end |
.master_templates ⇒ Object
Used as the definitive source of shared templates for the whole pancake graph. Allows different stacks to share the same templates
142 143 144 |
# File 'lib/pancake/master.rb', line 142 def master_templates @master_templates end |
.master_templates=(stack) ⇒ Object
Set the master templates to control the default templates for the stack
149 150 151 |
# File 'lib/pancake/master.rb', line 149 def master_templates=(stack) @master_templates = stack 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 |