Class: R10K::Environment::Name Private

Inherits:
Object
  • Object
show all
Defined in:
lib/r10k/environment/name.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Handle environment name validation and modification.

Constant Summary collapse

INVALID_CHARACTERS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

%r[\W]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, opts) ⇒ Name

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Name.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/r10k/environment/name.rb', line 14

def initialize(name, opts)
  @source  = opts[:source]
  @prefix  = opts[:prefix]
  @invalid = opts[:invalid]

  @name = derive_name(name, opts[:strip_component])
  @opts = opts

  case @invalid
  when 'correct_and_warn'
    @validate = true
    @correct  = true
  when 'correct'
    @validate = false
    @correct  = true
  when 'error'
    @validate = true
    @correct  = false
  when NilClass
    @validate = opts[:validate]
    @correct = opts[:correct]
  end
end

Instance Attribute Details

#nameObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



10
11
12
# File 'lib/r10k/environment/name.rb', line 10

def name
  @name
end

Instance Method Details

#correct?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Should the environment name have invalid characters removed?

Returns:

  • (Boolean)


39
40
41
# File 'lib/r10k/environment/name.rb', line 39

def correct?
  @correct
end

#dirnameString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The directory name for the environment, modified as necessary to remove invalid characters.

Returns:

  • (String)


59
60
61
62
63
64
65
66
67
68
69
# File 'lib/r10k/environment/name.rb', line 59

def dirname
  dir = @name.dup

  prefix = derive_prefix(@source,@prefix)

  if @correct
    dir.gsub!(INVALID_CHARACTERS, '_')
  end

  "#{prefix}#{dir}"
end

#valid?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


47
48
49
50
51
52
53
# File 'lib/r10k/environment/name.rb', line 47

def valid?
  if @validate
    ! @name.match(INVALID_CHARACTERS)
  else
    true
  end
end

#validate?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


43
44
45
# File 'lib/r10k/environment/name.rb', line 43

def validate?
  @validate
end