Class: Ukiryu::Models::Components
- Inherits:
-
Lutaml::Model::Serializable
- Object
- Lutaml::Model::Serializable
- Ukiryu::Models::Components
- Defined in:
- lib/ukiryu/models/components.rb
Overview
Components register for reusable definitions
Enables sharing common option/argument/flag/exit_codes definitions across commands through ‘$ref` references.
Instance Method Summary collapse
-
#argument(name) ⇒ ArgumentDefinition?
Get an argument by name.
-
#can_resolve?(ref) ⇒ Boolean
Check if a reference can be resolved.
-
#flag(name) ⇒ FlagDefinition?
Get a flag by name.
-
#option(name) ⇒ OptionDefinition?
Get an option by name.
-
#resolve(ref) ⇒ Object?
Resolve a reference path to a component.
Instance Method Details
#argument(name) ⇒ ArgumentDefinition?
Get an argument by name
48 49 50 |
# File 'lib/ukiryu/models/components.rb', line 48 def argument(name) @arguments&.dig(name.to_s) end |
#can_resolve?(ref) ⇒ Boolean
Check if a reference can be resolved
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/ukiryu/models/components.rb', line 56 def can_resolve?(ref) return false unless ref =~ %r{^#/components/(options|flags|arguments|exit_codes)/(.+)$} type = Regexp.last_match(1) name = Regexp.last_match(2) case type when 'options' @options&.key?(name) when 'flags' @flags&.key?(name) when 'arguments' @arguments&.key?(name) when 'exit_codes' !@exit_codes.nil? else false end end |
#flag(name) ⇒ FlagDefinition?
Get a flag by name
40 41 42 |
# File 'lib/ukiryu/models/components.rb', line 40 def flag(name) @flags&.dig(name.to_s) end |
#option(name) ⇒ OptionDefinition?
Get an option by name
32 33 34 |
# File 'lib/ukiryu/models/components.rb', line 32 def option(name) @options&.dig(name.to_s) end |
#resolve(ref) ⇒ Object?
Resolve a reference path to a component
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/ukiryu/models/components.rb', line 80 def resolve(ref) return nil unless ref =~ %r{^#/components/(options|flags|arguments|exit_codes)/(.+)$} type = Regexp.last_match(1) name = Regexp.last_match(2) case type when 'options' option(name) when 'flags' flag(name) when 'arguments' argument(name) when 'exit_codes' @exit_codes end end |