Module: SnippetCli::VarBuilder::Params
- Defined in:
- lib/snippet_cli/var_builder/params.rb
Overview
Interactive collection of Espanso ‘params` hashes per variable type.
Constant Summary collapse
- COLLECTORS =
{ 'echo' => lambda { |b| { echo: b.prompt!(Gum.input(placeholder: 'echo value', prompt_style: UI::PROMPT_STYLE, header_style: UI::PROMPT_STYLE)) } }, 'random' => lambda { |b| raw = b.prompt!(Gum.write(header: 'Put one random choice per line', prompt_style: UI::PROMPT_STYLE, header_style: UI::PROMPT_STYLE)) { choices: raw.to_s.lines.map(&:chomp).reject(&:empty?) } }, 'choice' => lambda { |b| raw = b.prompt!(Gum.write(header: 'Put one choice per line', prompt_style: UI::PROMPT_STYLE, header_style: UI::PROMPT_STYLE)) { values: raw.to_s.lines.map(&:chomp).reject(&:empty?) } } }.freeze
- DATE_OPT_FIELDS =
[ [:offset, 'Add an offset?', 'offset in seconds (e.g. 86400)', :to_i], [:locale, 'Add a locale?', 'BCP47 locale (e.g. en-US, ja-JP)', nil], [:tz, 'Add a timezone?', 'IANA timezone (e.g. America/New_York)', nil] ].freeze
Class Method Summary collapse
- .collect(builder, type) ⇒ Object
- .collect_list(builder, item_name) ⇒ Object
- .validate!(type, params) ⇒ Object
Class Method Details
.collect(builder, type) ⇒ Object
27 28 29 30 31 |
# File 'lib/snippet_cli/var_builder/params.rb', line 27 def self.collect(builder, type) params = collect_raw(builder, type) validate!(type, params) params end |
.collect_list(builder, item_name) ⇒ Object
54 55 56 57 58 |
# File 'lib/snippet_cli/var_builder/params.rb', line 54 def self.collect_list(builder, item_name) raw = builder.prompt!(Gum.write(header: "Put one #{item_name} per line", prompt_style: UI::PROMPT_STYLE, header_style: UI::PROMPT_STYLE)) raw.to_s.lines.map(&:chomp).reject(&:empty?) end |
.validate!(type, params) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/snippet_cli/var_builder/params.rb', line 33 def self.validate!(type, params) return unless ParamSchema.known_type?(type) return if ParamSchema.valid_params?(type, params) raise SnippetCli::InvalidParamsError, "Invalid params #{params.inspect} for var type '#{type}'" end |