Module: Brine::Selecting

Included in:
Brine
Defined in:
lib/brine/selecting.rb

Overview

Provide assorted means to select particular values out of objects/graphs.

Defined Under Namespace

Classes: AllSelector, AnySelector, Selector, Traversal

Instance Method Summary collapse

Instance Method Details

#select(target, negated = nil) ⇒ Object

Activate a Selector for the provided target.



108
109
110
# File 'lib/brine/selecting.rb', line 108

def select(target, negated=nil)
  use_selector(Selector.new(target, negated))
end

#select_all(target, negated = nil) ⇒ Object

Activate a Selector for all of the children of the provided target.



128
129
130
# File 'lib/brine/selecting.rb', line 128

def select_all(target, negated=nil)
  use_selector(AllSelector.new(target, negated))
end

#select_any(target, negated = nil) ⇒ Object

Activate a Selector for any of the children of the provided target.



118
119
120
# File 'lib/brine/selecting.rb', line 118

def select_any(target, negated=nil)
  use_selector(AnySelector.new(target, negated))
end

#selectorSelector

Return the currently active Selector.



147
148
149
# File 'lib/brine/selecting.rb', line 147

def selector
  @selector
end

#traversal(path, is_plural) ⇒ Traversal

Return a Traversal based on the provided arguments.

This primarily exists as the exported interface to retrieve a Traversal instance.



189
190
191
# File 'lib/brine/selecting.rb', line 189

def traversal(path, is_plural)
  Traversal.new(path, !is_plural.nil?)
end

#use_selector(selector) ⇒ Object

Configure selector and make it the active Selector.



137
138
139
140
# File 'lib/brine/selecting.rb', line 137

def use_selector(selector)
  selector.coercer = coercer
  @selector = selector
end