Module: Ramaze::Contrib

Defined in:
lib/ramaze/contrib.rb,
lib/ramaze/contrib/profiling.rb,
lib/ramaze/contrib/auto_params.rb

Overview

A module used for loading contrib modules.

Defined Under Namespace

Classes: AutoParams, Gettext, Profiling

Class Method Summary collapse

Class Method Details

.load(*contribs) ⇒ Object

Loads and sets up contrib modules from /ramaze/contrib.

Usage:

Ramaze::Contrib.load :gzip_filter

Creating a contrib module:

module Ramaze::Contrib::Test
  def self.setup
    Log.info "Test module set up"
  end
end
class TestController < Ramaze::Controller
  map '/test'
  def index; "Chunky Bacon!"; end
end

# Save that to your <app dir>/contrib and use like:
Ramaze.contrib :test


43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/ramaze/contrib.rb', line 43

def self.load(*contribs)
  contribs.each do |name|
    mod_name = name.to_s.camel_case
    begin
      const = Contrib.const_get(mod_name)
      Global.contribs << const
      const.startup if const.respond_to?(:startup)
      Log.dev "Loaded contrib: #{const}"
    rescue NameError
      files = Dir["{contrib,#{BASEDIR/:ramaze/:contrib}}/#{name}.{so,bundle,rb}"]
      raise LoadError, "#{mod_name} not found" unless files.any?
      require(files.first) ? retry : raise
    end
  end
end

.shutdownObject

Will call .shutdown on all contrib modules which support it.


.shudown gets called by Ramaze :essentials. +++



64
65
66
67
68
# File 'lib/ramaze/contrib.rb', line 64

def self.shutdown
  Global.contribs.each do |contrib|
    contrib.shutdown if contrib.respond_to?(:shutdown)
  end
end

.startup(options = {}) ⇒ Object

Will load all contrib modules from options


.startup gets called by Ramaze :essentials. +++



75
76
77
78
79
80
# File 'lib/ramaze/contrib.rb', line 75

def self.startup(options = {})
  return unless options[:contrib]
  [options[:contrib]].flatten.each do |contrib|
    load(contrib)
  end
end