Sha256: 1f76527e1219e0e2b26005a67031fe3ec461dcfe403b7d90f41f8c9e11b853f8

Contents?: true

Size: 682 Bytes

Versions: 10

Compression:

Stored size: 682 Bytes

Contents

require 'active_support/concern'

module Ardm
  module ActiveRecord
    module Hooks
      extend ActiveSupport::Concern

      module ClassMethods
        def before(event, meth=nil, &block)
          _ardm_hook(:before, event, meth, &block)
        end

        def after(event, meth=nil, &block)
          _ardm_hook(:after, event, meth, &block)
        end

        def _ardm_hook(order, event, meth=nil, &block)
          if event.to_sym == :valid?
            event = "validation"
          end

          if meth.nil?
            send "#{order}_#{event}", &block
          else
            send "#{order}_#{event}", meth
          end
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
ardm-0.2.7 lib/ardm/active_record/hooks.rb
ardm-0.2.6 lib/ardm/active_record/hooks.rb
ardm-0.2.5 lib/ardm/active_record/hooks.rb
ardm-0.2.4 lib/ardm/active_record/hooks.rb
ardm-0.2.3 lib/ardm/active_record/hooks.rb
ardm-0.2.2 lib/ardm/active_record/hooks.rb
ardm-0.2.1 lib/ardm/active_record/hooks.rb
ardm-0.2.0 lib/ardm/active_record/hooks.rb
ardm-0.1.0 lib/ardm/active_record/hooks.rb
ardm-0.0.1 lib/ardm/active_record/hooks.rb