Class: Seira::Config

Inherits:
Object
  • Object
show all
Includes:
Commands
Defined in:
lib/seira/config.rb

Constant Summary collapse

VALID_ACTIONS =
%w[help get set unset list].freeze
SUMMARY =
"Manage your application's environment variables configuration".freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Commands

#gcloud, gcloud, kubectl, #kubectl, #tsh, tsh

Constructor Details

#initialize(app:, action:, args:, context:) ⇒ Config

Returns a new instance of Config.



17
18
19
20
21
22
# File 'lib/seira/config.rb', line 17

def initialize(app:, action:, args:, context:)
  @app = app
  @action = action
  @args = args
  @context = context
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



15
16
17
# File 'lib/seira/config.rb', line 15

def action
  @action
end

#appObject (readonly)

Returns the value of attribute app.



15
16
17
# File 'lib/seira/config.rb', line 15

def app
  @app
end

#argsObject (readonly)

Returns the value of attribute args.



15
16
17
# File 'lib/seira/config.rb', line 15

def args
  @args
end

#contextObject (readonly)

Returns the value of attribute context.



15
16
17
# File 'lib/seira/config.rb', line 15

def context
  @context
end

Instance Method Details

#get(key) ⇒ Object



48
49
50
51
52
# File 'lib/seira/config.rb', line 48

def get(key)
  config = fetch_current_config
  value = config.dig('data', key)
  value.nil? ? nil : value
end

#main_config_nameObject



44
45
46
# File 'lib/seira/config.rb', line 44

def main_config_name
  "#{app}-env-config"
end

#runObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/seira/config.rb', line 24

def run
  case action
  when 'help'
    run_help
  when 'get'
    validate_single_key
    run_get
  when 'set'
    validate_keys_and_values
    run_set
  when 'unset'
    validate_single_key
    run_unset
  when 'list'
    run_list
  else
    fail "Unknown command encountered"
  end
end