Module: SnippetCli::VarBuilder::ParamSchema
- Defined in:
- lib/snippet_cli/var_builder/param_schema.rb
Overview
Pure data layer: describes what params are valid for each var type. No Gum/UI calls — independently testable.
Constant Summary collapse
- SCHEMAS =
{ 'echo' => { required: [:echo], optional: [], field_types: { echo: :string } }, 'random' => { required: [:choices], optional: [], field_types: { choices: :string_array } }, 'choice' => { required: [:values], optional: [], field_types: { values: :string_array } }, 'date' => { required: [:format], optional: %i[offset locale tz], field_types: { format: :string, offset: :integer, locale: :string, tz: :string } }, 'shell' => { required: %i[cmd shell], optional: %i[debug trim], field_types: { cmd: :string, shell: :string, debug: :boolean, trim: :boolean } }, 'script' => { required: [:args], optional: [:trim], field_types: { args: :string_array, trim: :boolean } }, 'form' => { required: [:layout], optional: [:fields], field_types: { layout: :string, fields: :any } }, 'clipboard' => { required: [], optional: [], field_types: {} } }.freeze
Class Method Summary collapse
- .known_type?(type) ⇒ Boolean
- .schema_for(type) ⇒ Object
-
.valid_params?(type, params) ⇒ Boolean
Returns true if params hash contains all required fields and no unknown fields.
Class Method Details
.known_type?(type) ⇒ Boolean
51 52 53 |
# File 'lib/snippet_cli/var_builder/param_schema.rb', line 51 def self.known_type?(type) SCHEMAS.key?(type) end |
.schema_for(type) ⇒ Object
55 56 57 |
# File 'lib/snippet_cli/var_builder/param_schema.rb', line 55 def self.schema_for(type) SCHEMAS[type] end |
.valid_params?(type, params) ⇒ Boolean
Returns true if params hash contains all required fields and no unknown fields. Pure method — no UI calls.
61 62 63 64 65 66 67 68 |
# File 'lib/snippet_cli/var_builder/param_schema.rb', line 61 def self.valid_params?(type, params) schema = SCHEMAS[type] return false unless schema allowed = schema[:required] + schema[:optional] schema[:required].all? { |f| params.key?(f) } && params.keys.all? { |k| allowed.include?(k) } end |