Module: Ramaze

Defined in:
lib/ramaze.rb,
lib/ramaze.rb,
lib/ramaze/log.rb,
lib/ramaze/cache.rb,
lib/ramaze/error.rb,
lib/ramaze/route.rb,
lib/ramaze/setup.rb,
lib/ramaze/action.rb,
lib/ramaze/helper.rb,
lib/ramaze/option.rb,
lib/ramaze/adapter.rb,
lib/ramaze/contrib.rb,
lib/ramaze/current.rb,
lib/ramaze/gestalt.rb,
lib/ramaze/log/hub.rb,
lib/ramaze/trinity.rb,
lib/ramaze/version.rb,
lib/ramaze/log/xosd.rb,
lib/ramaze/template.rb,
lib/ramaze/log/growl.rb,
lib/ramaze/tool/mime.rb,
lib/ramaze/controller.rb,
lib/ramaze/dispatcher.rb,
lib/ramaze/helper/cgi.rb,
lib/ramaze/log/logger.rb,
lib/ramaze/log/syslog.rb,
lib/ramaze/option/dsl.rb,
lib/ramaze/adapter/cgi.rb,
lib/ramaze/adapter/ebb.rb,
lib/ramaze/helper/auth.rb,
lib/ramaze/helper/form.rb,
lib/ramaze/helper/link.rb,
lib/ramaze/helper/rest.rb,
lib/ramaze/helper/tagz.rb,
lib/ramaze/helper/user.rb,
lib/ramaze/log/knotify.rb,
lib/ramaze/log/logging.rb,
lib/ramaze/tool/create.rb,
lib/ramaze/tool/record.rb,
lib/ramaze/adapter/base.rb,
lib/ramaze/adapter/fcgi.rb,
lib/ramaze/adapter/lsws.rb,
lib/ramaze/adapter/scgi.rb,
lib/ramaze/adapter/thin.rb,
lib/ramaze/cache/memory.rb,
lib/ramaze/contrib/gems.rb,
lib/ramaze/helper/cache.rb,
lib/ramaze/helper/flash.rb,
lib/ramaze/helper/pager.rb,
lib/ramaze/helper/stack.rb,
lib/ramaze/log/informer.rb,
lib/ramaze/sourcereload.rb,
lib/ramaze/action/render.rb,
lib/ramaze/contrib/email.rb,
lib/ramaze/helper/aspect.rb,
lib/ramaze/helper/maruku.rb,
lib/ramaze/helper/sequel.rb,
lib/ramaze/log/analogger.rb,
lib/ramaze/option/holder.rb,
lib/ramaze/option/merger.rb,
lib/ramaze/store/default.rb,
lib/ramaze/template/haml.rb,
lib/ramaze/template/none.rb,
lib/ramaze/template/sass.rb,
lib/ramaze/template/tagz.rb,
lib/ramaze/template/xslt.rb,
lib/ramaze/tool/localize.rb,
lib/ramaze/helper/markaby.rb,
lib/ramaze/helper/partial.rb,
lib/ramaze/adapter/mongrel.rb,
lib/ramaze/adapter/webrick.rb,
lib/ramaze/cache/memcached.rb,
lib/ramaze/contrib/gettext.rb,
lib/ramaze/current/request.rb,
lib/ramaze/current/session.rb,
lib/ramaze/dispatcher/file.rb,
lib/ramaze/helper/identity.rb,
lib/ramaze/helper/redirect.rb,
lib/ramaze/helper/sendfile.rb,
lib/ramaze/template/erubis.rb,
lib/ramaze/template/ezamar.rb,
lib/ramaze/template/liquid.rb,
lib/ramaze/template/nagoro.rb,
lib/ramaze/cache/yaml_store.rb,
lib/ramaze/contrib/facebook.rb,
lib/ramaze/controller/error.rb,
lib/ramaze/current/response.rb,
lib/ramaze/dispatcher/error.rb,
lib/ramaze/helper/nitroform.rb,
lib/ramaze/template/builder.rb,
lib/ramaze/template/markaby.rb,
lib/ramaze/contrib/profiling.rb,
lib/ramaze/dispatcher/action.rb,
lib/ramaze/helper/formatting.rb,
lib/ramaze/helper/httpdigest.rb,
lib/ramaze/template/redcloth.rb,
lib/ramaze/controller/resolve.rb,
lib/ramaze/contrib/auto_params.rb,
lib/ramaze/contrib/gzip_filter.rb,
lib/ramaze/snippets/dictionary.rb,
lib/ramaze/template/remarkably.rb,
lib/ramaze/current/session/hash.rb,
lib/ramaze/dispatcher/directory.rb,
lib/ramaze/current/session/flash.rb,
lib/ramaze/spec/helper/mock_http.rb,
lib/ramaze/spec/helper/pretty_output.rb,
lib/ramaze/snippets/ramaze/deprecated.rb,
lib/ramaze/snippets/ramaze/caller_info.rb,
lib/ramaze/snippets/ramaze/caller_lines.rb,
lib/ramaze/snippets/ramaze/thread_accessor.rb,
lib/ramaze/template/amrita2.rb,
lib/ramaze/template/tenjin.rb

Overview

Copyright © 2008 Michael Fellinger [email protected] All files in this distribution are subject to the terms of the Ruby license.

Defined Under Namespace

Modules: Adapter, Contrib, Current, Dispatcher, FileCache, Filter, Gems, Helper, Logging, Option, SourceReloadHooks, Store, Template, ThreadAccessor, Tool, Trinity, Version Classes: Action, Analogger, Cache, ClassForm, Controller, Dictionary, EmailHelper, Error, Form, Gestalt, Growl, Informer, InstanceForm, Knotify, LogHub, Logger, MemcachedCache, Pager, Request, Response, Rewrite, Route, SequelCache, Session, SetupEnvironment, SourceReload, SpecLogger, Syslog, Xosd, YAMLStoreCache

Constant Summary collapse

BASEDIR =
File.dirname(File.expand_path(__FILE__))
Log =
LogHub.new(Informer)
Global =
Option::Holder.new
STATUS_CODE =

Shortcut to the HTTP_STATUS_CODES of Rack::Utils inverted for easier access

Rack::Utils::HTTP_STATUS_CODES.invert
VERSION =
Version::STRING
Record =
[]
MemoryCache =
Hash
OpenIDStore =

Constant for storing meta-information persistent

OpenID::Store::Filesystem.new(openid_store_file)

Class Method Summary collapse

Class Method Details

.Action(hash = {}) ⇒ Object

Shortcut to create new instances of Action via Action::fill



150
151
152
# File 'lib/ramaze/action.rb', line 150

def self.Action(hash = {})
  Action.create(hash)
end

.caller_info(i = 1) ⇒ Object

Gives you back the file, line and method of the caller number i Example:

Ramaze.caller_info(1)
# => ['/usr/lib/ruby/1.8/irb/workspace.rb', '52', 'irb_binding']


11
12
13
# File 'lib/ramaze/snippets/ramaze/caller_info.rb', line 11

def self.caller_info(i = 1)
  file, line, meth = *parse_backtrace(caller[i])
end

.caller_lines(file, line, size = 4) ⇒ Object

Gives you some context around a specific line in a file. the size argument works in both directions + the actual line, size = 2 gives you 5 lines of source, the returned array has the following format.

[
  line = [
           lineno           = Integer,
           line             = String,
           is_searched_line = (lineno == initial_lineno)
         ],
  ...,
  ...
]

Example:

caller_lines('/usr/lib/ruby/1.8/debug.rb', 122, 2) # ->
 [
   [ 120, "  def check_suspend",                               false ],
   [ 121, "    return if Thread.critical",                     false ],
   [ 122, "    while (Thread.critical = true; @suspend_next)", true  ],
   [ 123, "      DEBUGGER__.waiting.push Thread.current",      false ],
   [ 124, "      @suspend_next = false",                       false ]
 ]


29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/ramaze/snippets/ramaze/caller_lines.rb', line 29

def self.caller_lines(file, line, size = 4)
  return [[0, file, true]] if file == '(eval)'
  lines = File.readlines(File.expand_path(file)) rescue []
  current = line.to_i - 1

  first = current - size
  first = first < 0 ? 0 : first

  last = current + size
  last = last > lines.size ? lines.size : last

  log = lines[first..last] || []

  area = []

  log.each_with_index do |line, index|
    index = index + first + 1
    area << [index, line.chomp, index == current + 1]
  end

  area
end

.contrib(*args) ⇒ Object

Loads and sets up contrib modules.

For more information @see Ramaze::Contrib.load

Usage:

Ramaze.contrib :gzip_filter


14
15
16
# File 'lib/ramaze/contrib.rb', line 14

def self.contrib(*args)
  Contrib.load(*args)
end

.deprecated(from, to = nil) ⇒ Object



2
3
4
5
6
# File 'lib/ramaze/snippets/ramaze/deprecated.rb', line 2

def self.deprecated(from, to = nil)
  message = "%s is deprecated"
  message << ", use %s instead" unless to.nil?
  Log.warn(message % [from, to])
end

.parse_backtrace(line = '') ⇒ Object

Parses one line of backtrace and tries to extract as much information as possible.

Example:

line = "/web/repo/ramaze/lib/ramaze/dispatcher.rb:105:in `respond'"
Ramaze.parse_backtrace(line)
#=> ["/web/repo/ramaze/lib/ramaze/dispatcher.rb", "105", "respond"]


23
24
25
26
27
28
29
# File 'lib/ramaze/snippets/ramaze/caller_info.rb', line 23

def self.parse_backtrace(line = '')
  full = line.scan(/(.*?):(\d+):in `(.*?)'/).first
  return full if full and full.all?
  partial = line.scan(/(.*?):(\d+)/).first
  return partial if partial and partial.all?
  line
end

.Rewrite(name, value = nil, &block) ⇒ Object



94
95
96
# File 'lib/ramaze/route.rb', line 94

def self.Rewrite(name, value = nil, &block)
  Rewrite[name] = value || block
end

.Route(name, value = nil, &block) ⇒ Object

Shortcut for defining new routes.



90
91
92
# File 'lib/ramaze/route.rb', line 90

def self.Route(name, value = nil, &block)
  Route[name] = value || block
end

.setup(start = true, &block) ⇒ Object



2
3
4
5
# File 'lib/ramaze/setup.rb', line 2

def self.setup(start = true, &block)
  SetupEnvironment.new(&block) if block_given?
  self.start if start
end

.shutdownObject Also known as: stop

This will be called when you hit ^C or send SIGINT. It sends ::shutdown to every class in trait and informs you when it is done



95
96
97
98
99
100
101
102
103
# File 'lib/ramaze.rb', line 95

def shutdown
  trait[:essentials].each do |obj|
    obj.shutdown if obj.respond_to?(:shutdown)
  end

  puts("Shutdown Ramaze (it's safe to kill me now if i hang)")

  exit!
end

.startup(options = {}) ⇒ Object Also known as: start

The one place to start Ramaze, takes an Hash of options to pass on to each class in trait by calling ::startup on them.



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/ramaze.rb', line 74

def startup options = {}
  force = options.delete(:force)

  runner = options[:runner] ||= caller[0][/^(.*?):\d+/, 1]
  Global.merge!(options)

  if $0 == runner or force
    Log.info("Starting up Ramaze (Version #{VERSION})")

    trait[:essentials].each do |obj|
      obj.startup(options)
    end
  else
    Log.info "Ramaze already started, skipped start."
  end
end