Class: Rubino::API::Operations::Skills::ToggleOperation

Inherits:
Object
  • Object
show all
Defined in:
lib/rubino/api/operations/skills/toggle_operation.rb

Overview

PUT /v1/skills/:name Persists the enable/disable flag for a single registered skill.

Raises:

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(registry: nil, state_repository: nil) ⇒ ToggleOperation

Accepts an alternate skills registry and state repository for tests.



18
19
20
21
# File 'lib/rubino/api/operations/skills/toggle_operation.rb', line 18

def initialize(registry: nil, state_repository: nil)
  @registry = registry || ::Rubino::Skills::Registry.new
  @state_repository = state_repository || ::Rubino::Skills::StateRepository.new
end

Class Method Details

.call(request) ⇒ Object



13
14
15
# File 'lib/rubino/api/operations/skills/toggle_operation.rb', line 13

def self.call(request)
  new.call(request)
end

Instance Method Details

#call(request) ⇒ Object

Raises:



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/rubino/api/operations/skills/toggle_operation.rb', line 23

def call(request)
  name = request.params.fetch("name")
  raise NotFoundError.new("skill", name) unless @registry.find(name)

  attrs = request.validate!(Schemas::ToggleSkill)
  # The shared toggle write path (Skills::Toggle, #188) — the same
  # registry-validated StateRepository write the in-chat
  # `/skills enable|disable` and the `rubino skills` CLI verbs run.
  ::Rubino::Skills::Toggle.set(name, enabled: attrs[:enabled],
                                     registry: @registry,
                                     state_repository: @state_repository)
  [200, { name: name, enabled: attrs[:enabled] }]
end