Class: Coque::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/coque/context.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dir = Dir.pwd, env = {}, disinherits_env = false) ⇒ Context

Returns a new instance of Context.



4
5
6
7
8
# File 'lib/coque/context.rb', line 4

def initialize(dir = Dir.pwd, env = {}, disinherits_env = false)
  @dir = dir
  @env = env
  @disinherits_env = disinherits_env
end

Instance Attribute Details

#dirObject (readonly)

Returns the value of attribute dir.



3
4
5
# File 'lib/coque/context.rb', line 3

def dir
  @dir
end

#envObject (readonly)

Returns the value of attribute env.



3
4
5
# File 'lib/coque/context.rb', line 3

def env
  @env
end

Instance Method Details

#[](*args) ⇒ Object



14
15
16
# File 'lib/coque/context.rb', line 14

def [](*args)
  Sh.new(self, args)
end

#chdir(new_dir) ⇒ Object



22
23
24
# File 'lib/coque/context.rb', line 22

def chdir(new_dir)
  Context.new(new_dir, env, disinherits_env?)
end

#disinherit_envObject



31
32
33
# File 'lib/coque/context.rb', line 31

def disinherit_env
  Context.new(dir, {}, true)
end

#disinherits_env?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/coque/context.rb', line 10

def disinherits_env?
  @disinherits_env
end

#rb(&block) ⇒ Object



18
19
20
# File 'lib/coque/context.rb', line 18

def rb(&block)
  Rb.new(self, &block)
end

#setenv(opts) ⇒ Object



26
27
28
29
# File 'lib/coque/context.rb', line 26

def setenv(opts)
  opts = opts.map { |k,v| [k.to_s, v.to_s] }.to_h
  Context.new(dir, self.env.merge(opts), disinherits_env?)
end