Module: Philtre

Defined in:
lib/philtre.rb,
lib/philtre/filter.rb,
lib/philtre/version.rb,
lib/philtre/predicates.rb,
lib/philtre/place_holder.rb,
lib/philtre/predicate_dsl.rb,
lib/philtre/empty_expression.rb,
lib/philtre/predicate_splitter.rb

Overview

:nodoc:

Defined Under Namespace

Classes: EmptyExpression, Filter, Grinder, PlaceHolder, PredicateDsl, PredicateSplitter, Predicates

Constant Summary collapse

VERSION =
"0.1.0"

Class Method Summary collapse

Class Method Details

.filter(dataset: nil, with: {}, **kwargs) ⇒ Object

This is the high-level, easy-to-read smalltalk-style interface params:

  • dataset is a Sequel::Model or a Sequel::Dataset

  • with is the param hash (optional, or just use hash-style args)

for x-ample, in rails you could do

@personages = Philtre.filter dataset: Personage, with: params[:filter]

or even

@personages = Philtre.filter dataset: Personage, name: 'Dylan', age_gt: 21, age_lt: 67

35
36
37
# File 'lib/philtre.rb', line 35

def self.filter( dataset: nil, with: {}, **kwargs )
  new(with.merge kwargs).apply(dataset)
end

.grind(dataset: nil, with: {}, **kwargs) ⇒ Object

Create a grinder with the parameters, and use it on the dataset. Return the result.

dataset should have placeholders, otherwise calling this method just warms your cpu.


44
45
46
47
# File 'lib/philtre.rb', line 44

def self.grind( dataset: nil, with: {}, **kwargs )
  filter = new(with.merge kwargs)
  Philtre::Grinder.new(filter).transform(dataset)
end

.new(*filter_parameters, &blk) ⇒ Object

Just a factory method that calls Filter.new

philtre = Philtre.new params[:filter]

18
19
20
# File 'lib/philtre.rb', line 18

def self.new( *filter_parameters, &blk )
  Filter.new *filter_parameters, &blk
end