Sha256: 84de9a26865b9b4efd16432f85798df2c811835f0da9038cf69c049be92eb19d

Contents?: true

Size: 1.57 KB

Versions: 14

Compression:

Stored size: 1.57 KB

Contents

# frozen_string_literal: true

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

  # FIXME: Something in rails double require this module. Prevent that to keep
  # @@registered integrity
  unless defined?(Keeper)
    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, :description

      attr_reader :registered

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

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
publify_core-10.0.2 lib/publify_plugins.rb
publify_core-10.0.1 lib/publify_plugins.rb
publify_core-10.0.0 lib/publify_plugins.rb
publify_core-9.2.10 lib/publify_plugins.rb
publify_core-9.2.9 lib/publify_plugins.rb
publify_core-9.2.8 lib/publify_plugins.rb
publify_core-9.2.7 lib/publify_plugins.rb
publify_core-9.2.6 lib/publify_plugins.rb
publify_core-9.2.5 lib/publify_plugins.rb
publify_core-9.2.4 lib/publify_plugins.rb
publify_core-9.2.3 lib/publify_plugins.rb
publify_core-9.2.2 lib/publify_plugins.rb
publify_core-9.2.1 lib/publify_plugins.rb
publify_core-9.2.0 lib/publify_plugins.rb