Class: SchwarmCli::TemplateResolver
- Inherits:
-
Object
- Object
- SchwarmCli::TemplateResolver
- Defined in:
- lib/schwarm_cli/template_resolver.rb
Overview
Turns a user-provided ‘–template` reference into a task template ID.
Accepted inputs:
- a numeric template ID (looked up directly)
- an exact template name (resolved via search + exact match)
Defined Under Namespace
Classes: ResolutionError
Instance Method Summary collapse
-
#initialize(client:) ⇒ TemplateResolver
constructor
A new instance of TemplateResolver.
- #resolve(ref) ⇒ Object
Constructor Details
#initialize(client:) ⇒ TemplateResolver
Returns a new instance of TemplateResolver.
12 13 14 |
# File 'lib/schwarm_cli/template_resolver.rb', line 12 def initialize(client:) @client = client end |
Instance Method Details
#resolve(ref) ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/schwarm_cli/template_resolver.rb', line 16 def resolve(ref) return nil if blank?(ref) ref = ref.to_s.strip template = ref.match?(/\A\d+\z/) ? find_by_id(ref) : find_by_name(ref) raise ResolutionError, "no schwarm task template matches `#{ref}`." if template.nil? template["id"] end |