Class: PromptCanary::Dashboard::PromptsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/prompt_canary/dashboard/prompts_controller.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#promptObject (readonly)

Returns the value of attribute prompt.



6
7
8
# File 'app/controllers/prompt_canary/dashboard/prompts_controller.rb', line 6

def prompt
  @prompt
end

#promptsObject (readonly)

Returns the value of attribute prompts.



6
7
8
# File 'app/controllers/prompt_canary/dashboard/prompts_controller.rb', line 6

def prompts
  @prompts
end

Instance Method Details

#indexObject



8
9
10
# File 'app/controllers/prompt_canary/dashboard/prompts_controller.rb', line 8

def index
  @prompts = PromptCanary.registered_prompts.map { |klass| build_prompt_data(klass) }
end

#promoteObject



19
20
21
22
23
24
25
# File 'app/controllers/prompt_canary/dashboard/prompts_controller.rb', line 19

def promote
  klass = PromptCanary.registered_prompts.find { |k| k.name == params[:name] }
  head(:not_found) && return unless klass

  PromptCanary.promote(klass, params[:version])
  redirect_to prompt_path(params[:name])
end

#showObject



12
13
14
15
16
17
# File 'app/controllers/prompt_canary/dashboard/prompts_controller.rb', line 12

def show
  klass = PromptCanary.registered_prompts.find { |k| k.name == params[:name] }
  head(:not_found) && return unless klass

  @prompt = build_prompt_data(klass).merge(events: fetch_events(klass.name))
end