Module: Brine::Selecting

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

Overview

A module providing assorted means to select particular values out of objects/graphs.

Defined Under Namespace

Classes: AllSelector, AnySelector, Selector

Instance Method Summary collapse

Instance Method Details

#select(target, negated = nil) ⇒ Object

Activate a Selector for the provided target.

Parameters:

  • target (Object)

    The value which the Selector should target.

  • negated (Boolean) (defaults to: nil)

    DEPRECATED If true the assertions should be expected to fail.



104
105
106
# File 'lib/brine/selecting.rb', line 104

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.

Parameters:

  • target (Object)

    The value which the Selector should target.

  • negated (Boolean) (defaults to: nil)

    DEPRECATED If true the assertions should be expected to fail.



124
125
126
# File 'lib/brine/selecting.rb', line 124

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.

Parameters:

  • target (Object)

    The value which the Selector should target.

  • negated (Boolean) (defaults to: nil)

    DEPRECATED If true the assertions should be expected to fail.



114
115
116
# File 'lib/brine/selecting.rb', line 114

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

#selectorObject

The currently active Selector.

Returns:

  • The Selector as set by #use_selector



143
144
145
# File 'lib/brine/selecting.rb', line 143

def selector
  @selector
end

#use_selector(selector) ⇒ Object

Configure selector and make it the active Selector.

Parameters:

  • selector (Selector)

    The selector which will be activated.



133
134
135
136
# File 'lib/brine/selecting.rb', line 133

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