Sha256: 6982c4d3ad1e6f47f3b009a3dbfb58e33b5f560950df674c807b6d859370bdf5

Contents?: true

Size: 1.07 KB

Versions: 30

Compression:

Stored size: 1.07 KB

Contents

module Mobility
=begin

Plugins allow modular customization of backends independent of the backend
itself. They are enabled through {Mobility::Translations.plugins} (delegated to
from {Mobility.configure}), which takes a block within which plugins can be
declared in any order (dependencies will be resolved).

=end
  module Plugins
    @plugins = {}
    @names = {}

    class << self
      # @param [Symbol] name Name of plugin to load.
      def load_plugin(name)
        return name if Module === name || name.nil?

        unless (plugin = @plugins[name])
          require "mobility/plugins/#{name}"
          raise LoadError, "plugin #{name} did not register itself correctly in Mobility::Plugins" unless (plugin = @plugins[name])
        end
        plugin
      end

      # @param [Module] plugin Plugin module to lookup. Plugin must already be loaded.
      def lookup_name(plugin)
        @names.fetch(plugin)
      end

      def register_plugin(name, plugin)
        @plugins[name] = plugin
        @names[plugin] = name
      end

      class LoadError < Error; end
    end
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
mobility-1.3.1 lib/mobility/plugins.rb
mobility-1.3.0 lib/mobility/plugins.rb
mobility-1.3.0.rc3 lib/mobility/plugins.rb
mobility-1.3.0.rc2 lib/mobility/plugins.rb
mobility-1.3.0.rc1 lib/mobility/plugins.rb
mobility-1.2.9 lib/mobility/plugins.rb
mobility-1.2.8 lib/mobility/plugins.rb
mobility-1.2.7 lib/mobility/plugins.rb
mobility-1.2.6 lib/mobility/plugins.rb
mobility-1.2.5 lib/mobility/plugins.rb
mobility-1.2.4 lib/mobility/plugins.rb
mobility-1.2.3 lib/mobility/plugins.rb
mobility-1.2.2 lib/mobility/plugins.rb
mobility-1.2.1 lib/mobility/plugins.rb
mobility-1.2.0 lib/mobility/plugins.rb
mobility-1.1.3 lib/mobility/plugins.rb
mobility-1.1.2 lib/mobility/plugins.rb
mobility-1.1.1 lib/mobility/plugins.rb
mobility-1.1.0 lib/mobility/plugins.rb
mobility-1.0.7 lib/mobility/plugins.rb