Sha256: 1cbfc31653991e06f3655121cb343b5da814968f5f266d44d2b21f8257b468c9

Contents?: true

Size: 994 Bytes

Versions: 9

Compression:

Stored size: 994 Bytes

Contents

module Sunrise
  class Plugins < Array

    def initialize
      @plugins = []
    end

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

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

    def menu(value)
      self.select { |p| p.menu == value.to_s.downcase }
    end

    def names
      self.map(&:name)
    end

    def titles
      self.map(&:title)
    end

    class << self
      def active
        @active_plugins ||= self.new
      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

9 entries across 9 versions & 1 rubygems

Version Path
sunrise-core-0.2.2 lib/sunrise/plugins.rb
sunrise-core-0.2.1 lib/sunrise/plugins.rb
sunrise-core-0.2.0 lib/sunrise/plugins.rb
sunrise-core-0.1.5 lib/sunrise/plugins.rb
sunrise-core-0.1.4 lib/sunrise/plugins.rb
sunrise-core-0.1.3 lib/sunrise/plugins.rb
sunrise-core-0.1.2 lib/sunrise/plugins.rb
sunrise-core-0.1.1 lib/sunrise/plugins.rb
sunrise-core-0.1.0 lib/sunrise/plugins.rb