Giter VIP home page Giter VIP logo

nilly_vanilly's Introduction

NillyVanilly

This Rails gem/plugin stores NULL in your database when you try to store an empty string.

Build Status

It only works for columns you explicitly mention inside your model. It comes with a rake task which prints out all the columns eligible for nillification.

Since HTTP parameters are always strings, an empty string is sent by form values for which you did not mean to enter any value. This plugin makes sure to save NULL in database varchar columns that are defined with DEFAULT NULL.

Example

class Comment < ActiveRecord::Base
  nillify :author_url
end

comment = Comment.create :author_url => ""
comment.author_url        # -> nil

Installation

Install this gem using Bundler:

gem 'nilly_vanilly'

and then run bundle.

Inspection

To see what columns are eligible for nillification, run the following:

rake nilly:vanilly:inspect

This will print a list of all tables in your database, cross-referenced with the models in your application. All text columns which may be NULL and are nil by default are shown, i.e. all these columns should be safe to nillify. This does not take into account any validations you might have.

When a column has already been nillified, it will be indicated with [OK].

But WHY?!!

You: who cares that empty strings are stored in the database? Me: if you don't care, just move along. And would I recommend you nillify every attribute in your application? No. But beside from the fact that NULL is the "correct" value for something you don't know, enforcing this is required if you have a unique index on that column. Unique indexes are the fastest you can have, and they deal great with NULL values. Empty strings? Not so much so.

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/tilsammans/nilly_vanilly. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

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

Author

Joost Baaij [email protected] www.spacebabies.nl

nilly_vanilly's People

Contributors

cedum avatar dependabot[bot] avatar tilsammans avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

nilly_vanilly's Issues

rake nilly:vanilly:inspect doesn't work with PostgreSQL

Running the following command after adding gem 'nilly_vanilly' to Gemfile and running bundle install :

rake nilly:vanilly:inspect

produce folllowing error :

rake aborted!
Don't know how to build task 'nilly:vanilly:inspect'

In fact, the whole gem is not working at all...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.