Sha256: adcb593b104a89ea7332975a71c047ac66b1b9a355b7d5d95bc827f2b89e62bb

Contents?: true

Size: 1 KB

Versions: 1

Compression:

Stored size: 1 KB

Contents

module Octopus
  module Rails2
    module Persistence
      def self.included(base)
        base.instance_eval do
          alias_method_chain :destroy, :octopus
          alias_method_chain :delete, :octopus
          alias_method_chain :reload, :octopus
        end
      end

      def delete_with_octopus()
        if should_set_current_shard?
          Octopus.using(self.current_shard) { delete_without_octopus() }
        else
          delete_without_octopus()
        end
      end

      def destroy_with_octopus()
        if should_set_current_shard?
          Octopus.using(self.current_shard) { destroy_without_octopus() }
        else
          destroy_without_octopus()
        end
      end

      def reload_with_octopus(options = nil)
        if should_set_current_shard?
          Octopus.using(self.current_shard) { reload_without_octopus(options) }
        else
          reload_without_octopus(options)
        end
      end
    end
  end
end

ActiveRecord::Base.send(:include, Octopus::Rails2::Persistence)

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ar-octopus-0.5.0 lib/octopus/rails2/persistence.rb