Class: Etcher::Transformers::Format
- Inherits:
-
Object
- Object
- Etcher::Transformers::Format
- Defined in:
- lib/etcher/transformers/format.rb
Overview
Formats given key using existing and/or placeholder attributes.
Instance Method Summary collapse
- #call(attributes) ⇒ Object
-
#initialize(key, *retainers, **mappings) ⇒ Format
constructor
A new instance of Format.
Constructor Details
#initialize(key, *retainers, **mappings) ⇒ Format
Returns a new instance of Format.
11 12 13 14 15 16 |
# File 'lib/etcher/transformers/format.rb', line 11 def initialize key, *retainers, **mappings @key = key @retainers = retainers @mappings = mappings @pattern = /%<.+>s/o end |
Instance Method Details
#call(attributes) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/etcher/transformers/format.rb', line 18 def call attributes value = attributes[key] return Success attributes unless value && value.match?(pattern) Success attributes.merge!(key => format(value, **attributes, **pass_throughs)) rescue KeyError => error Failure step: :transform, constant: self.class, payload: "Unable to transform #{key.inspect}, missing specifier: " \ "\"#{error.[/<.+>/]}\"." end |