Class: Rigup::Context
- Inherits:
-
Object
- Object
- Rigup::Context
- Defined in:
- lib/rigup/context.rb
Instance Attribute Summary collapse
-
#argv ⇒ Object
readonly
Returns the value of attribute argv.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#credentials ⇒ Object
readonly
Returns the value of attribute credentials.
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#key_chain ⇒ Object
readonly
Returns the value of attribute key_chain.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#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.
-
#variant ⇒ Object
readonly
Returns the value of attribute variant.
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
- #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 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
#argv ⇒ Object (readonly)
Returns the value of attribute argv.
4 5 6 |
# File 'lib/rigup/context.rb', line 4 def argv @argv end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
4 5 6 |
# File 'lib/rigup/context.rb', line 4 def config @config end |
#credentials ⇒ Object (readonly)
Returns the value of attribute credentials.
4 5 6 |
# File 'lib/rigup/context.rb', line 4 def credentials @credentials end |
#env ⇒ Object (readonly)
Returns the value of attribute env.
4 5 6 |
# File 'lib/rigup/context.rb', line 4 def env @env end |
#key_chain ⇒ Object (readonly)
Returns the value of attribute key_chain.
4 5 6 |
# File 'lib/rigup/context.rb', line 4 def key_chain @key_chain end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
4 5 6 |
# File 'lib/rigup/context.rb', line 4 def logger @logger end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
4 5 6 |
# File 'lib/rigup/context.rb', line 4 def @options end |
#pwd ⇒ Object
Returns the value of attribute pwd.
4 5 6 |
# File 'lib/rigup/context.rb', line 4 def pwd @pwd end |
#stderr ⇒ Object (readonly)
Returns the value of attribute stderr.
4 5 6 |
# File 'lib/rigup/context.rb', line 4 def stderr @stderr end |
#stdin ⇒ Object (readonly)
Returns the value of attribute stdin.
4 5 6 |
# File 'lib/rigup/context.rb', line 4 def stdin @stdin end |
#stdout ⇒ Object (readonly)
Returns the value of attribute stdout.
4 5 6 |
# File 'lib/rigup/context.rb', line 4 def stdout @stdout end |
#variant ⇒ Object (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_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
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_root ⇒ Object
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_root ⇒ Object
25 26 27 |
# File 'lib/rigup/context.rb', line 25 def git_root @git_root ||= find_git_root end |