humzashah / convenient_grouper Goto Github PK
View Code? Open in Web Editor NEWUse Ruby hashes to group database table rows through ActiveRecord.
Home Page: https://rubygems.org/gems/convenient_grouper
License: MIT License
Use Ruby hashes to group database table rows through ActiveRecord.
Home Page: https://rubygems.org/gems/convenient_grouper
License: MIT License
Currently the tests are checking the string outputs of a few methods. Modify this so that a real database is involved and the tests verify the records that are being fetched, rather than strings being outputted.
Any one of the following should be sufficient, since the where
and group
are treated the same: MySQL, PostgreSQL, or SQLite
ALSO: use Minitest rather than RSpec.
Something like this:
age: {
teen: 13..19,
greater_than_20: "> 20",
less_than_50: "< 50"
}
Add >=
and <=
too.
Accept array of values, arrays, and ranges and auto-name the groups e.g.
Employee.group(id: [1, 2, [3,4], 6..9])
should become something like:
Employee.group(id: {a: 1, b: 2, c: [3,4], d: 6..9})
this entails removing keyword-method-arguments
Disable the default group so that the following commands:
Event.group(date: {not_on_date: ">= #{some_date}"}).count
yield either an empty hash or a hash with only one key which is not_on_date
Enable support for inequality matcher i.e. !=
Employee.group({age: {first: 18}}, restrict: true)
should translate to
Employee.where(age: 18).group(age: {first: 18)
Similarly
Employee.group({age: {first: 18, second: [19, 20], third: 25..30}}, restrict: true)
should restrict the query to employees who are of ages 18, 19, 20, or between 25 and 30.
Technically speaking, the range is not invalid, it's just equivalent to group_name: range.min
.
I'm using the gem and generating the groups dynamically and ran into this. It would be nice not to have to change from a range to a value.
So I suggest changing https://github.com/humzashah/convenient_grouper/blob/master/lib/convenient_grouper/hash_converter.rb#L120 to be valid = min && max && (min <= max)
, what do you think?
I can submit a PR, please let me know.
Thank you!
Rachel
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.