Sha256: acb1d6cd9ecbb6a11d29fe38be1024788cf9c053b9c080d0f7007864cde8f05f

Contents?: true

Size: 1.01 KB

Versions: 2

Compression:

Stored size: 1.01 KB

Contents

# Author: Stephen Sykes

module SlimScrooge
  class Callsites
    CallsitesMutex = Mutex.new
    @@callsites = {}

    class << self
      def has_key?(callsite_key)
        @@callsites.has_key?(callsite_key)
      end

      def [](callsite_key)
        @@callsites[callsite_key]
      end

      def callsite_key(callsite_hash, sql)
        callsite_hash + sql.gsub(/WHERE.*/i, "").hash
      end

      def create(sql, callsite_key, name)
        begin
          model_class = name.split.first.constantize
        rescue NameError, NoMethodError
          add_callsite(callsite_key, nil)
        else
          add_callsite(callsite_key, Callsite.make_callsite(model_class, sql))
        end
      end

      def add_callsite(callsite_key, callsite)
        CallsitesMutex.synchronize do
          @@callsites[callsite_key] = callsite
        end
      end

      def add_seen_column(callsite, seen_column)
        CallsitesMutex.synchronize do
          callsite.seen_columns << seen_column
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
slim_scrooge-1.0.0 lib/slim_scrooge/callsites.rb
slim_scrooge-0.1.1 lib/slim_scrooge/callsites.rb