Schmetterling

Simple aspects implemented on Module#prepend.

Requirements

Ruby 2.0

Highlights

  • Support before/after/around advices
  • Separate cross-cutting concerns

How it works

Every time you add an advice a new anonymous module is created and prepended to the adviced class.

The similar effect can be achived with alias method chaining.

Usage

class User
  def recommend_book(book)
    @recommended_books << book
  end
end

class Twitter
  def publish(token, message)
    # ...
  end
end

require 'schmetterling/dsl'
class AppConfiguration
  include Schmetterling::DSL

  def initialize(twitter)
    @twitter = twitter
  end

  def enable
    After(User, :recommend_book) do |user, book|
      twitter.publish(user.twitter_token, "Hey, I just read #{book.title}")
    end
  end
end