Class: DesignShell::Context
- Inherits:
-
Object
- Object
- DesignShell::Context
- Defined in:
- lib/designshell/context.rb
Instance Attribute Summary collapse
-
#argv ⇒ Object
readonly
Returns the value of attribute argv.
-
#credentials ⇒ Object
readonly
Returns the value of attribute credentials.
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#global_options ⇒ Object
readonly
Returns the value of attribute global_options.
-
#key_chain ⇒ Object
readonly
Returns the value of attribute key_chain.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#pwd ⇒ Object
Returns the value of attribute pwd.
-
#stderr ⇒ Object
readonly
Returns the value of attribute stderr.
-
#stdin ⇒ Object
readonly
Returns the value of attribute stdin.
-
#stdout ⇒ Object
readonly
Returns the value of attribute stdout.
Instance Method Summary collapse
-
#capture_stdout ⇒ Object
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.
- #find_git_root ⇒ Object
-
#initialize(aValues = nil) ⇒ Context
constructor
A new instance of Context.
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
#argv ⇒ Object (readonly)
Returns the value of attribute argv.
4 5 6 |
# File 'lib/designshell/context.rb', line 4 def argv @argv end |
#credentials ⇒ Object (readonly)
Returns the value of attribute credentials.
4 5 6 |
# File 'lib/designshell/context.rb', line 4 def credentials @credentials end |
#env ⇒ Object (readonly)
Returns the value of attribute env.
4 5 6 |
# File 'lib/designshell/context.rb', line 4 def env @env end |
#global_options ⇒ Object (readonly)
Returns the value of attribute global_options.
4 5 6 |
# File 'lib/designshell/context.rb', line 4 def @global_options end |
#key_chain ⇒ Object (readonly)
Returns the value of attribute key_chain.
4 5 6 |
# File 'lib/designshell/context.rb', line 4 def key_chain @key_chain end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
4 5 6 |
# File 'lib/designshell/context.rb', line 4 def @options end |
#pwd ⇒ Object
Returns the value of attribute pwd.
4 5 6 |
# File 'lib/designshell/context.rb', line 4 def pwd @pwd end |
#stderr ⇒ Object (readonly)
Returns the value of attribute stderr.
4 5 6 |
# File 'lib/designshell/context.rb', line 4 def stderr @stderr end |
#stdin ⇒ Object (readonly)
Returns the value of attribute stdin.
4 5 6 |
# File 'lib/designshell/context.rb', line 4 def stdin @stdin end |
#stdout ⇒ Object (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_stdout ⇒ Object
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_root ⇒ Object
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 |