Class: Answers::Plugins

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Plugins



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

def initialize(*args)
  @plugins = Array.new(*args)
end

Class Method Details

.activate(name) ⇒ Object



52
53
54
# File 'lib/answers/plugins.rb', line 52

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

.activeObject



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

def active
  @active_plugins ||= new
end

.always_allowedObject



44
45
46
# File 'lib/answers/plugins.rb', line 44

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

.deactivate(name) ⇒ Object



56
57
58
# File 'lib/answers/plugins.rb', line 56

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

.registeredObject



48
49
50
# File 'lib/answers/plugins.rb', line 48

def registered
  @registered_plugins ||= new
end

.set_active(names) ⇒ Object



60
61
62
63
64
65
66
# File 'lib/answers/plugins.rb', line 60

def set_active(names)
  @active_plugins = new

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

Instance Method Details

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



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

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

#find_by_title(title) ⇒ Object



19
20
21
# File 'lib/answers/plugins.rb', line 19

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

#in_menuObject



23
24
25
# File 'lib/answers/plugins.rb', line 23

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

#namesObject



27
28
29
# File 'lib/answers/plugins.rb', line 27

def names
  map(&:name)
end

#pathnamesObject



31
32
33
# File 'lib/answers/plugins.rb', line 31

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

#titlesObject



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

def titles
  map(&:title)
end