Class: Refinery::Plugins

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.activate(name) ⇒ Object



47
48
49
# File 'lib/refinery/plugins.rb', line 47

def activate(name)
  active << registered[name] if registered[name] && !active[name]
end

.activeObject



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

def active
  @active_plugins ||= new
end

.always_allowedObject



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

def always_allowed
  new registered.select(&:always_allow_access)
end

.deactivate(name) ⇒ Object



51
52
53
# File 'lib/refinery/plugins.rb', line 51

def deactivate(name)
  active.delete_if {|p| p.name == name}
end

.registeredObject



43
44
45
# File 'lib/refinery/plugins.rb', line 43

def registered
  @registered_plugins ||= new
end

.set_active(names) ⇒ Object



55
56
57
58
59
60
61
# File 'lib/refinery/plugins.rb', line 55

def set_active(names)
  @active_plugins = new

  names.each do |name|
    activate(name)
  end
end

Instance Method Details

#find_by_model(model) ⇒ Object



4
5
6
7
# File 'lib/refinery/plugins.rb', line 4

def find_by_model(model)
  model = model.constantize if model.is_a? String
  detect { |plugin| plugin.activity.any? {|activity| activity.klass == model } }
end

#find_by_name(name) ⇒ Object Also known as: []



9
10
11
# File 'lib/refinery/plugins.rb', line 9

def find_by_name(name)
  detect { |plugin| plugin.name == name }
end

#find_by_title(title) ⇒ Object



14
15
16
# File 'lib/refinery/plugins.rb', line 14

def find_by_title(title)
  detect { |plugin| plugin.title == title }
end

#in_menuObject



18
19
20
# File 'lib/refinery/plugins.rb', line 18

def in_menu
  self.class.new(reject(&:hide_from_menu))
end

#namesObject



22
23
24
# File 'lib/refinery/plugins.rb', line 22

def names
  map(&:name)
end

#pathnamesObject



26
27
28
# File 'lib/refinery/plugins.rb', line 26

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

#titlesObject



30
31
32
# File 'lib/refinery/plugins.rb', line 30

def titles
  map(&:title)
end