Sha256: 0be5f2cfeed3e92c3a0fa0e6ab9cbf891179bd8c6a1c6c98b99ee392244b36d9

Contents?: true

Size: 1.74 KB

Versions: 71

Compression:

Stored size: 1.74 KB

Contents

module Paperclip
  module CallbackCompatability
    module Rails21
      def self.included(base)
        base.extend(Defining)
        base.send(:include, Running)
      end

      module Defining
        def define_paperclip_callbacks(*args)
          args.each do |callback|
            define_callbacks("before_#{callback}")
            define_callbacks("after_#{callback}")
          end
        end
      end

      module Running
        def run_paperclip_callbacks(callback, opts = nil, &blk)
          # The overall structure of this isn't ideal since after callbacks run even if
          # befores return false. But this is how rails 3's callbacks work, unfortunately.
          if run_callbacks(:"before_#{callback}"){ |result, object| result == false } != false
            blk.call
          end
          run_callbacks(:"after_#{callback}"){ |result, object| result == false }
        end
      end
    end

    module Rails3
      def self.included(base)
        base.extend(Defining)
        base.send(:include, Running)
      end

      module Defining
        def define_paperclip_callbacks(*callbacks)
          define_callbacks *[callbacks, {:terminator => "result == false"}].flatten
          callbacks.each do |callback|
            eval <<-end_callbacks
              def before_#{callback}(*args, &blk)
                set_callback(:#{callback}, :before, *args, &blk)
              end
              def after_#{callback}(*args, &blk)
                set_callback(:#{callback}, :after, *args, &blk)
              end
            end_callbacks
          end
        end
      end

      module Running
        def run_paperclip_callbacks(callback, opts = nil, &block)
          run_callbacks(callback, opts, &block)
        end
      end

    end

  end
end

Version data entries

71 entries across 71 versions & 23 rubygems

Version Path
jmcnevin-paperclip-2.4.5 lib/paperclip/callback_compatibility.rb
paperclip-2.4.5 lib/paperclip/callback_compatibility.rb
mender_paperclip-2.4.3 lib/paperclip/callback_compatibility.rb
paperclip-2.4.4 lib/paperclip/callback_compatibility.rb
paperclip-2.4.3 lib/paperclip/callback_compatibility.rb
paperclip-2.4.2 lib/paperclip/callback_compatibility.rb
paperclip-2.4.1 lib/paperclip/callback_compatibility.rb
paperclip-2.4.0 lib/paperclip/callback_compatibility.rb
paperclip-2.3.16 lib/paperclip/callback_compatibility.rb
paperclip-2.3.15 lib/paperclip/callback_compatibility.rb
olek-paperclip-2.3.3.2 lib/paperclip/callback_compatability.rb
paperclip-2.3.12 lib/paperclip/callback_compatibility.rb
paperclip-cloudfiles-2.3.10.1 lib/paperclip/callback_compatability.rb
paperclip-cloudfiles-2.3.8.6 lib/paperclip/callback_compatability.rb
sayso-paperclip-2.3.10.001 lib/paperclip/callback_compatability.rb
paperclip-cloudfiles-2.3.8.5 lib/paperclip/callback_compatability.rb
ryansch-paperclip-2.3.10 lib/paperclip/callback_compatability.rb
olek-paperclip-2.3.3.1 lib/paperclip/callback_compatability.rb
paperclip-2.3.11 lib/paperclip/callback_compatability.rb
paperclip-2.3.10 lib/paperclip/callback_compatability.rb