V(irtual)attributes

Makes virtual attributes easier.

Build Status Coverage Status Code Climate Dependency Status Gem Version

Instalation

Add this line to your application's Gemfile:

gem 'vattributes'

And then execute:

$ bundle

Usage

Add the vattributes field to the table as a text and run the migration:

rails g migration AddVattributesToPosts vattributes:text
rake db:migrate
class Post < ActiveRecord::Base
  vattributes :permalink

  validates :permalink, presence: true
end

If you ever need to overrite a setter, or getter, you can do like follows:

class Post < ActiveRecord::Base
  vattributes :tags, :permalink

  def tags=(array)
    set_vattribute(:tags, array.join(','))
  end

  def tags
    get_vattribute(:tags).split(',')
  end
end

Authors

Contributing

  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

** Do not forget to write tests**