Class: Kontena::Cli::Stacks::StackName

Inherits:
Object
  • Object
show all
Defined in:
lib/kontena/cli/stacks/stack_name.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(definition = nil, version = nil) ⇒ StackName

Examples:

name = StackName.new('kontena/foo:0.1.0')
name.user => 'kontena'
name.stack => 'foo'
name.version => '0.1.0'
name.stack_name => 'kontena/foo'
name.to_s => 'kontena/foo:0.1.0

Parameters:

  • definition (String) (defaults to: nil)

    such as kontena/foo:1.0.0

  • version (String) (defaults to: nil)

    set version separately



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

#stackObject (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

#userObject (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

#versionObject (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

Returns:

  • (NilClass, TrueClass, FalseClass)

    nil when no version, true when prerelease, false when not.



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_nameString

Stack name without version

Returns:

  • (String)

    example: kontena/foo



34
35
36
# File 'lib/kontena/cli/stacks/stack_name.rb', line 34

def stack_name
  [user, stack].compact.join('/')
end

#to_sString Also known as: to_str

Full stack name including version if present

Returns:

  • (String)

    example: kontena/foo:0.1.0



40
41
42
# File 'lib/kontena/cli/stacks/stack_name.rb', line 40

def to_s
  version ? "#{stack_name}:#{version}" : stack_name
end