Class: CloudShell::Context

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#hereObject (readonly)

Returns the value of attribute here.



71
72
73
# File 'lib/cloud_shell.rb', line 71

def here
  @here
end

#parent_contextObject (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_sObject



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