module RPath

Constants

VERSION

Public Class Methods

register(adapter, id = nil)
Alias for: use
use(adapter, id = nil) click to toggle source

Registers an adapter. Once an adapter is registered, RPath calls its {Adapter#adapts?} when trying to infer the adapter for an evaluation, and its id may be given to {#RPath}. @example Built-in adapter

RPath.use :nokogiri

@example Custom adapter

RPath.use CustomAdapter.new
RPath(graph, :custom_adapter) { foo.bar }

@example Custom adapter with custom ID

RPath.use CustomAdapter.new, :custom
RPath(graph, :custom) { foo.bar }

@param [Symbol, Adapter] adapter

For built-in adapters, the underscored, symbolized class name (e.g.
+:nokogiri+). For custom adapters, an instance of the adapter class.

@param [Symbol, nil] id

The identifier to be used in calls to {#RPath}. If +nil+, the
underscored, symbolized name of the adapter class is assumed.

@return [void]

# File lib/rpath.rb, line 33
def use(adapter, id = nil)
  if adapter.is_a?(Symbol)
    class_names = [Util.camelcase(adapter.to_s), adapter.to_s.upcase]
    class_ = Util.first_defined_const(RPath::Adapters, *class_names)

    unless class_
      raise "No adapter in RPath::Adapters with class name in #{class_names}"
    end

    adapter = class_.new
  end

  Registry.register adapter, id
end
Also aliased as: register