![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Add this line to your application's Gemfile:
gem 'activeset'
And then execute:
$ bundle
Or install it yourself as:
$ gem install activeset
The ActiveSet
class provides convenience methods for filtering, sorting, paginating, and transforming collections of data-objects, whether ActiveRecord::Relation
s or Ruby Array
s or custom classes that extend the Enumerable
module.
When calling a convenience method on an instance of ActiveSet
, you pass only 1 argument: a plain-old-Ruby-hash that encodes the instructions for that operation. Each convenience method works with hashes of differing signatures.
ActiveSet
allows for you to filter your collection by:
ActiveRecord
model, a database attribute)The syntax for the instructions hash is relatively simple:
{
attribute: 'value',
association: {
field: 'value'
},
'association.field' => 'value',
'attribute(operator)' => 1.0,
association: {
'field(operator)': 'value'
},
'association.field(operator)' => 'value',
}
Every entry in the instructions hash is treated and processed as an independent operation, and all operations are conjoined ("AND"-ed). At the moment, you cannot use disjointed ("OR"-ed) operations.
The logic of this method is to attempt to process every instruction with the ActiveRecordStrategy, marking all successful attempts. If we successfully processed every instruction, we simply returned the processed result. If there are any instructions that went unprocessed, we take only those instructions and process them against the set processed by the ActiveRecordStrategy.
This filtering operation does not preserve the order of the filters, enforces conjunction, and will discard any unprocessable instruction.
For ActiveRecord sets, the various ARel predicate methods are available as operators:
eq
not_eq
eq_any
not_eq_any
eq_all
not_eq_all
in
not_in
in_any
not_in_any
in_all
not_in_all
lt
lteq
lt_any
lteq_any
lt_all
lteq_all
gt
gteq
gt_any
gteq_any
gt_all
gteq_all
matches
does_not_match
matches_any
does_not_match_any
matches_all
does_not_match_all
ActiveSet
allows for multi-dimensional, multi-directional sorting across the same kinds of attributes as filtering ("direct", "computed", "associated", and "called").
The syntax for the instructions hash is relatively simple:
{
attribute: :desc,
association: {
field: :asc
}
}
The logic for this method is to check whether all of the instructions appear to be processable by the ActiveRecordStrategy, and if they are to attempt to sort using the ActiveRecordStrategy (with all of the instructions, as you can't split sorting instructions). We then double check that all of the instructions were indeed successfully processed by the ActiveRecordStrategy, and if they were, we return that result. Otherwise (if either some instructions don't appear to be processable by ActiveRecord or some instructions weren't processed by ActiveRecord), we sort with the EnumerableStrategy.
ActiveSet
also allows for paginating both ActiveRecord or plain Ruby enumerable sets.
The syntax for the instructions hash remains relatively simple:
{
size: 25,
page: 1
}
Unlike the filtering or sorting operations, you do not have to pass an instructions hash, as the operation will default to paginating with a size
of 25 and starting on page
1.
Paginating as an operation works with "direct" instructions (that is, the instructions don't represent attribute paths or column structures; the instructions hash is a simple, flat hash), and the operation requires all instruction entries together (as opposed to filtering for example, where we can process each instruction entry separately).
to-many
associations (maybe via associations[any]
or associations[all]
syntax)key*
syntax)This library does not deal with typecasting string values; the values of your structures must be of the appropriate data-type.
After checking out the repo, run bin/setup
to install dependencies. Then, run rake spec
to run the tests. You can also run bin/console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
, which will create a git tag for the version, push git commits and tags, and push the .gem
file to rubygems.org.
Bug reports and pull requests are welcome on GitHub at https://github.com/fractaledmind/activeset.
The gem is available as open source under the terms of the MIT License.
FAQs
Unknown package
We found that activeset demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.