Sha256: 26049a473f2225a76670fe5cfb243a7fc5feae74e39fe29bc3d0d3416268d333

Contents?: true

Size: 596 Bytes

Versions: 17

Compression:

Stored size: 596 Bytes

Contents

module SuperModel
  module Observing
    extend ActiveSupport::Concern
    include ActiveModel::Observing

    included do
      %w( create save update destroy ).each do |method|
        class_eval(<<-EOS, __FILE__, __LINE__ + 1)
          def #{method}_with_notifications(*args, &block)
            notify_observers(:before_#{method})
            if result = #{method}_without_notifications(*args, &block)
              notify_observers(:after_#{method})
            end
            result
          end
        EOS
        alias_method_chain(method, :notifications)
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 3 rubygems

Version Path
worsemodel-0.2.0 lib/supermodel/observing.rb
worsemodel-0.1.9 lib/supermodel/observing.rb
worsemodel-0.1.8 lib/supermodel/observing.rb
worsemodel-0.1.7 lib/supermodel/observing.rb
supermodel-0.1.6 lib/supermodel/observing.rb
supermodel-0.1.5 lib/supermodel/observing.rb
csun-student-affairs-supermodel-0.1.5 lib/supermodel/observing.rb
supermodel-0.1.4 lib/supermodel/observing.rb
supermodel-0.1.3 lib/supermodel/observing.rb
supermodel-0.1.2 lib/supermodel/observing.rb
supermodel-0.1.0 lib/supermodel/observing.rb
supermodel-0.0.8 lib/supermodel/observing.rb
supermodel-0.0.6 lib/supermodel/observing.rb
supermodel-0.0.5 lib/supermodel/observing.rb
supermodel-0.0.4 lib/supermodel/observing.rb
supermodel-0.0.2 lib/supermodel/observing.rb
supermodel-0.0.1 lib/supermodel/observing.rb