Module: Nucleus::Adapters::V1::Heroku::Vars

Included in:
Nucleus::Adapters::V1::Heroku
Defined in:
lib/nucleus/adapters/v1/heroku/vars.rb

Instance Method Summary collapse

Instance Method Details

#create_env_var(application_id, env_var) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/nucleus/adapters/v1/heroku/vars.rb', line 26

def create_env_var(application_id, env_var)
  fail Errors::SemanticAdapterRequestError,
       "Env. var key '#{env_var[:key]}' already taken" if env_var?(application_id, env_var[:key])

  request_body = { env_var[:key] => env_var[:value] }
  all_vars = patch("/apps/#{application_id}/config-vars", body: request_body).body
  { id: env_var[:key], key: env_var[:key], value: all_vars[env_var[:key].to_sym] }
end

#delete_env_var(application_id, env_var_key) ⇒ Object



46
47
48
49
50
51
52
53
# File 'lib/nucleus/adapters/v1/heroku/vars.rb', line 46

def delete_env_var(application_id, env_var_key)
  fail Errors::AdapterResourceNotFoundError,
       "Env. var key '#{env_var_key}' does not exist" unless env_var?(application_id, env_var_key)

  # vars can be deleted by setting them to null / nil
  request_body = { env_var_key => nil }
  patch("/apps/#{application_id}/config-vars", body: request_body).body
end

#env_var(application_id, env_var_key) ⇒ Object

See Also:



17
18
19
20
21
22
23
# File 'lib/nucleus/adapters/v1/heroku/vars.rb', line 17

def env_var(application_id, env_var_key)
  all_vars = get("/apps/#{application_id}/config-vars").body
  fail Errors::AdapterResourceNotFoundError,
       "Env. var key '#{env_var_key}' does not exist" unless env_var?(application_id, env_var_key, all_vars)

  { id: env_var_key, key: env_var_key, value: all_vars[env_var_key.to_sym] }
end

#env_vars(application_id) ⇒ Object

See Also:



7
8
9
10
11
12
13
14
# File 'lib/nucleus/adapters/v1/heroku/vars.rb', line 7

def env_vars(application_id)
  all_vars = get("/apps/#{application_id}/config-vars").body
  formatted_vars = []
  all_vars.each do |key, value|
    formatted_vars.push(id: key, key: key, value: value)
  end
  formatted_vars
end

#update_env_var(application_id, env_var_key, env_var) ⇒ Object



36
37
38
39
40
41
42
43
# File 'lib/nucleus/adapters/v1/heroku/vars.rb', line 36

def update_env_var(application_id, env_var_key, env_var)
  fail Errors::AdapterResourceNotFoundError,
       "Env. var key '#{env_var_key}' does not exist" unless env_var?(application_id, env_var_key)

  request_body = { env_var_key => env_var[:value] }
  updated_vars = patch("/apps/#{application_id}/config-vars", body: request_body).body
  { id: env_var_key, key: env_var_key, value: updated_vars[env_var_key.to_sym] }
end