Sha256: 4fc2636a812493683a8b0b267681fa5c9531fc18f17f93ea6ab5d9c98f6a4885

Contents?: true

Size: 722 Bytes

Versions: 1

Compression:

Stored size: 722 Bytes

Contents

module OldApiResource
  
  module Observing
    
    extend ActiveSupport::Concern
    include ActiveModel::Observing
    
    # Redefine these methods to 
    included do
      %w( create save update destroy ).each do |method|
        alias_method_chain method, :observers
    end
    
    module InstanceMethods
      %w( create save update destroy ).each do |method|
        module_eval <<-EOE, __FILE__, __LINE__ + 1
          def #{method}_with_observers(*args)
            notify_observers(:before_#method)
            if result = #{method}_without_observers(*args)
              notify_observers(:after_#{method})
            end
            return result
          end
        EOE
      end
    end
    
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
old_api_resource-0.3.0 lib/old_api_resource/observing.rb