Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
This gem provides a DSL on top of ActiveRecord to get collection of models for index pages with filters.
Add this line to your application's Gemfile:
gem 'index_query_builder'
And then execute:
$ bundle
Or install it yourself as:
$ gem install index_query_builder
Let's say you have the following schema:
create_table :posts, force: true do |t|
t.text :title
t.integer :view_count
end
create_table :comments, force: true do |t|
t.integer :post_id
t.text :text
end
And the following models
class Post < ActiveRecord::Base
has_many :comments
end
class Comment < ActiveRecord::Base
belongs_to :post
end
And you are building an index page for posts with the following requirements:
view_count
.filters
is { comment_text: 'This post is amazing' }
, then we should return all the posts with a comment containing 'This post is amazing'
.Without Index Query Builder, you will probably have to do something like this.
conditions_strings = []
conditions_params = {}
unless filters[:comment_text].blank?
conditions_strings << "comments.text ILIKE :comment_text"
conditions_params[:comment_text] = "%#{filters[:comment_text]}%"
end
conditions = (conditions_params.empty? ? "" : [conditions_strings.join(" AND "), conditions_params])
joins_list = []
joins_list << {:posts => :comment} if filters[:comment_text].present?
posts = Post.where(conditions).joins(joins_list).order("expected_ship_at desc, id desc")
Or, with Index Query Builder, you can just write this.
posts = IndexQueryBuilder.query Post, with: filters do |query|
query.filter_field [:comments, :text], contains: :comment_text
query.order_by "view_count DESC"
end
Operators will apply where clauses to query only if the filter_name is present in filters hash.
Find more in the docs
It requires PostgreSQL.
$ cp config/database.yml.sample config/database.yml
Update config/database.yml
with your connection information.
$ rake db:test:setup
$ rspec
git checkout -b my-new-feature
)git commit -am 'Add some feature'
)git push origin my-new-feature
)FAQs
Unknown package
We found that index_query_builder 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
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.