Sha256: 43e137e4e17eee31c5158b70052f05d753d3e536e77ba4917de68483c4dc0536

Contents?: true

Size: 1.17 KB

Versions: 19

Compression:

Stored size: 1.17 KB

Contents

#
# The Chance factory.
# All methods require two parts: a key and a hash of options. The hash will be used in
# the case of a cache missed.
#
module Chance
  module ChanceFactory
    
    @instances = {}
    @file_hashes = {}
    class << self
      def clear_instances
        @file_hashes = {}
        @instances = {}
      end
    
      def instance_for_key(key, opts)
        if not @instances.include? key
          @instances[key] = Chance::Instance.new(opts)
        end
        
        return @instances[key]
      end
    
      # Call with a hash mapping instance paths to absolute paths. This will compare with
      # the last 
      def update_instance(key, opts, files)
        instance = instance_for_key(key, opts)
        last_hash = @file_hashes[key] || {}
        
        # If they are not equal, we might as well throw everything. The biggest cost is from
        # Chance re-running, and it will have to anyway.
        if not last_hash.eql? files
          instance.unmap_all
          files.each {|path, identifier|
            instance.map_file path, identifier
          }
          
          @file_hashes[key] = files
        end
      end
      
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
sproutcore-1.11.0 vendor/chance/lib/chance/factory.rb
sproutcore-1.11.0.rc3 vendor/chance/lib/chance/factory.rb
sproutcore-1.11.0.rc2 vendor/chance/lib/chance/factory.rb
sproutcore-1.11.0.rc1 vendor/chance/lib/chance/factory.rb
sproutcore-1.10.3.1 vendor/chance/lib/chance/factory.rb
sproutcore-1.10.2 vendor/chance/lib/chance/factory.rb
sproutcore-1.10.1 vendor/chance/lib/chance/factory.rb
sproutcore-1.10.0 vendor/chance/lib/chance/factory.rb
sproutcore-1.10.0.rc.3 vendor/chance/lib/chance/factory.rb
sproutcore-1.10.0.rc.2 vendor/chance/lib/chance/factory.rb
sproutcore-1.10.0.rc.1 vendor/chance/lib/chance/factory.rb
sproutcore-1.9.2 vendor/chance/lib/chance/factory.rb
sproutcore-1.9.1 vendor/chance/lib/chance/factory.rb
sproutcore-1.9.0 vendor/chance/lib/chance/factory.rb
sproutcore-1.8.2.1 vendor/chance/lib/chance/factory.rb
sproutcore-1.8.1 vendor/chance/lib/chance/factory.rb
sproutcore-1.8.0 vendor/chance/lib/chance/factory.rb
sproutcore-1.7.1.beta-java vendor/chance/lib/chance/factory.rb
sproutcore-1.7.1.beta vendor/chance/lib/chance/factory.rb