Class: DesignShell::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/designshell/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
# File 'lib/designshell/context.rb', line 7

def initialize(aValues=nil)
	return if !aValues
	@global_options = aValues[:global_options]
	@options = aValues[:options]
	@pwd = MiscUtils.real_path(Dir.pwd)
	@argv = aValues[:argv]
	@env = aValues[:env]
	@stdout = aValues[:stdout]
	@stdin = aValues[:stdin]
	@stderr = aValues[:stderr]
	@credentials = aValues[:credentials]
	@key_chain = aValues[:key_chain]
end

Instance Attribute Details

#argvObject (readonly)

Returns the value of attribute argv.



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

def argv
  @argv
end

#credentialsObject (readonly)

Returns the value of attribute credentials.



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

def credentials
  @credentials
end

#envObject (readonly)

Returns the value of attribute env.



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

def env
  @env
end

#global_optionsObject (readonly)

Returns the value of attribute global_options.



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

def global_options
  @global_options
end

#key_chainObject (readonly)

Returns the value of attribute key_chain.



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

def key_chain
  @key_chain
end

#optionsObject (readonly)

Returns the value of attribute options.



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

def options
  @options
end

#pwdObject

Returns the value of attribute pwd.



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

def pwd
  @pwd
end

#stderrObject (readonly)

Returns the value of attribute stderr.



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

def stderr
  @stderr
end

#stdinObject (readonly)

Returns the value of attribute stdin.



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

def stdin
  @stdin
end

#stdoutObject (readonly)

Returns the value of attribute stdout.



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

def stdout
  @stdout
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



31
32
33
34
35
36
37
38
39
# File 'lib/designshell/context.rb', line 31

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

#find_git_rootObject



41
42
43
44
# File 'lib/designshell/context.rb', line 41

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