Purpose

Alternative for AOP libaries providing simple syntax and containing less than 100 rows of code.

Containing only:

  • before

  • after

  • around (Not implemented yet)

Installation

Add to your Gemfile:

gem 'anchor'

And run:

bundle install

Or run:

gem install anchor

Naming recommendations

You can name things as you want, but it is recommended to it so:

Example: Using hooks for models in Rails app (Not implemented yet)

Create app/hooks/model_name.rb

anchor ModelName do

  before :save do
    puts "Before save #{self.inspect}"
  end

end

Example: Using hooks for conserns in Rails app (Not implemented yet)

Create app/hooks/model_name/what_for_hook_is_itended.rb

...

Example: Using hooks in models

You can also do in app/models/your_model.rb

class YourModel
  include Anchor::Hooks

  before :save do
    puts "Before save #{self.inspect}"
  end

end

Usage examples

You can find some examples from:

Method regexp

anchor Yourmodel do
  before self.instance_methods.grep(/$methods/) do
    puts 
  end
end