Class: Spree::AgentTools::DescribeResource
- Inherits:
-
Spree::AgentTool
- Object
- Spree::AgentTool
- Spree::AgentTools::DescribeResource
- Defined in:
- app/tools/spree/agent_tools/describe_resource.rb
Overview
Tells the model which resources exist and what they can be filtered by, so it discovers the real vocabulary instead of guessing field names and producing errors the merchant has to read.
Constant Summary
Constants inherited from Spree::AgentTool
Spree::AgentTool::PARENT_ID_DESCRIPTION
Instance Attribute Summary
Attributes inherited from Spree::AgentTool
Instance Method Summary collapse
Methods inherited from Spree::AgentTool
additive!, audience, description, destructive?, #initialize, input_schema, mutating!, mutating?, param, params, permission, #permitted?, #summary, tool_name, #unknown_resource
Constructor Details
This class inherits a constructor from Spree::AgentTool
Instance Method Details
#call(resource: nil) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'app/tools/spree/agent_tools/describe_resource.rb', line 21 def call(resource: nil) entries = Spree::AgentTools::ResourceMap.available_for(context) entries = entries.select { |entry| entry.key == resource.to_s } if resource.present? if entries.empty? return { error: "Unknown or unavailable resource #{resource.inspect}", available: Spree::AgentTools::ResourceMap.available_for(context).map(&:key) } end # One resource gets every type's schema; the listing names the types # only, because every family's schema at once is more than an index # should cost a model's context. { resources: entries.map { |entry| describe(entry, detailed: resource.present?) } } end |