module Octopus::ShardTracking::ClassMethods

Public Instance Methods

create_sharded_method(name) click to toggle source
# File lib/octopus/shard_tracking.rb, line 15
def create_sharded_method(name)
  name.to_s =~ /([^!?]+)([!?])?/
  method, punctuation = [Regexp.last_match[1], Regexp.last_match[2]]
  with = :"#{method}_with_octopus#{punctuation}"
  without = :"#{method}_without_octopus#{punctuation}"
  define_method with do |*args, &block|
    run_on_shard { send(without, *args, &block) }
  end
  alias_method without.to_sym, name.to_sym
  alias_method name.to_sym, with.to_sym
end
sharded_methods(*methods) click to toggle source

If the class which includes this module responds to the class method sharded_methods, then automagically alias_method_chain a sharding-friendly version of each of those methods into existence

# File lib/octopus/shard_tracking.rb, line 11
def sharded_methods(*methods)
  methods.each { |m| create_sharded_method(m) }
end