Skip to content

Make nilify_blanks more generic and applicable even for non-DB  #17

@hgani

Description

@hgani

Hi,

Please consider adding the following features to nilify_blanks.

  1. Add an 'after' option similar to that of 'before'
  2. Allow it to be used by the more general ActiveModel::Model instead of just ActiveRecord::Base

The reasoning is that it can be useful to apply nilify_blanks in after_initialize, so that we can treat all attributes consistently (not only ones that are saved into DB, but also ones that are not yet saved, and even ones that are not DB columns).

It's true that the initial intent was to provide consistency for stored DB values. But it's better if this consistency also applies at code (ruby) level, so we know that unspecified values are always nil.

This consistency can then be taken to a higher level, whereby non-DB-backed models (ActiveModel::Model) also have the same behaviour.

Thank you

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions