module Chance::ChanceFactory

Public Class Methods

clear_instances() click to toggle source
# File vendor/chance/lib/chance/factory.rb, line 12
def clear_instances
  @file_hashes = {}
  @instances = {}
end
instance_for_key(key, opts) click to toggle source
# File vendor/chance/lib/chance/factory.rb, line 17
def instance_for_key(key, opts)
  if not @instances.include? key
    @instances[key] = Chance::Instance.new(opts)
  end
  
  return @instances[key]
end
update_instance(key, opts, files) click to toggle source

Call with a hash mapping instance paths to absolute paths. This will compare with the last

# File vendor/chance/lib/chance/factory.rb, line 27
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