Class: Subflag::Rails::FlagsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/subflag/rails/flags_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



18
19
20
21
22
23
24
25
# File 'app/controllers/subflag/rails/flags_controller.rb', line 18

def create
  @flag = Flag.new(flag_params)
  if @flag.save
    redirect_to flags_path, notice: "Flag created."
  else
    render :new, status: :unprocessable_entity
  end
end

#destroyObject



37
38
39
40
# File 'app/controllers/subflag/rails/flags_controller.rb', line 37

def destroy
  @flag.destroy
  redirect_to flags_path, notice: "Flag deleted."
end

#editObject



27
# File 'app/controllers/subflag/rails/flags_controller.rb', line 27

def edit; end

#indexObject



8
9
10
# File 'app/controllers/subflag/rails/flags_controller.rb', line 8

def index
  @flags = Flag.order(:key)
end

#newObject



14
15
16
# File 'app/controllers/subflag/rails/flags_controller.rb', line 14

def new
  @flag = Flag.new(enabled: true, value_type: "boolean", value: "false")
end

#showObject



12
# File 'app/controllers/subflag/rails/flags_controller.rb', line 12

def show; end

#testObject



47
48
49
50
51
52
53
54
55
56
# File 'app/controllers/subflag/rails/flags_controller.rb', line 47

def test
  context = parse_test_context(params[:context])
  @test_result = @flag.evaluate(context: context)
  @test_context = context

  respond_to do |format|
    format.html { render :edit }
    format.json { render json: { result: @test_result, context: @test_context } }
  end
end

#toggleObject



42
43
44
45
# File 'app/controllers/subflag/rails/flags_controller.rb', line 42

def toggle
  @flag.update!(enabled: !@flag.enabled)
  redirect_to flags_path, notice: "Flag #{@flag.enabled? ? 'enabled' : 'disabled'}."
end

#updateObject



29
30
31
32
33
34
35
# File 'app/controllers/subflag/rails/flags_controller.rb', line 29

def update
  if @flag.update(flag_params)
    redirect_to edit_flag_path(@flag), notice: "Flag updated."
  else
    render :edit, status: :unprocessable_entity
  end
end