Module: Octopus::ShardTracking::ClassMethods
- Defined in:
- lib/octopus/shard_tracking.rb
Instance Method Summary collapse
- #create_sharded_method(name) ⇒ Object
-
#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.
Instance Method Details
#create_sharded_method(name) ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/octopus/shard_tracking.rb', line 14 def create_sharded_method(name) name.to_s =~ /([^!?]+)([!?])?/ method, punctuation = [ $1, $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_chain name.to_sym, :octopus 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
10 11 12 |
# File 'lib/octopus/shard_tracking.rb', line 10 def sharded_methods(*methods) methods.each { |m| create_sharded_method(m) } end |