Class: Profiler::Api::EnvVarsController

Inherits:
Profiler::ApplicationController show all
Defined in:
app/controllers/profiler/api/env_vars_controller.rb

Instance Method Summary collapse

Instance Method Details

#showObject



8
9
10
11
# File 'app/controllers/profiler/api/env_vars_controller.rb', line 8

def show
  variables = ENV.to_h.sort.to_h
  render json: { variables: variables, total: variables.size }
end

#updateObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/controllers/profiler/api/env_vars_controller.rb', line 13

def update
  key = params[:key].to_s.strip

  if key.blank?
    render json: { error: "Key cannot be blank" }, status: :unprocessable_entity
    return
  end

  value = params[:value]

  if value.nil? || value.to_s.empty?
    ENV.delete(key)
    render json: { key: key, value: nil, deleted: true }
  else
    ENV[key] = value.to_s
    render json: { key: key, value: ENV[key] }
  end
end