Class: LinearToonMcp::Tools::Get
- Defined in:
- lib/linear_toon_mcp/tools/get.rb
Overview
Base class for single-entity read tools. Queries by id and extracts the named entity field; raises a labeled not-found error when the field is nil. The entity field name derives from the class name:
GetIssue.entity_name # => "issue"
GetProject.entity_name # => "project"
Subclasses define the QUERY constant and override #variables when the lookup key needs resolving first (e.g., name/slug → UUID).
Direct Known Subclasses
GetInitiative, GetIssue, GetIssueStatus, GetProject, GetTeam, GetUser
Class Method Summary collapse
-
.entity(name) ⇒ Object
Overrides the derived GraphQL entity field name.
-
.entity_label ⇒ Object
Returns the entity label for not-found messages.
-
.entity_name ⇒ Object
Returns the GraphQL entity field name.
-
.query_string ⇒ Object
Returns the GraphQL query — the
QUERYconstant on the subclass.
Instance Method Summary collapse
-
#not_found_message(id: nil) ⇒ Object
Subclass hook.
-
#perform(**params) ⇒ Object
Queries Get.query_string with #variables and extracts the entity field.
-
#variables(id:) ⇒ Object
Subclass hook.
Methods inherited from Base
call, #call, error_response, success_response
Class Method Details
.entity(name) ⇒ Object
Overrides the derived GraphQL entity field name.
18 19 20 |
# File 'lib/linear_toon_mcp/tools/get.rb', line 18 def entity(name) @entity = name.to_s end |
.entity_label ⇒ Object
Returns the entity label for not-found messages.
GetIssue.entity_label # => "Issue"
30 31 32 |
# File 'lib/linear_toon_mcp/tools/get.rb', line 30 def entity_label @entity_label ||= name.split("::").last.sub(/\AGet/, "") end |
.entity_name ⇒ Object
Returns the GraphQL entity field name.
23 24 25 |
# File 'lib/linear_toon_mcp/tools/get.rb', line 23 def entity_name @entity ||= derive_entity_name end |
.query_string ⇒ Object
Returns the GraphQL query — the QUERY constant on the subclass.
35 36 37 |
# File 'lib/linear_toon_mcp/tools/get.rb', line 35 def query_string const_get(:QUERY) end |
Instance Method Details
#not_found_message(id: nil) ⇒ Object
Subclass hook. Returns the not-found error message.
64 65 66 |
# File 'lib/linear_toon_mcp/tools/get.rb', line 64 def (id: nil, **) "#{self.class.entity_label} not found: #{id}" end |
#perform(**params) ⇒ Object
Queries query_string with #variables and extracts the entity field.
51 52 53 54 |
# File 'lib/linear_toon_mcp/tools/get.rb', line 51 def perform(**params) data = client.query(self.class.query_string, variables: variables(**params)) data[self.class.entity_name] or raise Error, (**params) end |
#variables(id:) ⇒ Object
Subclass hook. Returns the GraphQL variables hash for #perform. Defaults to {id: id}; override when the lookup key needs resolving first (e.g., name/slug → UUID).
59 60 61 |
# File 'lib/linear_toon_mcp/tools/get.rb', line 59 def variables(id:, **) {id: id} end |