Class: Kontena::Plugin::Shell::Context
- Inherits:
-
Object
- Object
- Kontena::Plugin::Shell::Context
- Defined in:
- lib/kontena/plugin/shell/context.rb
Instance Attribute Summary collapse
-
#context ⇒ Object
Returns the value of attribute context.
Instance Method Summary collapse
- #+(arr) ⇒ Object
- #<<(token) ⇒ Object
- #concat(tokens) ⇒ Object
- #empty? ⇒ Boolean
- #first ⇒ Object
-
#initialize(context) ⇒ Context
constructor
A new instance of Context.
- #normalize(context) ⇒ Object
- #to_a ⇒ Object
- #to_s ⇒ Object
- #top ⇒ Object
- #up ⇒ Object
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
#context ⇒ Object
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
28 29 30 |
# File 'lib/kontena/plugin/shell/context.rb', line 28 def empty? context.empty? end |
#first ⇒ Object
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_a ⇒ Object
50 51 52 |
# File 'lib/kontena/plugin/shell/context.rb', line 50 def to_a context end |
#to_s ⇒ Object
46 47 48 |
# File 'lib/kontena/plugin/shell/context.rb', line 46 def to_s context.join(' ') end |
#top ⇒ Object
15 16 17 |
# File 'lib/kontena/plugin/shell/context.rb', line 15 def top context.clear end |
#up ⇒ Object
11 12 13 |
# File 'lib/kontena/plugin/shell/context.rb', line 11 def up context.pop end |