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

Attributes inherited from Abstract

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

Instance Method Summary collapse

Methods inherited from Abstract

data_field, data_fields, gen_methods, #initialize_from_hash, load!, #sync!, #to_h, #to_s, type

Constructor Details

#initialize(session, label, variable, value) ⇒ Environment

Returns a new instance of Environment.

Parameters:

  • session (Session)

    the session to associate with

  • label (Symbol)

    the new record's label

  • variable (String)

    the new record's variable

  • value (String)

    the new record's value



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

def initialize(session, label, variable, value)
  super(session, label)

  @data = {
    environment: {
      variable: variable.shellescape,
      value: value.shellescape,
    },
  }
end

Instance Method Details

#to_assignmentString

Returns a sh-style environment assignment.

Returns:

  • (String)

    a sh-style environment assignment



28
29
30
# File 'lib/kbsecret/record/environment.rb', line 28

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

#to_exportString

Returns a sh-style environment export line.

Returns:

  • (String)

    a sh-style environment export line



33
34
35
# File 'lib/kbsecret/record/environment.rb', line 33

def to_export
  "export #{to_assignment}"
end