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(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

Class Method Summary collapse

Methods included from Middleware

build, extended, middlewares, stack, use

Class Attribute Details

.rootObject

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

.configurationObject



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

.envString

Provides the environment for the currently running pancake

Returns:

  • (String)

    The currently running environment



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__

Returns:

  • (String)

    an expanded version of file



44
45
46
# File 'lib/pancake/master.rb', line 44

def get_root(file, *args)
  File.expand_path(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

Returns:

  • (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

.loggerObject



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_configurationObject



140
141
142
# File 'lib/pancake/configuration.rb', line 140

def self.reset_configuration
  @configuration = nil
end

.stack_labelsArray<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.

Examples:

Pancake.stack_labels == [:development, :demo]

# This would activate middleware marked with :development or :demo or the implicit :any label

Returns:

  • (Array<Symbol>)

    An array of labels to activate The default is [:production]

See Also:



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

Examples:

Pancake.stack_labels = [:demo, :production]

Parameters:

  • An (Array<Symbol>, Symbol)

    array of labels or a single label, specifying the middlewares to activate

See Also:



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

Examples:

Starting a pancake stack

Pancake.start(:root => "/path/to/root"){ MyApp # App to use}

Parameters:

  • opts (Hash)

Options Hash (opts):

  • :root (String)

    The root of the pancake stack



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

Examples:

Pancake.url(UserManamgent, :login) # => "/users/login"


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