Class: KBSecret::Record::Environment

Inherits:
Abstract
  • Object
show all
Defined in:
lib/kbsecret/record/environment.rb

Overview

Represents a record containing an environment variable and value.

Instance Attribute Summary collapse

Attributes inherited from Abstract

#data, #label, #path, #session, #timestamp, #type

Instance Method Summary collapse

Methods inherited from Abstract

data_field, data_fields, #data_fields, #defer_sync, #external_fields, external_fields, gen_methods, #initialize, #initialize_from_hash, internal?, #internal?, load!, sensitive?, #sensitive?, #sync!, #to_h, #to_s, type

Constructor Details

This class inherits a constructor from KBSecret::Record::Abstract

Instance Attribute Details

#valueString

Returns the value of the environment value.

Returns:

  • (String)

    the value of the environment value



13
# File 'lib/kbsecret/record/environment.rb', line 13

data_field :variable, sensitive: false

#variableString

Returns the environment variable.

Returns:

  • (String)

    the environment variable



13
# File 'lib/kbsecret/record/environment.rb', line 13

data_field :variable, sensitive: false

Instance Method Details

#load!void

This method returns an undefined value.

Load this record's environment variable into the environment of the current process.



37
38
39
# File 'lib/kbsecret/record/environment.rb', line 37

def load!
  ENV[variable] = value
end

#populate_internal_fieldsvoid

This method returns an undefined value.



18
19
20
21
22
23
# File 'lib/kbsecret/record/environment.rb', line 18

def populate_internal_fields
  defer_sync implicit: false do
    self.variable = variable.shellescape
    self.value = value.shellescape
  end
end

#to_assignmentString

Returns a sh-style environment assignment.

Returns:

  • (String)

    a sh-style environment assignment



26
27
28
# File 'lib/kbsecret/record/environment.rb', line 26

def to_assignment
  "#{variable}=#{value}"
end

#to_exportString

Returns a sh-style environment export line.

Returns:

  • (String)

    a sh-style environment export line



31
32
33
# File 'lib/kbsecret/record/environment.rb', line 31

def to_export
  "export #{to_assignment}"
end