Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
validates_lengths_from_database
Advanced tools
{}[http://travis-ci.org/rubiety/validates_lengths_from_database] {}[https://gemnasium.com/rubiety/validates_lengths_from_database] {}[https://codeclimate.com/github/rubiety/validates_lengths_from_database]
== Validates Lengths from Database
Few people add length validations to fields in their database, and when saving such fields that have exhausted their length, an SQL error occurs. This gem introspects your table schema for maximum lengths on string and text fields and automatically adds length validations to the model.
== Requirements
Due to issues maintaining backwards compatibility, as of v0.8.0 validates_lengths_from_database requires ruby 2 or higher. If you are still using 1.9, please use the v0.7.0 release.
== Installation
Include the gem using bundler in your Gemfile:
gem "validates_lengths_from_database"
== Usage
In your model you can activate validations:
class Post < ActiveRecord::Base validates_lengths_from_database end
It also supports filter-style :only and :except options:
class Post < ActiveRecord::Base validates_lengths_from_database :only => [:title, :contents] end
class Post < ActiveRecord::Base validates_lengths_from_database :except => [:other_field] end
If you'd rather specify the limits explicitly instead of pulling them from the database, you can set it:
class Post < ActiveRecord::Base validates_lengths_from_database :limit => 255 end
Or to set the limit differently for string (VARCHAR) and (TEXT) columns:
class Post < ActiveRecord::Base validates_lengths_from_database :limit => {:string => 255, :text => 4092} end
Since v0.5.2, it's possible to use the validate_lengths_from_database
on an abstract parent (without a table), such as +ApplicationRecord+ or ActiveRecord::Base.
class ApplicationRecord < ActiveRecord::Base self.abstract_class = true validates_lengths_from_database :limit => 255 end
class Post < ApplicationRecord end
class User < ApplicationRecord validates_lengths_from_database :only => [:name] end
class Comment < ApplicationRecord validate_lengths_from_database_options[:only] << :name end
== Running Tests
This gem uses appraisal to test with different versions of the dependencies. See Appraisal first for which versions are tested.
$ rake test
$ appraisal install $ appraisal rake test
FAQs
Unknown package
We found that validates_lengths_from_database 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.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.