DEV Community

Boris
Boris

Posted on

2 small gems

I come to present to you 2 small gems, quite simple that I realized recently.

The first which allows you to check an email via different methods:

address = RailsEmailChecker.address('test@gmail.com') # or RailsEmailChecker::Address.new('test@gmail.com')
address.formatted? # => true
address.sub_addressed? # => false
address.recorded? # => true
address.whitelisted? # => false
address.blacklisted? # => false
Enter fullscreen mode Exit fullscreen mode

You can also check the email via a validates

class User < ActiveRecord::Base
  validates :email, email: { no_sub_addressed: true, recorded: true, blacklisted: true }
end
Enter fullscreen mode Exit fullscreen mode

You can see it here:
https://github.com/OpenGems/rails_email_checker

The other gems allows you to generate dynamic "scopes" according to your columns.

class User < ApplicationRecord
  include RailsScopy
end


User.not_admin
User.first_name_contains('Test')
Enter fullscreen mode Exit fullscreen mode

List of scopes:

SQL type Scope method Description
All #{column}_eq(value) equal
All #{column}_not_eq(value) not equal
All #{column}_null is null
All #{column}_not_null is not null
All #{column}_present not null and not empty
All #{column}_blank null or empty
All ascend_by_#{column} ascending order
All descend_by_#{column} descending order
boolean #{column} true
boolean not_#{column} false
json #{column}_has_key(value) key present in json
json not_#{column}_has_not_key(value) key doesn't present in json
boolean #{column} true
boolean not_#{column} false
date, datetime, time #{column}_to(value) <= to
date, datetime, time #{column}_from(value) from >=
date, datetime, time #{column}_after(value) after >
date, datetime, time #{column}_before(value) < before
date, datetime, time #{column}_between(value) from >= <= to
string, text #{column}_contains(value) contains
string, text #{column}_not_contains(value) doesn't contains
string, text #{column}_starts_with(value) start with
string, text #{column}_not_starts_with(value) doesn't start with
string, text #{column}_ends_with(value) end with
string, text #{column}_not_ends_with(value) doesn't end with
string, text #{column}_length(value) length eql
string, text #{column}_between_length(value) from >= <= to (length)
integer, float #{column}_to(value) <= to
integer, float #{column}_from(value) from >=
integer, float #{column}_above(value) above >
integer, float #{column}_below(value) < below
integer, float #{column}_between(value) from >= <= to
float #{column}_scale(value) scale eql (Number of decimal digits)

You can see it here:
https://github.com/OpenGems/rails_scopy

Thanks !

Top comments (0)