dobtco / filterer Goto Github PK
View Code? Open in Web Editor NEW:mag: Object-oriented query building for ActiveRecord.
License: MIT License
:mag: Object-oriented query building for ActiveRecord.
License: MIT License
Ruby 2.6.0
was released this week, and introduces Enumerator::Chain and Enumerable#filter.
The filterer
gem already implements the chain
and filter
methods on an ActiveRecord collection.
On older rubies (<2.6) everything works fine;
# Ruby 2.5.x
> User.where('1=1').chain
=> [#<User:0x00007fe8bbf5f9c3 ... etc as expected.
However, on new rubies (>2.6.0) we see the following problem;
# Ruby 2.6.0
> User.where('1=1').chain
=> #<Enumerator::Chain: ...>
It seems the simplest solution is to rename or avoid the .chain
and .filter
methods in this gem.
Thoughts?
The Filterer::ActiveRecord module defines the class methods filter
and chain
on ActiveRecord::Base
.
The filter_without_pagination
method is not defined, however.
Is there a deliberate reason for this, or would it make sense to add this?
I could then call (for example)
@users.filter_without_pagination({})
Will need to be a major version change.
This happens because per_page
, when given in the params, is a string. I have a branch that fixes it here. I didn't create a pull request because there's no "0_4_x" branch to merge it into. Note: this branch is from v0.4.2
. I took a quick look at master and I think master is susceptible to this issue too.
DEPRECATION WARNING: Method to_hash is deprecated and will be removed in Rails 5.1, as `ActionController::Parameters` no longer inherits from hash. Using this deprecated behavior exposes potential security problems. If you continue to use this method you may be creating a security vulnerability in your app that can be exploited. Instead, consider using one of these documented methods which are not deprecated: http://api.rubyonrails.org/v5.0.0.1/classes/ActionController/Parameters.html
I wanted to be able to filter what my API returns and I used filterer to do this. I was surprised to see that there was a limit of 10. I was able to find the code in filterer that does this and it does not seem like it can be overriden. Is my use case of the Filterer gem valid? Or should it not be used for an API?
The cost of filterer is probably negligible, but still.
I want to create a filterer that only returns results from all fields match. For example, let's say I want to get the results of only the records that both match the age
and rank
. If only age
is given, it will return nothing. If only rank
is given, it will return nothing.
I had thought of setting defaults
to {age: nil, rank: nil}
(yes, this will only work if neither of those fields can be nil
), but noticed that present_params
checks for values that are present?
. This would also disallow people from searching for values that match ""
(blank).
What issues would removing present_params
cause? I did a cursory search in the git history but couldn't find the reason that method is there.
filterer = Site.form_templates.filterer(params)
# would then be the equivalent of
FormTemplateFilterer.new(params, starting_query: Site.form_templates)
I like the way filterer makes it easy to pass params and get the result without having a bunch of if
s. However, I don't always use it for an API -- sometimes I use it in some service object to allow fellow developers pass in options that are in turn used in the filterer object. The problem is that I don't want pagination for this. Is there a way to use filterer without pagination?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.