0.0
No commit activity in last 3 years
No release in over 3 years
The concern mechanism in ActiveSupport is handy but the code does a lot of stuff, most of which isn't needed in the vast majority of cases. Code you don't need is code that can cause unexpected issues. This gem, based on the wonderful 'augmnentations' plugin by henrik, provides similar behaviour without the cruft. Or, indeed, ActiveSupport.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

~> 1.6
~> 10.0
 Project Readme

Augmentations gem

Augmentations is a tiny Ruby gem to easily extend any class with instance methods and class methods, as well as running class methods like belongs_to at extend time.

It's basically like includeing a module, but you can also define class methods and call class methods as you would in the class itself, without (ab)using the self.included hook and thus with less boilerplate.

Why do we need this now ActiveSupport has Concerns? Several reasons.

1: You're using plain Ruby or a non-Rails framework and you want the behaviour without the bulk of ActiveSupport.

2: You don't like the fact that ActiveSupport calls them 'Concerns' when they're just modules effectively implementing a form of multiple inheritance.

3: You don't like the module dependency management system built in to ActiveSupport Concerns. (Modules that depend on each other are a code smell, cyclical dependencies doubly so.)

Use it like

class User < ActiveRecord::Base
  augment Shared::Pingable, User::PasswordResetExtension
end

with modules like

module User::PasswordResetExtension
  augmentation do

    has_many :password_resets

    def self.a_class_method
      # …
    end

    def an_instance_method
      # …
    end

  end
end

(If you want to weird things up in the name of fewer lines of code, the Ruby parser will accept

module User::PasswordResetExtension augmentation do

    …

end end

too.)

Installation

Add this line to your application's Gemfile:

gem 'augmentations'

And then execute:

$ bundle

Or install it yourself as:

$ gem install augmentations

Unless you're using Bundler, in your code:

require 'augmentations'

Credits

Originally by Henrik Nyh for DanceJam under the MIT license.

Original repository

Contributing

  1. Fork it ( https://github.com/[my-github-username]/augmentations/fork )
  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 a new Pull Request