Sha256: 931763d778944e76bb5c8014ef64c9d2e346a0f36f4c6ae4d4ad0ddadd42613f

Contents?: true

Size: 1.45 KB

Versions: 27

Compression:

Stored size: 1.45 KB

Contents

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 } }
    end

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

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

    def in_menu
      self.reject{ |p| p.hide_from_menu }
    end

    def names
      self.map(&:name)
    end

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

    def titles
      self.map(&:title)
    end

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

      def always_allowed
        registered.reject { |p| !p.always_allow_access? }
      end

      def registered
        @registered_plugins ||= self.new
      end

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

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

      def set_active(names)
        @active_plugins = self.new

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

  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
refinerycms-core-1.0.8 lib/refinery/plugins.rb
refinerycms-core-1.0.7 lib/refinery/plugins.rb
refinerycms-core-1.0.5 lib/refinery/plugins.rb
refinerycms-core-1.0.4 lib/refinery/plugins.rb
refinerycms-core-1.0.3 lib/refinery/plugins.rb
refinerycms-core-1.0.1 lib/refinery/plugins.rb
refinerycms-core-1.0.0 lib/refinery/plugins.rb
refinerycms-core-0.9.9.22 lib/refinery/plugins.rb
refinerycms-core-0.9.9.21 lib/refinery/plugins.rb
refinerycms-core-0.9.9.20 lib/refinery/plugins.rb
refinerycms-core-0.9.9.19 lib/refinery/plugins.rb
refinerycms-core-0.9.9.18 lib/refinery/plugins.rb
refinerycms-core-0.9.9.17 lib/refinery/plugins.rb
refinerycms-core-0.9.9.16 lib/refinery/plugins.rb
refinerycms-core-0.9.9.15 lib/refinery/plugins.rb
refinerycms-core-0.9.9.14 lib/refinery/plugins.rb
refinerycms-core-0.9.9.13 lib/refinery/plugins.rb
refinerycms-core-0.9.9.12 lib/refinery/plugins.rb
refinerycms-core-0.9.9.11 lib/refinery/plugins.rb
refinerycms-core-0.9.9.10 lib/refinery/plugins.rb