Class: Refinery::Plugins

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/refinery/plugins.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Plugins

Returns a new instance of Plugins.



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

def initialize(*args)
  @plugins = Array.new(*args)
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 ||= new
end

.always_allowedObject



49
50
51
# File 'lib/refinery/plugins.rb', line 49

def always_allowed
  new registered.select(&: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 ||= 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 = new

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

Instance Method Details

#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
  detect { |plugin| plugin.activity.any? {|activity| activity.klass == 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)
  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)
  detect { |plugin| plugin.title == title }
end

#in_menuObject



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

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

#namesObject



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

def names
  map(&:name)
end

#pathnamesObject



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

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

#titlesObject



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

def titles
  map(&:title)
end