Class: Refinery::Plugins

Inherits:
Array
  • Object
show all
Defined in:
lib/refinery/plugins.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePlugins

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

.activeObject



45
46
47
# File 'lib/refinery/plugins.rb', line 45

def active
  @active_plugins ||= self.new
end

.always_allowedObject



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

.registeredObject



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_menuObject



28
29
30
# File 'lib/refinery/plugins.rb', line 28

def in_menu
  self.reject{ |p| p.hide_from_menu }
end

#namesObject



32
33
34
# File 'lib/refinery/plugins.rb', line 32

def names
  self.map(&:name)
end

#pathnamesObject



36
37
38
# File 'lib/refinery/plugins.rb', line 36

def pathnames
  self.map(&:pathname).compact.uniq
end

#titlesObject



40
41
42
# File 'lib/refinery/plugins.rb', line 40

def titles
  self.map(&:title)
end