Sha256: a6d81e861473a9416defc510912339b79927f0a511989bf8366859a640d21acb

Contents?: true

Size: 1.42 KB

Versions: 32

Compression:

Stored size: 1.42 KB

Contents

#          Copyright (c) 2009 Michael Fellinger m.fellinger@gmail.com
# All files in this distribution are subject to the terms of the Ruby license.

module Ramaze
  def self.plugin(name, options = {})
    Plugin.load(name, options)
  end

  module Plugin
    PLUGIN_LIST = Set.new
    EXTS = %w[rb so bundle]
    PATH = []
    POOL = []

    module_function

    Ramaze.options.setup << self

    def setup
      PLUGIN_LIST.each do |name, const, options|
        const.setup(options) if const.respond_to?(:setup)
      end
    end

    def teardown
      PLUGIN_LIST.each do |name, const, options|
        const.teardown if const.respond_to?(:teardown)
      end
    end

    def add_pool(pool)
      POOL.unshift(pool)
      POOL.uniq!
    end

    add_pool(self)

    def add_path(path)
      PATH.unshift(File.expand_path(path))
      PATH.uniq!
    end

    add_path(__DIR__)
    add_path('')

    def load(name, options)
      name = name.to_s
      try_require(name.snake_case)
      PLUGIN_LIST << [name, const_get(name.camel_case), options]
    rescue Exception => exception
      Log.error(exception)
      raise LoadError, "Plugin #{name} not found"
    end

    def try_require(name)
      found = Dir[glob(name)].first
      require(File.expand_path(found)) if found
    rescue LoadError
    end

    def glob(name = '*')
      "{#{paths.join(',')}}/plugin/#{name}.{#{EXTS.join(',')}}"
    end

    def paths
      PATH
    end
  end
end

Version data entries

32 entries across 32 versions & 4 rubygems

Version Path
Pistos-ramaze-2009.04.08 lib/ramaze/plugin.rb
Pistos-ramaze-2009.06.12 lib/ramaze/plugin.rb
manveru-ramaze-2009.04.01 lib/ramaze/plugin.rb
manveru-ramaze-2009.04.08 lib/ramaze/plugin.rb
manveru-ramaze-2009.04.18 lib/ramaze/plugin.rb
manveru-ramaze-2009.04.22 lib/ramaze/plugin.rb
manveru-ramaze-2009.04 lib/ramaze/plugin.rb
manveru-ramaze-2009.05.08 lib/ramaze/plugin.rb
manveru-ramaze-2009.05 lib/ramaze/plugin.rb
manveru-ramaze-2009.06.04 lib/ramaze/plugin.rb
manveru-ramaze-2009.06.12 lib/ramaze/plugin.rb
manveru-ramaze-2009.06 lib/ramaze/plugin.rb
manveru-ramaze-2009.07 lib/ramaze/plugin.rb
rjspotter-ramaze-2009.06.29 lib/ramaze/plugin.rb
rjspotter-ramaze-2009.06.31 lib/ramaze/plugin.rb
ramaze-2011.12.28 lib/ramaze/plugin.rb
ramaze-2011.10.23 lib/ramaze/plugin.rb
ramaze-2011.07.25 lib/ramaze/plugin.rb
ramaze-2011.01.30 lib/ramaze/plugin.rb
ramaze-2011.01 lib/ramaze/plugin.rb