Class: Kontena::Plugin::Shell::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/kontena/plugin/shell/context.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context) ⇒ Context

Returns a new instance of Context.



7
8
9
# File 'lib/kontena/plugin/shell/context.rb', line 7

def initialize(context)
  @context = normalize(context)
end

Instance Attribute Details

#contextObject

Returns the value of attribute context.



5
6
7
# File 'lib/kontena/plugin/shell/context.rb', line 5

def context
  @context
end

Instance Method Details

#+(arr) ⇒ Object



54
55
56
# File 'lib/kontena/plugin/shell/context.rb', line 54

def +(arr)
  context + Array(arr)
end

#<<(token) ⇒ Object



24
25
26
# File 'lib/kontena/plugin/shell/context.rb', line 24

def <<(token)
  context << token
end

#concat(tokens) ⇒ Object



19
20
21
22
# File 'lib/kontena/plugin/shell/context.rb', line 19

def concat(tokens)
  arg_index = tokens.index { |a| a == '--' || a.start_with?('-') } || tokens.size
  context.concat(tokens[0..arg_index-1])
end

#empty?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/kontena/plugin/shell/context.rb', line 28

def empty?
  context.empty?
end

#firstObject



32
33
34
# File 'lib/kontena/plugin/shell/context.rb', line 32

def first
  context.first
end

#normalize(context) ⇒ Object



41
42
43
44
# File 'lib/kontena/plugin/shell/context.rb', line 41

def normalize(context)
  return [] if context.nil?
  context.kind_of?(String) ? context.shellsplit : context
end

#to_aObject



50
51
52
# File 'lib/kontena/plugin/shell/context.rb', line 50

def to_a
  context
end

#to_sObject



46
47
48
# File 'lib/kontena/plugin/shell/context.rb', line 46

def to_s
  context.join(' ')
end

#topObject



15
16
17
# File 'lib/kontena/plugin/shell/context.rb', line 15

def top
  context.clear
end

#upObject



11
12
13
# File 'lib/kontena/plugin/shell/context.rb', line 11

def up
  context.pop
end