Sha256: 4eed4d81f1f4e3cd6513cebb3b711538858eea24042bff9b0b54e0fa9c2926d0

Contents?: true

Size: 869 Bytes

Versions: 2

Compression:

Stored size: 869 Bytes

Contents

# These are just utlity functions used by Ampere internally to generate Redis
# keys for various Ampere functions, for DRY excellence. 
module Ampere #:nodoc:
  module Keys #:nodoc:
    # These methods get mixed in to class and instance
    def self.included(base)
      # base.extend(ClassMethods)
      base.extend(self)
    end
    
    def key_for_find(parent_model, id)
      unless id =~ /\./
        id = "#{parent_model.to_s.downcase}.#{id}"
      end
      id
    end
    
    def key_for_has_many(parent_model, id, field)
      [parent_model, id, 'has_many', field].flatten.join('.')
    end
    
    def key_for_index(field)
      ['ampere', 'index', model_name.downcase, field].flatten.join('.')
    end
    
    private
    
    def model_name
      if self.class == Class then
        to_s
      else
        self.class.to_s
      end
    end
  
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ampere-1.2.1 lib/ampere/keys.rb
ampere-1.2.0 lib/ampere/keys.rb