Module: Fastr::Plugin

Includes:
Log
Defined in:
lib/fastr/plugin.rb

Constant Summary collapse

PLUGIN_PATH =
"custom/plugins"

Class Method Summary collapse

Methods included from Log

create_logger, included, level=

Class Method Details

.load(app) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/fastr/plugin.rb', line 7

def self.load(app)
  logger.debug "Loading plugins..."

  if File.directory? "#{app.app_path}/#{PLUGIN_PATH}"
    load_plugins_dir(app)
  end
end

.load_plugin(app, name, dir) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/fastr/plugin.rb', line 23

def self.load_plugin(app, name, dir)
  plugin_name = "#{name.camelcase}Plugin"
  logger.debug "Loading plugin #{plugin_name}..."

  begin
    require("#{dir}/plugin.rb")
    m = Module.const_get(plugin_name)

    if File.directory? "#{dir}/lib"
      Dir.glob(File.join("#{dir}/lib/**", "*.rb")).each { |f| require("#{f}") }
    end

    app.plugins << m
  rescue => e
    logger.error "Unable to load plugin: #{e}"
  end
end

.load_plugins_dir(app) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/fastr/plugin.rb', line 15

def self.load_plugins_dir(app)
  Dir.foreach("#{app.app_path}/#{PLUGIN_PATH}") do |filename|
    if filename != '.' and filename != '..'
      load_plugin(app, filename, "#{app.app_path}/#{PLUGIN_PATH}/#{filename}")
    end
  end
end