Class: Etcher::Transformers::Time

Inherits:
Object
  • Object
show all
Defined in:
lib/etcher/transformers/time.rb

Overview

Conditionally transforms current time for key.

Instance Method Summary collapse

Constructor Details

#initialize(key = :loaded_at, fallback: ::Time.now.utc) ⇒ Time

Returns a new instance of Time.



11
12
13
14
# File 'lib/etcher/transformers/time.rb', line 11

def initialize key = :loaded_at, fallback: ::Time.now.utc
  @key = key
  @fallback = fallback
end

Instance Method Details

#call(attributes) ⇒ Object



16
17
18
19
# File 'lib/etcher/transformers/time.rb', line 16

def call attributes
  attributes.fetch(key) { fallback }
            .then { |value| Success attributes.merge!(key => value) }
end