Method: Tap::Env#initialize

Defined in:
lib/tap/env.rb

#initialize(config_or_dir = Dir.pwd, context = {}) ⇒ Env

Initializes a new Env linked to the specified directory. Configurations for the env will be loaded from the config file (as determined by the context) if it exists.

A configuration hash may be manually provided in the place of dir. In that case, no configurations will be loaded, even if the config file exists.

Context can be specified as a Context, or a Hash used to initialize a Context.



383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
# File 'lib/tap/env.rb', line 383

def initialize(config_or_dir=Dir.pwd, context={})
  
  # setup root

  config = nil
  @root = case config_or_dir
  when Root
    config_or_dir
  when String
    Root.new(config_or_dir)
  else
    config = config_or_dir
    
    if config.has_key?(:root) && config.has_key?('root')
      raise "multiple values mapped to :root"
    end
    
    root = config.delete(:root) || config.delete('root') || Dir.pwd
    root.kind_of?(Root) ? root : Root.new(root)
  end
  
  # note registration requires root.root, and so the

  # setup of context must follow the setup of root.

  @context = case context
  when Context
    context
  when Hash
    Context.new(context)
  else raise "cannot convert #{context.inspect} to Tap::Env::Context"
  end
  @context.register(self)
  
  # these need to be set for reset_env

  @active = false
  @gems = nil
  @env_paths = nil
  
  # only load configurations if configs were not provided

  config ||= Env.load_config(@context.config_file(@root.root))
  initialize_config(config)
  
  # set the invert flag

  @invert = false
end