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
-
.default(char = "_") ⇒ Object
Returns the default namer, which join segments together using a character and upcase the result.
-
.prefix(prefix, delegate_namer) ⇒ Object
Returns the prefix namer, which add a prefix to segments and delegate its work to another namer.
Class Method Details
.default(char = "_") ⇒ Object
Returns the default namer, which join segments together using a character 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.
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 |