Module: RPath

Defined in:
lib/rpath.rb,
lib/rpath/util.rb,
lib/rpath/adapter.rb,
lib/rpath/version.rb,
lib/rpath/adapters.rb,
lib/rpath/registry.rb,
lib/rpath/expressions.rb,
lib/rpath/adapters/oga.rb,
lib/rpath/adapters/rexml.rb,
lib/rpath/adapters/nokogiri.rb,
lib/rpath/adapters/filesystem.rb

Defined Under Namespace

Modules: Adapters Classes: Adapter, Adjacent, At, Attribute, Content, Expression, Named, Root, VertexArrayExpression, VertexExpression, Where

Constant Summary collapse

VERSION =
'1.1.0'

Class Method Summary collapse

Class Method Details

.use(adapter, id = nil) ⇒ void Also known as: register

This method returns an undefined value.

Registers an adapter. Once an adapter is registered, RPath calls its RPath::Adapter#adapts? when trying to infer the adapter for an evaluation, and its id may be given to #RPath.

Examples:

Built-in adapter

RPath.use :nokogiri

Custom adapter

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

Custom adapter with custom ID

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

Parameters:

  • adapter (Symbol, Adapter)

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

  • id (Symbol, nil) (defaults to: nil)

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



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# 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