Class: LinearToonMcp::Tools::Create
- Defined in:
- lib/linear_toon_mcp/tools/create.rb
Overview
Base class for create-mutation tools. Submits the MUTATION constant, asserts the success flag, and returns the created entity. The mutation field and entity key derive from the class name:
CreateIssue.mutation_name # => "issueCreate"
CreateIssue.entity_name # => "issue"
CreateComment.mutation_name # => "commentCreate"
Subclasses define the MUTATION constant and override #variables to construct the GraphQL input.
Direct Known Subclasses
Class Method Summary collapse
-
.entity(name) ⇒ Object
Overrides the derived payload entity field name.
-
.entity_label ⇒ Object
Returns the entity label for error messages.
-
.entity_name ⇒ Object
Returns the entity field name inside the mutation payload.
-
.label(name) ⇒ Object
Overrides the derived entity label used in error messages.
-
.mutation(name) ⇒ Object
Overrides the derived GraphQL mutation field name.
-
.mutation_name ⇒ Object
Returns the GraphQL mutation field name.
-
.mutation_string ⇒ Object
Returns the GraphQL mutation — the
MUTATIONconstant on the subclass.
Instance Method Summary collapse
-
#perform(**params) ⇒ Object
Submits Create.mutation_string with #variables, validates the
successflag, and returns the created entity. -
#variables ⇒ Object
Subclass hook.
Methods inherited from Base
call, #call, error_response, success_response
Class Method Details
.entity(name) ⇒ Object
Overrides the derived payload entity field name.
24 25 26 |
# File 'lib/linear_toon_mcp/tools/create.rb', line 24 def entity(name) @entity_name = name.to_s end |
.entity_label ⇒ Object
Returns the entity label for error messages.
CreateIssue.entity_label # => "Issue"
46 47 48 |
# File 'lib/linear_toon_mcp/tools/create.rb', line 46 def entity_label @entity_label ||= name.split("::").last.sub(/\ACreate/, "") end |
.entity_name ⇒ Object
Returns the entity field name inside the mutation payload.
39 40 41 |
# File 'lib/linear_toon_mcp/tools/create.rb', line 39 def entity_name @entity_name ||= derive_entity_name end |
.label(name) ⇒ Object
Overrides the derived entity label used in error messages.
29 30 31 |
# File 'lib/linear_toon_mcp/tools/create.rb', line 29 def label(name) @entity_label = name.to_s end |
.mutation(name) ⇒ Object
Overrides the derived GraphQL mutation field name.
19 20 21 |
# File 'lib/linear_toon_mcp/tools/create.rb', line 19 def mutation(name) @mutation_name = name.to_s end |
.mutation_name ⇒ Object
Returns the GraphQL mutation field name.
34 35 36 |
# File 'lib/linear_toon_mcp/tools/create.rb', line 34 def mutation_name @mutation_name ||= "#{entity_name}Create" end |
.mutation_string ⇒ Object
Returns the GraphQL mutation — the MUTATION constant on the subclass.
52 53 54 |
# File 'lib/linear_toon_mcp/tools/create.rb', line 52 def mutation_string const_get(:MUTATION) end |
Instance Method Details
#perform(**params) ⇒ Object
Submits mutation_string with #variables, validates the success flag, and returns the created entity.
68 69 70 71 72 73 74 |
# File 'lib/linear_toon_mcp/tools/create.rb', line 68 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} creation failed: no result returned" raise Error, "#{self.class.entity_label} creation failed" unless result["success"] result[self.class.entity_name] end |
#variables ⇒ Object
Subclass hook. Returns the GraphQL variables hash for the mutation. Subclasses must implement.
78 79 80 |
# File 'lib/linear_toon_mcp/tools/create.rb', line 78 def variables(**) raise NotImplementedError, "#{self.class.name} must implement #variables" end |