Sha256: d8a6f0a49e72a935d95f1c3de7994e3e42309ec2caa69a0ce490ac7b05fa5b40

Contents?: true

Size: 1.55 KB

Versions: 9

Compression:

Stored size: 1.55 KB

Contents

module PublifyPlugins
  # Deprecated?
  def plugin_public_action(action)
    @@plugin_public_actions ||= []
    @@plugin_public_actions.push action
  end

  # Deprecated?
  def plugin_public_actions
    @@plugin_public_actions
  end

  # Deprecated?
  def plugin_description(description)
    eval "def self.description; '#{description}'; end"
  end

  # Deprecated?
  def plugin_display_name(name)
    eval "def self.display_name; '#{name}'; end"
  end

  unless defined?(Keeper) # Something in rails double require this module. Prevent that to keep @@registered integrity
    class Keeper
      KINDS = [:avatar, :textfilter].freeze
      @@registered = {}

      class << self
        def available_plugins(kind = nil)
          return @@registered.inspect unless kind
          check_kind(kind)
          @@registered[kind] || []
        end

        def register(klass)
          kind = klass.kind
          check_kind(kind)
          @@registered[kind] ||= []
          @@registered[kind] << klass
          @@registered[kind]
        end

        private

        def check_kind(kind)
          unless KINDS.include?(kind)
            raise ArgumentError,
                  "#{kind} is not part of available plugin targets (#{KINDS.join(',')})"
          end
        end
      end

      private

      def initialize
        raise 'No instance allowed.'
      end
    end
  end # Defined

  class Base
    class << self
      attr_accessor :name
      attr_accessor :description
      attr_reader :registered

      def kind
        :void
      end
    end # << self
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
publify_core-9.1.0 lib/publify_plugins.rb
publify_core-9.0.1 lib/publify_plugins.rb
publify_core-9.0.0 lib/publify_plugins.rb
publify_core-9.0.0.pre6 lib/publify_plugins.rb
publify_core-9.0.0.pre5 lib/publify_plugins.rb
publify_core-9.0.0.pre4 lib/publify_plugins.rb
publify_core-9.0.0.pre3 lib/publify_plugins.rb
publify_core-9.0.0.pre2 lib/publify_plugins.rb
publify_core-9.0.0.pre1 lib/publify_plugins.rb