Class: Refinery::Plugins
- Inherits:
-
Array
- Object
- Array
- Refinery::Plugins
- Defined in:
- lib/refinery/plugins.rb
Class Method Summary collapse
- .activate(name) ⇒ Object
- .active ⇒ Object
- .always_allowed ⇒ Object
- .deactivate(name) ⇒ Object
- .registered ⇒ Object
- .set_active(names) ⇒ Object
Instance Method Summary collapse
- #find_activity_by_model(model) ⇒ Object
- #find_by_model(model) ⇒ Object
- #find_by_name(name) ⇒ Object (also: #[])
- #find_by_title(title) ⇒ Object
- #in_menu ⇒ Object
-
#initialize ⇒ Plugins
constructor
A new instance of Plugins.
- #names ⇒ Object
- #pathnames ⇒ Object
- #titles ⇒ Object
Constructor Details
#initialize ⇒ Plugins
Returns a new instance of Plugins.
4 5 6 |
# File 'lib/refinery/plugins.rb', line 4 def initialize @plugins = [] end |
Class Method Details
.activate(name) ⇒ Object
57 58 59 |
# File 'lib/refinery/plugins.rb', line 57 def activate(name) active << registered[name] if registered[name] && !active[name] end |
.active ⇒ Object
45 46 47 |
# File 'lib/refinery/plugins.rb', line 45 def active @active_plugins ||= self.new end |
.always_allowed ⇒ Object
49 50 51 |
# File 'lib/refinery/plugins.rb', line 49 def always_allowed registered.reject { |p| !p.always_allow_access? } end |
.deactivate(name) ⇒ Object
61 62 63 |
# File 'lib/refinery/plugins.rb', line 61 def deactivate(name) active.delete_if {|p| p.name == name} end |
.registered ⇒ Object
53 54 55 |
# File 'lib/refinery/plugins.rb', line 53 def registered @registered_plugins ||= self.new end |
.set_active(names) ⇒ Object
65 66 67 68 69 70 71 |
# File 'lib/refinery/plugins.rb', line 65 def set_active(names) @active_plugins = self.new names.each do |name| activate(name) end end |
Instance Method Details
#find_activity_by_model(model) ⇒ Object
8 9 10 11 12 |
# File 'lib/refinery/plugins.rb', line 8 def find_activity_by_model(model) unless (plugin = find_by_model(model)).nil? plugin.activity.detect {|activity| activity.class == model} end end |
#find_by_model(model) ⇒ Object
14 15 16 17 |
# File 'lib/refinery/plugins.rb', line 14 def find_by_model(model) model = model.constantize if model.is_a? String self.detect { |plugin| plugin.activity.any? {|activity| activity.class == model } } end |
#find_by_name(name) ⇒ Object Also known as: []
19 20 21 |
# File 'lib/refinery/plugins.rb', line 19 def find_by_name(name) self.detect { |plugin| plugin.name == name } end |
#find_by_title(title) ⇒ Object
24 25 26 |
# File 'lib/refinery/plugins.rb', line 24 def find_by_title(title) self.detect { |plugin| plugin.title == title } end |
#in_menu ⇒ Object
28 29 30 |
# File 'lib/refinery/plugins.rb', line 28 def self.reject{ |p| p. } end |
#names ⇒ Object
32 33 34 |
# File 'lib/refinery/plugins.rb', line 32 def names self.map(&:name) end |
#pathnames ⇒ Object
36 37 38 |
# File 'lib/refinery/plugins.rb', line 36 def pathnames self.map(&:pathname).compact.uniq end |
#titles ⇒ Object
40 41 42 |
# File 'lib/refinery/plugins.rb', line 40 def titles self.map(&:title) end |