Class: NeetoDeploy::CLI::Env::Set

Inherits:
Base
  • Object
show all
Includes:
Constants, Session
Defined in:
lib/neeto_deploy/cli/env/set.rb

Constant Summary

Constants included from Constants

Constants::NEETO_DEPLOY_CLI_API_ENVIRONMENT_VARIABLES_URL

Instance Attribute Summary collapse

Attributes inherited from Base

#ui

Instance Method Summary collapse

Methods included from Session

#common_body, require_app_option, #send_delete_request, #send_get_request, #send_patch_request, #send_post_request

Methods included from Constants

#environment_variables_url

Methods inherited from Base

#create_config_dir

Constructor Details

#initialize(environment_variables_string_array, options:) ⇒ Set

Returns a new instance of Set.



18
19
20
21
22
23
24
25
# File 'lib/neeto_deploy/cli/env/set.rb', line 18

def initialize(environment_variables_string_array, options:)
  super()
  @app_slug = options[:app]
  @environment_variables = environment_variables_string_array.map do |environment_variable|
    key, value = environment_variable.split("=")
    { key:, value: }
  end
end

Instance Attribute Details

#app_slugObject (readonly)

Returns the value of attribute app_slug.



16
17
18
# File 'lib/neeto_deploy/cli/env/set.rb', line 16

def app_slug
  @app_slug
end

#environment_variablesObject (readonly)

Returns the value of attribute environment_variables.



16
17
18
# File 'lib/neeto_deploy/cli/env/set.rb', line 16

def environment_variables
  @environment_variables
end

Instance Method Details

#runObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/neeto_deploy/cli/env/set.rb', line 27

def run
  table = Terminal::Table.new(
    headings: table_columns,
    rows: environment_variables.map { |environment_variable|
      [environment_variable[:key], environment_variable[:value]]
    }
  )
  ui.info(table)

  ui.info("Setting environment variables and restarting app...")

  response = send_post_request(
    environment_variables_url, {
      app_slug:,
      environment_variables:
    }
  )

  ui.error(response) and return unless response.success?

  ui.success("Done")
end