Skip to content

Commit

Permalink
Merge pull request #936 from awagener/master
Browse files Browse the repository at this point in the history
Clean up unnecessary code in Refinery::Plugins
  • Loading branch information
parndt committed Sep 3, 2011
2 parents a4cdc42 + 37aa8d9 commit 906b376
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 27 deletions.
36 changes: 11 additions & 25 deletions core/lib/refinery/plugins.rb
@@ -1,61 +1,47 @@
module Refinery
class Plugins < Array

def initialize
@plugins = []
end

def find_activity_by_model(model)
unless (plugin = find_by_model(model)).nil?
plugin.activity.detect {|activity| activity.class == model}
end
end

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

def find_by_name(name)
self.detect { |plugin| plugin.name == name }
detect { |plugin| plugin.name == name }
end
alias :[] :find_by_name

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

def in_menu
_in_menu = self.class.new
self.each { |p| _in_menu << p unless p.hide_from_menu }
_in_menu
self.class.new(reject(&:hide_from_menu))
end

def names
self.map(&:name)
map(&:name)
end

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

def titles
self.map(&:title)
map(&:title)
end

class << self
def active
@active_plugins ||= self.new
@active_plugins ||= new
end

def always_allowed
_always_allowed = self.new
registered.each { |p| _always_allowed << p if p.always_allow_access? }
_always_allowed
new registered.select(&:"always_allow_access?")
end

def registered
@registered_plugins ||= self.new
@registered_plugins ||= new
end

def activate(name)
Expand All @@ -67,7 +53,7 @@ def deactivate(name)
end

def set_active(names)
@active_plugins = self.new
@active_plugins = new

names.each do |name|
activate(name)
Expand Down
4 changes: 2 additions & 2 deletions dashboard/app/helpers/refinery/admin/dashboard_helper.rb
Expand Up @@ -3,8 +3,8 @@ module Admin
module DashboardHelper

def activity_message_for(record)
if (plugin = ::Refinery::Plugins.active.find_by_model(record.class)).present? &&
(activity = plugin.activity.first).present?
if (plugin = ::Refinery::Plugins.active.find_by_model(record.class)) &&
(activity = plugin.activity.first)
# work out which action occured
action = record.updated_at.eql?(record.created_at) ? 'created' : 'updated'

Expand Down

0 comments on commit 906b376

Please sign in to comment.