Module: Octopus::ShardTracking::ClassMethods

Defined in:
lib/octopus/shard_tracking.rb

Instance Method Summary collapse

Instance Method Details

#create_sharded_method(name) ⇒ Object


15
16
17
18
19
20
21
22
23
24
25
# 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) ⇒ Object

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


11
12
13
# File 'lib/octopus/shard_tracking.rb', line 11

def sharded_methods(*methods)
  methods.each { |m| create_sharded_method(m) }
end