Class: Profiler::Api::ConsoleController

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

Instance Method Summary collapse

Instance Method Details

#clearObject



40
41
42
43
# File 'app/controllers/profiler/api/console_controller.rb', line 40

def clear
  Profiler.storage.clear(type: "console")
  head :no_content
end

#destroyObject



32
33
34
35
36
37
38
# File 'app/controllers/profiler/api/console_controller.rb', line 32

def destroy
  profile = Profiler.storage.load(params[:id])
  return render json: { error: "Console profile not found" }, status: :not_found unless profile&.profile_type == "console"

  Profiler.storage.delete(params[:id])
  head :no_content
end

#indexObject



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/controllers/profiler/api/console_controller.rb', line 8

def index
  limit  = (params[:limit]  || 50).to_i
  offset = (params[:offset] || 0).to_i
  all    = Profiler.storage.list(limit: 1000, offset: 0)
  console = all.select { |p| p.profile_type == "console" }
  page   = console.drop(offset).first(limit + 1)
  render json: {
    profiles: page.first(limit).map(&:to_h),
    limit:    limit,
    offset:   offset,
    has_more: page.size > limit
  }
end

#showObject



22
23
24
25
26
27
28
29
30
# File 'app/controllers/profiler/api/console_controller.rb', line 22

def show
  profile = Profiler.storage.load(params[:id])

  unless profile && profile.profile_type == "console"
    return render json: { error: "Console profile not found" }, status: :not_found
  end

  render json: profile.to_h
end