Class: Kontena::Cli::Stacks::StackName
- Inherits:
-
Object
- Object
- Kontena::Cli::Stacks::StackName
- Defined in:
- lib/kontena/cli/stacks/stack_name.rb
Instance Attribute Summary collapse
-
#stack ⇒ Object
readonly
A class for parsing stack name strings, such as kontena/foo:1.0.0.
-
#user ⇒ Object
readonly
A class for parsing stack name strings, such as kontena/foo:1.0.0.
-
#version ⇒ Object
readonly
A class for parsing stack name strings, such as kontena/foo:1.0.0.
Instance Method Summary collapse
- #initialize(definition = nil, version = nil) ⇒ StackName constructor
-
#pre? ⇒ NilClass, ...
True when version is a prerelease.
-
#stack_name ⇒ String
Stack name without version.
-
#to_s ⇒ String
(also: #to_str)
Full stack name including version if present.
Constructor Details
#initialize(definition = nil, version = nil) ⇒ StackName
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/kontena/cli/stacks/stack_name.rb', line 19 def initialize(definition = nil, version = nil) if definition.kind_of?(Hash) @user = definition[:user] || definition['user'] @stack = definition[:stack] || definition['stack'] @version = definition[:version] || definition['version'] || version elsif definition.kind_of?(String) parsed = parse(definition) @user = parsed[:user] @stack = parsed[:stack] @version = parsed[:version] || version end end |
Instance Attribute Details
#stack ⇒ Object (readonly)
A class for parsing stack name strings, such as kontena/foo:1.0.0
7 8 9 |
# File 'lib/kontena/cli/stacks/stack_name.rb', line 7 def stack @stack end |
#user ⇒ Object (readonly)
A class for parsing stack name strings, such as kontena/foo:1.0.0
7 8 9 |
# File 'lib/kontena/cli/stacks/stack_name.rb', line 7 def user @user end |
#version ⇒ Object (readonly)
A class for parsing stack name strings, such as kontena/foo:1.0.0
7 8 9 |
# File 'lib/kontena/cli/stacks/stack_name.rb', line 7 def version @version end |
Instance Method Details
#pre? ⇒ NilClass, ...
True when version is a prerelease
47 48 49 50 |
# File 'lib/kontena/cli/stacks/stack_name.rb', line 47 def pre? return nil if version.nil? !Semantic::Version.new(version).pre.nil? end |
#stack_name ⇒ String
Stack name without version
34 35 36 |
# File 'lib/kontena/cli/stacks/stack_name.rb', line 34 def stack_name [user, stack].compact.join('/') end |
#to_s ⇒ String Also known as: to_str
Full stack name including version if present
40 41 42 |
# File 'lib/kontena/cli/stacks/stack_name.rb', line 40 def to_s version ? "#{stack_name}:#{version}" : stack_name end |