Sha256: 14d502b39179d77416faa5d58540a796288fc94af4f744bd9b274e8cbde16074

Contents?: true

Size: 559 Bytes

Versions: 11

Compression:

Stored size: 559 Bytes

Contents

module Mongoid
  module Publishable
    class Callback
      def initialize(*args, &block)
        if block_given?
          @method = block
        elsif args.length == 1 && args[0].kind_of?(Symbol)
          @method = args[0]
        else
          raise ArgumentError, "after_publish only allows a block or a symbol method reference as arguments"
        end
      end
      
      def process(object)
        if @method.respond_to?(:yield)
          @method.yield(object)
        else
          object.send(@method)
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
mongoid-publishable-0.4.0 lib/mongoid/publishable/callback.rb
mongoid-publishable-0.3.2 lib/mongoid/publishable/callback.rb
mongoid-publishable-0.3.1 lib/mongoid/publishable/callback.rb
mongoid-publishable-0.2.1 lib/mongoid/publishable/callback.rb
mongoid-publishable-0.2.0 lib/mongoid/publishable/callback.rb
mongoid-publishable-0.1.0 lib/mongoid/publishable/callback.rb
mongoid-publishable-0.0.5 lib/mongoid/publishable/callback.rb
mongoid-publishable-0.0.4 lib/mongoid/publishable/callback.rb
mongoid-publishable-0.0.3 lib/mongoid/publishable/callback.rb
mongoid-publishable-0.0.2 lib/mongoid/publishable/callback.rb
mongoid-publishable-0.0.1 lib/mongoid/publishable/callback.rb