Sha256: 2d4f88b4226dcf28e139616a57941d0f9704ded4a9ef8d86bd2df39dc8260a53

Contents?: true

Size: 1.18 KB

Versions: 11

Compression:

Stored size: 1.18 KB

Contents

module Refinery
  class Plugins < Array

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

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

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

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

    def names
      map(&:name)
    end

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

    def titles
      map(&:title)
    end

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

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

      def registered
        @registered_plugins ||= 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 = new

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

  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
refinerycms-core-2.0.10 lib/refinery/plugins.rb
refinerycms-core-2.0.9 lib/refinery/plugins.rb
refinerycms-core-2.0.8 lib/refinery/plugins.rb
refinerycms-core-2.0.7 lib/refinery/plugins.rb
refinerycms-core-2.0.6 lib/refinery/plugins.rb
refinerycms-core-2.0.5 lib/refinery/plugins.rb
refinerycms-core-2.0.4 lib/refinery/plugins.rb
refinerycms-core-2.0.3 lib/refinery/plugins.rb
refinerycms-core-2.0.2 lib/refinery/plugins.rb
refinerycms-core-2.0.1 lib/refinery/plugins.rb
refinerycms-core-2.0.0 lib/refinery/plugins.rb