Class: Meroku::ConfigsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
lib/meroku/configs_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/meroku/configs_controller.rb', line 15

def create
  @config = Meroku::Config.where(name: params["name"], app_id: @app_.id).try(:first)
  if @config
    # if variable exists, update its value
    @config.update_attributes(value: params["value"])
  else      
    # if it doesn't exist, create record      
    @config = Meroku::Config.new(
      name: params["name"],
      value: params["value"],
      app_id: @app_.id
    )
  end
  respond_to do |format|
    if @config.save
      format.json { render json: {  data: @config  } }
    else
      format.json { render json: { :errors => @config.errors }, status: :unprocessable_entity }
    end
  end
end

#destroyObject

DELETE /keys/1 DELETE /keys/1.json



53
54
55
56
57
58
59
# File 'lib/meroku/configs_controller.rb', line 53

def destroy
  @config = Meroku::Config.find_by_name(params["name"])
  @config.destroy
  respond_to do |format|
    format.json { render json: {  data: @config  } }
  end
end

#indexObject



8
9
10
11
12
13
# File 'lib/meroku/configs_controller.rb', line 8

def index
  configs = Meroku::App.last.configs.map { |x| "#{x.name}: #{x.value || 'nil'}" }.join("\n")
  render json: {
    "data": "#{configs}\n"
  }
end