Class: Brightbox::Config::SectionNameDeduplicator
- Inherits:
-
Object
- Object
- Brightbox::Config::SectionNameDeduplicator
- Defined in:
- lib/brightbox-cli/config/section_name_deduplicator.rb
Overview
The CLI config file is broken into sections, each with a unique name. When adding a new section as a conveinence if a name would clash instead of the original error we select a suitable alternative.
If the name is not in use then it is returned unchanged.
Instance Method Summary collapse
-
#initialize(name, in_use) ⇒ SectionNameDeduplicator
constructor
A new instance of SectionNameDeduplicator.
-
#next ⇒ String
Return the next name given those in use already.
Constructor Details
#initialize(name, in_use) ⇒ SectionNameDeduplicator
Returns a new instance of SectionNameDeduplicator.
13 14 15 16 |
# File 'lib/brightbox-cli/config/section_name_deduplicator.rb', line 13 def initialize(name, in_use) @name = name @in_use = in_use end |
Instance Method Details
#next ⇒ String
Return the next name given those in use already
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/brightbox-cli/config/section_name_deduplicator.rb', line 21 def next # Sanity check. If the name is not in use, offer it back if @in_use.include?(@name) @in_use.sort.select do |name| name == @name end "#{normalised_name}_#{next_suffix}" else @name end end |