class Mongoid::Token::CollisionResolver

Attributes

create_new_token[RW]
field_name[R]
klass[R]
retry_count[R]

Public Class Methods

new(klass, field_name, retry_count) click to toggle source
# File lib/mongoid/token/collision_resolver.rb, line 11
def initialize(klass, field_name, retry_count)
  @create_new_token = Proc.new {|doc|}
  @klass = klass
  @field_name = field_name
  @retry_count = retry_count
  klass.send(:include, Mongoid::Token::Collisions)
  alias_method_with_collision_resolution(:insert)
  alias_method_with_collision_resolution(:upsert)
end

Public Instance Methods

create_new_token_for(document) click to toggle source
# File lib/mongoid/token/collision_resolver.rb, line 21
def create_new_token_for(document)
  @create_new_token.call(document)
end

Private Instance Methods

alias_method_with_collision_resolution(method) click to toggle source
# File lib/mongoid/token/collision_resolver.rb, line 26
def alias_method_with_collision_resolution(method)
  handler = self
  klass.send(:define_method, :"#{method.to_s}_with_#{handler.field_name}_safety") do |method_options = {}|
    self.resolve_token_collisions handler do
      with(:safe => true).send(:"#{method.to_s}_without_#{handler.field_name}_safety", method_options)
    end
  end
  klass.alias_method_chain method.to_sym, :"#{handler.field_name}_safety"
end