All Projects → fnando → normalize_attributes

fnando / normalize_attributes

Licence: MIT License
Sometimes you want to normalize data before saving it to the database like down casing e-mails, removing spaces and so on. This Rails plugin allows you to do so in a simple way.

Programming Languages

ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to normalize attributes

mv-core
Migration Validators project core classes
Stars: ✭ 23 (-43.9%)
Mutual labels:  activerecord
filedb
ActiveRecord for static data definitions based on files
Stars: ✭ 72 (+75.61%)
Mutual labels:  activerecord
pytorch-frn
Filter Response Normalization Layer in PyTorch
Stars: ✭ 110 (+168.29%)
Mutual labels:  normalization
models stats
Charts for your rails models with MetricsGraphics.js and NVD3
Stars: ✭ 43 (+4.88%)
Mutual labels:  activerecord
TextDatasetCleaner
🔬 Очистка датасетов от мусора (нормализация, препроцессинг)
Stars: ✭ 27 (-34.15%)
Mutual labels:  normalization
active-persistence
Active Persistence is a implementation of Active Record Query Interface for JPA that makes it easy and fun.
Stars: ✭ 14 (-65.85%)
Mutual labels:  activerecord
rails cursor pagination
Add cursor pagination to your ActiveRecord backed application
Stars: ✭ 21 (-48.78%)
Mutual labels:  activerecord
active model serializers validator
🃏 An extension to ActiveModel::Serializer that validates serializers output against a JSON schema
Stars: ✭ 18 (-56.1%)
Mutual labels:  activerecord
wisper-activerecord
Transparently publish all model changes to subscribers
Stars: ✭ 97 (+136.59%)
Mutual labels:  activerecord
ar-check
Enable PostgreSQL's CHECK constraints on ActiveRecord migrations
Stars: ✭ 17 (-58.54%)
Mutual labels:  activerecord
wp-activerecord
An ActiveRecord implementation for WordPress
Stars: ✭ 19 (-53.66%)
Mutual labels:  activerecord
rails-countries
Integration between Rails and countries gem.
Stars: ✭ 17 (-58.54%)
Mutual labels:  activerecord
datetime-scopes
A plugin for ActiveRecord which adds very helpful methods for querying records over time ranges (weeks/days/months/years), and it also respects time-zones!
Stars: ✭ 14 (-65.85%)
Mutual labels:  activerecord
ar-dynattribute
Provide ActiveRecord dynamic attributes stored into the single field in serialized state
Stars: ✭ 43 (+4.88%)
Mutual labels:  activerecord
idy
👓 An ID obfuscator for ActiveRecord
Stars: ✭ 15 (-63.41%)
Mutual labels:  activerecord
zen-query
parascope gem for param-based scope generation
Stars: ✭ 25 (-39.02%)
Mutual labels:  activerecord
SimpleCurd
2个类,实现类ActiveRecord,无需写Mapper, mybatis增强
Stars: ✭ 14 (-65.85%)
Mutual labels:  activerecord
rails-microservices-book
A guide to building distributed Ruby on Rails applications using Protocol Buffers, NATS and RabbitMQ
Stars: ✭ 23 (-43.9%)
Mutual labels:  activerecord
LocalSupport
A directory of local support services and volunteer opportunities
Stars: ✭ 60 (+46.34%)
Mutual labels:  activerecord
filtered
Filters ActiveRecord queries in a nice way
Stars: ✭ 28 (-31.71%)
Mutual labels:  activerecord

Normalize Attributes

Tests Code Climate Gem Gem

Sometimes you want to normalize data before saving it to the database like downcasing e-mails, removing spaces and so on. This Rails plugin allows you to do so in a simple way.

Usage

To install:

gem install normalize_attributes

Then on your model:

class User < ActiveRecord::Base
  normalize :email, with: :downcase
end

The example above will normalize your :email attribute on the before_save callback.

You can specify multiple attributes

normalize :email, :username, with: :downcase

You can use a block

normalize :name do |value|
  value.squish
end

You can combine both

normalize :name, with: :downcase do |value|
  value.squish
end

The squish method is the default normalizer for strings. All you need to is specify the attribute:

normalize :content

The compact method is the default normalizer for arrays (when using serialize method):

class User < ActiveRecord::Base
  serialize :preferences, Array
  normalize :preferences
end

The normalize method is aliased as normalize_attributes, normalize_attribute, normalize_attr, and normalize_attrs.

You can normalize the attribute before type casting; this is specially useful for normalizing dates and numbers.

class Product
  normalize(:price, raw: true) {|v| Money.new(v).to_f }
end

You can also use it with ActiveModel::Model classes.

class UserForm
  include ActiveModel::Model
  include ActiveModel::Attributes
  include ActiveModel::Validations::Callbacks
  include NormalizeAttributes::Callbacks

  attribute :username
  normalize :username
end

Maintainer

Contributors

Contributing

For more details about how to contribute, please read https://github.com/fnando/normalize_attributes/blob/main/CONTRIBUTING.md.

License

The gem is available as open source under the terms of the MIT License. A copy of the license can be found at https://github.com/fnando/normalize_attributes/blob/main/LICENSE.md.

Code of Conduct

Everyone interacting in the normalize_attributes project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].