Module: Nugrant::Helper::Env::Namer

Defined in:
lib/nugrant/helper/env/namer.rb

Overview

A namer is a lambda taking as argument an array of segments that should return a string representation of those segments. How the segments are transformed to a string is up to the namer. By using various namer, we can change how a bag key is transformed into and environment variable name. This is like the strategy pattern.

Class Method Summary collapse

Class Method Details

.default(char = "_") ⇒ Object

Returns the default namer, which join segments together using a character and upcase the result.

Parameters:

  • `char`

    The character used to join segments together, default to ‘“_”`.

Returns:

  • A lambda that will simply joins segment using the ‘char` argument and upcase the result.



23
24
25
26
27
# File 'lib/nugrant/helper/env/namer.rb', line 23

def self.default(char = "_")
  lambda do |segments|
    segments.join(char).upcase()
  end
end

.prefix(prefix, delegate_namer) ⇒ Object

Returns the prefix namer, which add a prefix to segments and delegate its work to another namer.

Parameters:

  • prefix

    The prefix to add to segments.

  • delegate_namer

    A namer that will be used to transform the prefixed segments.

Returns:

  • A lambda that will simply add prefix to segments and will call the delegate_namer with those new segments.



39
40
41
42
43
# File 'lib/nugrant/helper/env/namer.rb', line 39

def self.prefix(prefix, delegate_namer)
  lambda do |segments|
    delegate_namer.call([prefix] + segments)
  end
end