Class: Refinery::Plugins

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Plugins



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

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

Class Method Details

.always_allowedObject



57
58
59
# File 'core/lib/refinery/plugins.rb', line 57

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

.registeredObject



61
62
63
# File 'core/lib/refinery/plugins.rb', line 61

def registered
  @registered_plugins ||= new
end

Instance Method Details

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



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

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

#find_by_title(title) ⇒ Object



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

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

#first_in_menu_with_urlObject



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

def first_in_menu_with_url
  find(&:landable?)
end

#first_url_in_menuObject



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

def first_url_in_menu
  first_in_menu_with_url.try(:url)
end

#in_menuObject

TODO: Review necessary?



24
25
26
27
# File 'core/lib/refinery/plugins.rb', line 24

def in_menu
  items_in_menu = reject(&:hide_from_menu)
  self.class.new((prioritised & items_in_menu) | items_in_menu)
end

#namesObject



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

def names
  map(&:name)
end

#pathnamesObject



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

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

#titlesObject



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

def titles
  map(&:title)
end

#update_positions(plugin_list) ⇒ Object



49
50
51
52
53
54
# File 'core/lib/refinery/plugins.rb', line 49

def update_positions(plugin_list)
  plugins = plugin_list.map {|p| find_by_name(p) }.reject(&:blank?)
  plugins.each_with_index do |plugin, index|
    plugin.update_attributes(position: index)
  end
end