Activerecord Devkit

Version Build Climate Coverage

ActiveRecord DevKit is a package of utility Ruby Features for ActiveRecord.

requirements

Getting started

Add to your Gemfile:

gem 'activerecord-devkit'

Run the bundle command to install it.

For Rails projects, gun generator:

rails generate ruby_features:install

and apply required features in config/initializers/ruby-features.rb:

RubyFeatures.apply('activerecord_devkit/association_soft_build')

For no-Rails usage, apply required features just like:

require 'activerecord-devkit'

RubyFeatures.apply('activerecord_devkit/association_soft_build')

Features

activerecord_devkit/association_soft_build

Makes possible to build associated object without affecting to parent object's association scope:

user = User.first

## Regular build, user.roles.size going to be incremented
new_role = user.roles.build

## Soft build, user.roles.size will stay as is
new_role = user.roles.soft_build
# or
new_role = user.association(:roles).soft_build
# or
new_role = user.roles.where(name: 'admin').soft_build

License

MIT License. Copyright (c) 2015 Sergey Tokarenko