Class: Rigup::Context

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(aValues = nil) ⇒ Context

Returns a new instance of Context.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/rigup/context.rb', line 7

def initialize(aValues=nil)
	return if !aValues

	#is_client = !!(aValues[:key_chain] || aValues[:global_options] || aValues[:options])
	@config = aValues[:config]
	@pwd = Buzztools::File.real_path(aValues[:pwd] || (@config && @config[:folder]) || Dir.pwd)
	@options = aValues[:options]
	@argv = aValues[:argv]
	@env = aValues[:env]
	@stdout = aValues[:stdout]
	@stdin = aValues[:stdin]
	@stderr = aValues[:stderr]
	@key_chain = aValues[:key_chain]
	@credentials = aValues[:credentials]
	@logger = aValues[:logger]
	@variant = aValues[:variant]
end

Instance Attribute Details

#argvObject (readonly)

Returns the value of attribute argv.



4
5
6
# File 'lib/rigup/context.rb', line 4

def argv
  @argv
end

#configObject (readonly)

Returns the value of attribute config.



4
5
6
# File 'lib/rigup/context.rb', line 4

def config
  @config
end

#credentialsObject (readonly)

Returns the value of attribute credentials.



4
5
6
# File 'lib/rigup/context.rb', line 4

def credentials
  @credentials
end

#envObject (readonly)

Returns the value of attribute env.



4
5
6
# File 'lib/rigup/context.rb', line 4

def env
  @env
end

#key_chainObject (readonly)

Returns the value of attribute key_chain.



4
5
6
# File 'lib/rigup/context.rb', line 4

def key_chain
  @key_chain
end

#loggerObject (readonly)

Returns the value of attribute logger.



4
5
6
# File 'lib/rigup/context.rb', line 4

def logger
  @logger
end

#optionsObject (readonly)

Returns the value of attribute options.



4
5
6
# File 'lib/rigup/context.rb', line 4

def options
  @options
end

#pwdObject

Returns the value of attribute pwd.



4
5
6
# File 'lib/rigup/context.rb', line 4

def pwd
  @pwd
end

#stderrObject (readonly)

Returns the value of attribute stderr.



4
5
6
# File 'lib/rigup/context.rb', line 4

def stderr
  @stderr
end

#stdinObject (readonly)

Returns the value of attribute stdin.



4
5
6
# File 'lib/rigup/context.rb', line 4

def stdin
  @stdin
end

#stdoutObject (readonly)

Returns the value of attribute stdout.



4
5
6
# File 'lib/rigup/context.rb', line 4

def stdout
  @stdout
end

#variantObject (readonly)

Returns the value of attribute variant.



4
5
6
# File 'lib/rigup/context.rb', line 4

def variant
  @variant
end

Instance Method Details

#capture_stdoutObject

thinkingdigitally.com/archive/capturing-output-from-puts-in-ruby/ class SimpleSemParserTest < Test::Unit::TestCase

def test_set_stmt_write
  out = capture_stdout do
    parser = SimpleSemParser.new
    parser.parse('set write, "Hello World!"').execute
  end
  assert_equal "Hello World!\n", out.string
end

end



39
40
41
42
43
44
45
46
47
# File 'lib/rigup/context.rb', line 39

def capture_stdout
			stdout_before = @stdout
			out = StringIO.new
  @stdout = out
  yield
  return out.string
ensure
  @stdout = stdout_before
end

#find_git_rootObject



49
50
51
52
# File 'lib/rigup/context.rb', line 49

def find_git_root
	git_folder = BuzzTools::File.find_upwards(@pwd,'.git')
	return git_folder && git_folder.chomp('/.git')
end

#git_rootObject



25
26
27
# File 'lib/rigup/context.rb', line 25

def git_root
	@git_root ||= find_git_root
end