Top Level Namespace

Defined Under Namespace

Modules: RPath

Instance Method Summary collapse

Instance Method Details

#RPath {|root| ... } ⇒ RPath::Expression #RPath(graph, adapter = nil) {|root| ... } ⇒ Object

Constructs an RPath expression and optionally evaluates it on a graph.

Overloads:

  • #RPath {|root| ... } ⇒ RPath::Expression

    Constructs an RPath expression

    Examples:

    Construct an expression

    exp = RPath { foo.bar }

    Construct an expression beginning with an uppercase letter

    exp = RPath { |root| root.Users.alice }

    Yield Parameters:

    • root (RPath::Root)

      The RPath::Root of the RPath expression. You should almost always omit this yield paramter. Use it only to avoid an exception if the first letter of your expression is uppercase. See the example above.

    Returns:

    See Also:

  • #RPath(graph, adapter = nil) {|root| ... } ⇒ Object

    Constructs an RPath expression, evaluates it, and returns the result

    Examples:

    Construct and expression and evaluate it on an XML document

    RPath.use :nokogiri
    xml = Nokogiri::XML('<foo bar="baz"/>')
    RPath(xml) { foo['bar'] } # => "baz"

    Construct an expression and evaluate it with a custom adapter

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

    Construct an expression and evaluate it with a custom adapter that has been registered

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

    Construct an expression and evaluate it, letting RPath infer the adapter

    RPath(graph) { foo.bar }

    Parameters:

    • graph (Object)

      The graph on which to evaluate the expression.

    • adapter (RPath::Adapter, Symbol, nil) (defaults to: nil)

      The adapter with which to evaluate the expression. If the adapter has been registered with RPath.use, its id (a symbol) may be given as a shortcut. If nil, RPath attempts to infer the adapter by calling RPath::Adapter#adapts? on registered adapters.

    Yield Parameters:

    • root (RPath::Root)

      The RPath::Root of the RPath expression. You should almost always omit this yield parameter. Use it only to avoid an exception if the first letter of your expression is uppercase. See the example above.

    Returns:

    • (Object)

    See Also:



93
94
95
96
97
98
99
100
101
# File 'lib/rpath.rb', line 93

def RPath(graph = nil, adapter = nil, &block)
  exp = RPath::Root.new

  if block_given?
    exp = block.arity > 0 ? block.call(exp) : exp.instance_eval(&block)
  end

  graph ? exp.eval(graph, adapter) : exp
end