Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
format_for_extensions
Advanced tools
= format_for_extensions
Tired of repeating 'validates_format_of' with the same regex expression across your models only to validate the same email address and postal code fields? So am I. Use format_for_extensions to dynamically define reusable formats for any field you want.
By default, format_for_extensions comes with smart formats for email addresses and postal codes. Even better, no code repetition! Use constructs that make sense such as "validates_email_for :account_owner" and "validates_postal_code_for :address_postal_code".
== System Requirements format_for_extensions should work with Rails 2.3.5 and above. However, I have not yet tested this with Rails 3.1.
== Installation Modify your Gemfile to include format_for_extensions:
gem 'format_for_extensions'
Run bundle install
. You thought it would be harder?
== Usage By default, format_for_extensions supports email and postal code formats. These can be leveraged by including code such as:
class Person < ActiveRecord::Base # Notice how the normal ActiveRecord Validation options can still be used... validates_email_for :email_address validates_email_for :home_email_address, :if => :full_validation_required validates_postal_code_for :postal_code, :allow_blank => true end
=== Configuration
Default configurations are specified in the gem's config/format_for_extensions.yml file. If you wish to modify the default regular expressions or messages reported when validation fails, simply copy this file to the config directory in your Rails root folder. You can also manually create [rails_root]/config/format_for_extensions.yml if you'd like to.
The format of this file is as follows:
en: email: regex: /^([^@\s]+)@((?:[-a-z0-9]+.)+[a-z]{2,})$/ message: "is invalid. The address should be in a format similar to 'user@example.com'."
PLEASE NOTE that localization is not really supported at this time. By default we only support english mappings, the 'en' locale exists to allow us to more easily support localization in the future.
If you modify this file, you will need to bounce your application server (or restart your rails console) as this gem caches configurations at load time.
=== The Hotness You can dynamically create your own format validators! For instance, add this to your [rails_root]/config/format_for_extensions.yml file:
en: hotness: regex: /^hot/ message: "is not hot!"
And you now have a completely useless method to validate that fields begin with 'hot':
class Person < ActiveRecord::Base # Validation will fail if your first_name does not begin with 'hot' validates_hotness_for :first_name end
As you might have guessed, the gem is driven off of the configuration file. The same way you can add validators, you can remove them by simply deleting lines from the configuration file.
== TODO
== Contributing to format_for_extensions
== Copyright
Copyright (c) 2011 CustomInk. See LICENSE.txt for further details.
FAQs
Unknown package
We found that format_for_extensions demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers 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
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.