0.0
No commit activity in last 3 years
No release in over 3 years
Add attributes without any sort of integrity to your ActiveRecord or other types of objects.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

~> 3.4.0
 Project Readme

NoIntegrity

What is This?

Simple hash serialization with loose type coercion. Built for ActiveRecord models, but does not rely specifically on anything from Rails.

How do I use it?

For starters, throw this in your Gemfile:

gem "no_integrity"

Then, add this to your class:

class MrArbitrary < ActiveRecord::Base
  include NoIntegrity

  attr_accessor :some_random_hash

  no_attribute :misc
  no_attribute :hair, type: 'String'
  no_attribute :age, type: 'Integer'
  no_attribute :height, type: 'String'
  no_attribute :eyes, type: 'String'
  no_attribute :friendly, type: 'Boolean', default: true
  no_attribute :cheese
  no_attribute :ham
  no_attribute :balogne
end

Finally, you can make calls like this:

arbs = MrArbitrary.new
arbs.friendly? # => false
arbs.friendly = true
arbs.friendly? # => true

You can define as many attributes as you want, and you can specify any of the following coercion types:

  1. String
  2. Integer
  3. Boolean

Upgrading From 0.4.0

For 0.5.0 I added the ability to store default values for each of the attributes. This required some changes to the way that attributes were setup and stored for each object.

In your classes you'll need to convert from:

no_attribute hair: 'String'

To:

no_attribute :hair, type: 'String'

Also if you relied on any of the undocumented method calls, you'll need to update them so they can handle the new internal structure.

Why?

A while back, I needed serialized attributes but it either didn't work for my use case or it wasn't made yet. So, I wrote this gem.

Contributing

Do not modify the gemspec or version unless you absolutely need to!

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request