Skip to content

Instantly share code, notes, and snippets.

@parsonsmatt
Last active August 29, 2015 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parsonsmatt/52589ba1d4d555ee1e45 to your computer and use it in GitHub Desktop.
Save parsonsmatt/52589ba1d4d555ee1e45 to your computer and use it in GitHub Desktop.
muh filters
WhichBar =
Filter::Lift
| Filter::Singular.new(
attribute: :open,
value: true
)
| Filter::Collection.new(
attribute: :people,
aggregator: {
klass: :compare,
options: {
attribute: :age,
value: 21,
comparator: :>=,
reductor: :all?
}
}
)
Person = Struct.new(:age)
nope = (18..22).map(&Person.method(:new))
bad_news = (19..24).map(&Person.method(:new))
okay = (25..35).map(&Person.method(:new))
fine = (30..45).map(&Person.method(:new))
Bar = Struct.new(:people, :open)
trappeze = Bar.new(okay, true)
nineties = Bar.new(nope, true)
eighties = Bar.new(nope, false)
some_pig = Bar.new(fine, false)
bars = [trappeze, nineties, eighties, some_pig]
WhichBar.new(bars).records.first
=> trappeze
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment