Class: October::Plugins
- Inherits:
-
Array
- Object
- Array
- October::Plugins
show all
- Extended by:
- Environment
- Defined in:
- lib/october/plugins.rb
Defined Under Namespace
Modules: PluginMethods
Constant Summary
collapse
- @@plugins =
{}
- @@configs =
{}.with_indifferent_access
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
configuration, configuration!, environment, load_configuration
Constructor Details
Returns a new instance of Plugins.
7
8
9
10
|
# File 'lib/october/plugins.rb', line 7
def initialize
@loaded = []
import Plugins.configuration('plugins.yml')
end
|
Instance Attribute Details
#loaded ⇒ Object
Returns the value of attribute loaded.
5
6
7
|
# File 'lib/october/plugins.rb', line 5
def loaded
@loaded
end
|
Class Method Details
.config(plugin) ⇒ Object
79
80
81
|
# File 'lib/october/plugins.rb', line 79
def config(plugin)
@@configs.fetch(plugin, {})
end
|
83
84
85
|
# File 'lib/october/plugins.rb', line 83
def configure(plugin)
@@configs.merge! plugin
end
|
.initialize ⇒ Object
63
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/october/plugins.rb', line 63
def initialize
October.root.join('plugins').
each_child(false).
each do |file|
next unless file.to_s =~ /\.rb$/
name = file.basename('.rb').to_s.camelize
register name => file
end
PluginMethods
end
|
.register(plugin) ⇒ Object
75
76
77
|
# File 'lib/october/plugins.rb', line 75
def register plugin
@@plugins.merge! plugin
end
|
.registered ⇒ Object
87
88
89
|
# File 'lib/october/plugins.rb', line 87
def registered
@@plugins
end
|
Instance Method Details
#import(plugins) ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/october/plugins.rb', line 14
def import plugins
return unless plugins.present?
plugins = Hash[ plugins.map {|plugin|
plugin.respond_to?(:to_a) ? plugin.to_a.flatten(1) : [plugin, {}]
}].with_indifferent_access
names = plugins.keys.map {|name| name.camelize }
diff = registered.keys & (names - self)
push *diff
load diff
self.class.configure(plugins)
end
|
#imported ⇒ Object
30
31
32
|
# File 'lib/october/plugins.rb', line 30
def imported
self
end
|
#load(new) ⇒ Object
35
36
37
38
39
40
|
# File 'lib/october/plugins.rb', line 35
def load new
@loaded.push *new.map{ |plugin|
require registered[plugin]
plugin.constantize
}
end
|