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
paperclip-v2_7-patched-ruby-1_8_6-2.7.5 lib/paperclip/callback_compatibility.rb
paperclip-2.7.5 lib/paperclip/callback_compatibility.rb
smarter_paperclip-0.3.3 lib/paperclip/callback_compatability.rb
smarter_paperclip-0.3.2 lib/paperclip/callback_compatability.rb
smarter_paperclip-0.3.1 lib/paperclip/callback_compatability.rb
paperclip-2.7.4 lib/paperclip/callback_compatibility.rb
paperclip-2.7.2 lib/paperclip/callback_compatibility.rb
paperclip-2.8.0 lib/paperclip/callback_compatibility.rb
paperclip-2.7.1 lib/paperclip/callback_compatibility.rb
cloudfuji_paperclip-2.4.6 lib/paperclip/callback_compatibility.rb
radiant-1.0.0 ruby-debug/ruby/1.8/gems/paperclip-2.3.16/lib/paperclip/callback_compatibility.rb
paperclip-2.7.0 lib/paperclip/callback_compatibility.rb
paperclip-2.6.0 lib/paperclip/callback_compatibility.rb
paperclip-2.5.2 lib/paperclip/callback_compatibility.rb
paperclip-2.5.1 lib/paperclip/callback_compatibility.rb
smarter_paperclip-0.3.0 lib/paperclip/callback_compatability.rb
paperclip-2.5.0 lib/paperclip/callback_compatibility.rb
mender_paperclip-2.4.3.1 lib/paperclip/callback_compatibility.rb
cemeng-paperclip-2.3.6 lib/paperclip/callback_compatability.rb
jmcnevin-paperclip-2.4.5.1 lib/paperclip/callback_compatibility.rb