Class: LinearToonMcp::Tools::Delete

Inherits:
Base
  • Object
show all
Defined in:
lib/linear_toon_mcp/tools/delete.rb

Overview

Base class for delete-mutation tools. Submits the MUTATION constant, asserts the success flag, and returns {“success” => true, “entityId” => …}. The mutation field derives from the class name:

DeleteInitiative.mutation_name  # => "initiativeDelete"

Subclasses define the MUTATION constant and override #variables to build the {id:} payload.

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

call, #call, error_response, success_response

Class Method Details

.entity(name) ⇒ Object

Overrides the derived entity label.



22
23
24
# File 'lib/linear_toon_mcp/tools/delete.rb', line 22

def entity(name)
  @entity_name = name.to_s
end

.entity_labelObject

Returns the entity label for error messages.

DeleteInitiative.entity_label  # => "Initiative"


44
45
46
# File 'lib/linear_toon_mcp/tools/delete.rb', line 44

def entity_label
  @entity_label ||= name.split("::").last.sub(/\ADelete/, "")
end

.entity_nameObject

Returns the entity name (used to derive entity_label).



37
38
39
# File 'lib/linear_toon_mcp/tools/delete.rb', line 37

def entity_name
  @entity_name ||= derive_entity_name
end

.label(name) ⇒ Object

Overrides the derived entity label used in error messages.



27
28
29
# File 'lib/linear_toon_mcp/tools/delete.rb', line 27

def label(name)
  @entity_label = name.to_s
end

.mutation(name) ⇒ Object

Overrides the derived GraphQL mutation field name.



17
18
19
# File 'lib/linear_toon_mcp/tools/delete.rb', line 17

def mutation(name)
  @mutation_name = name.to_s
end

.mutation_nameObject

Returns the GraphQL mutation field name.



32
33
34
# File 'lib/linear_toon_mcp/tools/delete.rb', line 32

def mutation_name
  @mutation_name ||= "#{entity_name}Delete"
end

.mutation_stringObject

Returns the GraphQL mutation — the MUTATION constant on the subclass.



49
50
51
# File 'lib/linear_toon_mcp/tools/delete.rb', line 49

def mutation_string
  const_get(:MUTATION)
end

Instance Method Details

#perform(**params) ⇒ Object

Submits mutation_string with #variables, validates the success flag, and returns {success: true, entityId: …}.

Raises:

  • (Error)

    when the mutation fails



65
66
67
68
69
70
71
# File 'lib/linear_toon_mcp/tools/delete.rb', line 65

def perform(**params)
  data = client.query(self.class.mutation_string, variables: variables(**params))
  result = data[self.class.mutation_name] or raise Error, "#{self.class.entity_label} deletion failed: no result returned"
  raise Error, "#{self.class.entity_label} deletion failed" unless result["success"]

  {"success" => true, "entityId" => result["entityId"]}
end

#variablesObject

Subclass hook. Returns the GraphQL {id:} hash for the mutation.

Raises:

  • (NotImplementedError)


74
75
76
# File 'lib/linear_toon_mcp/tools/delete.rb', line 74

def variables(**)
  raise NotImplementedError, "#{self.class.name} must implement #variables"
end