Sha256: b3ea899e0234ef6e5d0c642db7df173136fd4eeaa74c779440260b3d9c9a4c98

Contents?: true

Size: 913 Bytes

Versions: 3

Compression:

Stored size: 913 Bytes

Contents

module Neovim
  class Host
    # @api private
    class Loader
      def initialize(host)
        @host = host
      end

      # Load the provided Ruby files while temporarily overriding
      # +Neovim.plugin+ to expose the remote plugin DSL and register the result
      # to the host.
      #
      # @param paths [Array<String>]
      def load(paths)
        paths.each do |path|
          override_plugin_method(path) do
            Kernel.load(path, true)
          end
        end
      end

      private

      def override_plugin_method(path)
        old_plugin_def = Neovim.method(:plugin)
        at_host = @host

        Neovim.define_singleton_method(:plugin) do |&block|
          plugin = Plugin.from_config_block(path, &block)
          at_host.register(plugin)
        end

        yield
      ensure
        Neovim.define_singleton_method(:plugin, &old_plugin_def)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
neovim-0.2.5 lib/neovim/host/loader.rb
neovim-0.2.4 lib/neovim/host/loader.rb
neovim-0.2.3 lib/neovim/host/loader.rb