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/reloader.rb,
lib/ramaze/template.rb,
lib/ramaze/log/growl.rb,
lib/ramaze/tool/mime.rb,
lib/ramaze/cache/file.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/fake.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/bench.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/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/helper/thread.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/gestalt.rb,
lib/ramaze/helper/markaby.rb,
lib/ramaze/helper/partial.rb,
lib/ramaze/tool/daemonize.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/gravatar.rb,
lib/ramaze/helper/identity.rb,
lib/ramaze/helper/paginate.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/maruku.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/helper/ultraviolet.rb,
lib/ramaze/contrib/gzip_filter.rb,
lib/ramaze/reloader/watch_stat.rb,
lib/ramaze/snippets/dictionary.rb,
lib/ramaze/snippets/string/esc.rb,
lib/ramaze/snippets/string/ord.rb,
lib/ramaze/template/remarkably.rb,
lib/ramaze/current/session/hash.rb,
lib/ramaze/dispatcher/directory.rb,
lib/ramaze/log/rotatinginformer.rb,
lib/ramaze/snippets/proc/locals.rb,
lib/ramaze/snippets/string/each.rb,
lib/ramaze/current/session/flash.rb,
lib/ramaze/helper/simple_captcha.rb,
lib/ramaze/snippets/numeric/time.rb,
lib/ramaze/snippets/object/scope.rb,
lib/ramaze/snippets/ramaze/fiber.rb,
lib/ramaze/snippets/ramaze/state.rb,
lib/ramaze/snippets/string/color.rb,
lib/ramaze/reloader/watch_inotify.rb,
lib/ramaze/snippets/object/pretty.rb,
lib/ramaze/snippets/ramaze/struct.rb,
lib/ramaze/snippets/binding/locals.rb,
lib/ramaze/snippets/object/__dir__.rb,
lib/ramaze/snippets/object/acquire.rb,
lib/ramaze/snippets/ramaze/acquire.rb,
lib/ramaze/snippets/kernel/constant.rb,
lib/ramaze/snippets/string/end_with.rb,
lib/ramaze/snippets/string/unindent.rb,
lib/ramaze/snippets/array/put_within.rb,
lib/ramaze/spec/helper/pretty_output.rb,
lib/ramaze/snippets/ramaze/deprecated.rb,
lib/ramaze/snippets/string/camel_case.rb,
lib/ramaze/snippets/string/snake_case.rb,
lib/ramaze/snippets/string/start_with.rb,
lib/ramaze/snippets/ramaze/caller_info.rb,
lib/ramaze/snippets/ramaze/caller_lines.rb,
lib/ramaze/snippets/kernel/pretty_inspect.rb,
lib/ramaze/snippets/numeric/filesize_format.rb,
lib/ramaze/snippets/object/instance_variable_defined.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, CoreExtensions, Filter, Gems, Helper, Logger, Logging, Option, StateAccessor, Store, Template, Tool, Trinity Classes: Action, Cache, ClassForm, Controller, Current, Dictionary, Dispatcher, EmailHelper, Error, Fiber, FileCache, Form, Gestalt, InstanceForm, MemcachedCache, Pager, Reloader, Request, Response, Rewrite, Route, SequelCache, Session, SetupEnvironment, SpecLogger, State, Struct, YAMLStoreCache
Constant Summary collapse
- BASEDIR =
File.dirname(File.(__FILE__))
- STATUS_CODE =
Shortcut to the HTTP_STATUS_CODES of Rack::Utils inverted for easier access
Rack::Utils::HTTP_STATUS_CODES.invert
- Log =
Logger::LogHub.new(Logger::Informer)
- Global =
Option::Holder.new
- STATE =
State.new
- VERSION =
"2009.01"
- Record =
[]
- MemoryCache =
Hash
- OpenIDStore =
Constant for storing meta-information persistent
OpenID::Store::Filesystem.new(openid_store_file)
- DEPRECATED_CONSTANTS =
{ :ThreadAccessor => :StateAccessor }
Class Method Summary collapse
-
.acquire(*globs) ⇒ Object
Require all .rb and .so files on the given globs, utilizes Dir::[].
-
.Action(hash = {}) ⇒ Object
Shortcut to create new instances of Action.
-
.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’].
-
.caller_lines(file, line, size = 4) ⇒ Object
Gives you some context around a specific line in a file.
- .const_missing(name) ⇒ Object
-
.contrib(*args) ⇒ Object
Loads and sets up contrib modules.
- .daemonize(runner, instruction, options = {}) ⇒ Object
- .deprecated(from, to = nil) ⇒ Object
-
.parse_backtrace(line = '') ⇒ Object
Parses one line of backtrace and tries to extract as much information as possible.
- .Rewrite(name, value = nil, &block) ⇒ Object
-
.Route(name, value = nil, &block) ⇒ Object
Shortcut for defining new routes.
- .setup(start = true, &block) ⇒ Object
-
.shutdown ⇒ Object
(also: stop)
This will be called when you hit ^C or send SIGINT.
-
.skip_start ⇒ Object
A shortcut for setting Ramaze.trait = true.
-
.start!(options = {}) ⇒ Object
Forces the startup of Ramaze regardless if trait is set.
-
.startup(options = {}) ⇒ Object
(also: 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.
Class Method Details
.acquire(*globs) ⇒ Object
Require all .rb and .so files on the given globs, utilizes Dir::[].
Examples:
# Given following directory structure:
# src/foo.rb
# src/bar.so
# src/foo.yaml
# src/foobar/baz.rb
# src/foobar/README
# requires all files in 'src':
Ramaze.acquire 'src/*'
# requires all files in 'src' recursive:
Ramaze.acquire 'src/**/*'
# require 'src/foo.rb' and 'src/bar.so' and 'src/foobar/baz.rb'
Ramaze.acquire 'src/*', 'src/foobar/*'
24 25 26 27 28 29 30 |
# File 'lib/ramaze/snippets/ramaze/acquire.rb', line 24 def self.acquire(*globs) globs.flatten.each do |glob| Dir[glob].each do |file| require file if file =~ /\.(rb|so)$/ end end end |
.Action(hash = {}) ⇒ Object
Shortcut to create new instances of Action
156 157 158 |
# File 'lib/ramaze/action.rb', line 156 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.(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 |
.const_missing(name) ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/ramaze/snippets/ramaze/deprecated.rb', line 13 def self.const_missing(name) if to = DEPRECATED_CONSTANTS[name] Log.warn "Ramaze::#{name} is deprecated, use #{to} instead" constant(to) else super end 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 |
.daemonize(runner, instruction, options = {}) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/ramaze/tool/daemonize.rb', line 4 def self.daemonize(runner, instruction, = {}) puts "Instructing daemonize to: #{instruction}" require 'daemons' pids = File.join(Dir.tmpdir, 'ramaze.pids') FileUtils.mkdir_p(pids) # FIXME: there's a much better way, gotta search irc logs. unless File.executable?(runner) mode = File.stat(runner).mode.to_s(8) mode[3,1] = '7' File.chmod(mode.to_i(8), runner) end content = File.readlines(runner) content.unshift('#!/usr/bin/env ruby') unless content[0] =~ /#!/ File.open(runner, 'w+'){|io| io.puts(content) } = { :app_name => File.basename(File.dirname(runner)), :ARGV => [instruction], :script => runner, :dir_mode => :normal, :dir => pids, :multiple => false, :ontop => false, :mode => :exec, :backtrace => true, :monitor => true, }.merge() Daemons.run(runner, ) end |
.deprecated(from, to = nil) ⇒ Object
6 7 8 9 10 11 |
# File 'lib/ramaze/snippets/ramaze/deprecated.rb', line 6 def self.deprecated(from, to = nil) = "%s is deprecated" << ", use %s instead" unless to.nil? << " - from: %p" Log.warn( % [from, to, caller[1]]) 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 |
.shutdown ⇒ Object 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
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/ramaze.rb', line 119 def shutdown Log.info "Initiate shutdown" Timeout.timeout(5) do trait[:essentials].each do |obj| obj.shutdown if obj.respond_to?(:shutdown) end puts "Ramazement is over, have a nice day." exit end rescue Timeout::Error puts "Shutdown timed out, issuing exit!" exit! end |
.skip_start ⇒ Object
A shortcut for setting Ramaze.trait = true.
104 105 106 |
# File 'lib/ramaze.rb', line 104 def skip_start trait[:started] = true end |
.start!(options = {}) ⇒ Object
Forces the startup of Ramaze regardless if trait is set.
110 111 112 113 |
# File 'lib/ramaze.rb', line 110 def start!( = {}) trait[:started] = false startup() 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.
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/ramaze.rb', line 81 def startup = {} = .to_hash force = .delete(:force) force ||= !trait[:started] [:runner] ||= caller[0][/^(.*?):\d+/, 1] Global.merge!() if force Log.info("Starting up Ramaze (Version #{VERSION})") trait[:started] = true trait[:essentials].each do |obj| obj.startup() end else Log.info "Ramaze already started, skipped start." end end |