Class: CloudShell::Context
- Inherits:
-
Object
- Object
- CloudShell::Context
- Defined in:
- lib/cloud_shell.rb
Instance Attribute Summary collapse
-
#here ⇒ Object
readonly
Returns the value of attribute here.
-
#parent_context ⇒ Object
readonly
Returns the value of attribute parent_context.
Instance Method Summary collapse
- #cat(path) ⇒ Object
- #cd(path) ⇒ Object
- #completions(input) ⇒ Object
-
#initialize(here, parent_context) ⇒ Context
constructor
A new instance of Context.
- #to_s ⇒ Object
Constructor Details
#initialize(here, parent_context) ⇒ Context
Returns a new instance of Context.
74 75 76 77 |
# File 'lib/cloud_shell.rb', line 74 def initialize(here,parent_context) @here = here @parent_context = parent_context end |
Instance Attribute Details
#here ⇒ Object (readonly)
Returns the value of attribute here.
71 72 73 |
# File 'lib/cloud_shell.rb', line 71 def here @here end |
#parent_context ⇒ Object (readonly)
Returns the value of attribute parent_context.
72 73 74 |
# File 'lib/cloud_shell.rb', line 72 def parent_context @parent_context end |
Instance Method Details
#cat(path) ⇒ Object
83 84 85 |
# File 'lib/cloud_shell.rb', line 83 def cat(path) item_at(path) end |
#cd(path) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/cloud_shell.rb', line 87 def cd(path) if path == '..' self.parent_context else item = item_at(path) if item.nil? nil else Context.new(item,self) end end end |
#completions(input) ⇒ Object
79 80 81 |
# File 'lib/cloud_shell.rb', line 79 def completions(input) self.to_s.split(/\s+/).grep(/^#{input}/) end |
#to_s ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/cloud_shell.rb', line 100 def to_s if self.here.kind_of? Array indices = [] self.here.each_index { |i| indices << i } indices.join(' ') elsif self.here.kind_of? Hash self.here.keys.join(' ') else self.here.to_s end end |