Module: Assistant::InputBuilder::Accessors

Included in:
Assistant::InputBuilder
Defined in:
lib/assistant/input_builder/accessors.rb

Overview

Generators for the per-input reader and ?-checker instance methods. The lexical refinement Assistant::Refinements::StringBlankness is activated here only (narrower than the pre-M13 module-wide using).

Instance Method Summary collapse

Instance Method Details

#input_checker_meth(name:) ⇒ void

This method returns an undefined value.

Define #name? predicate on the host class. Treats nil, false, whitespace-only strings, and #empty? collections as missing.

Parameters:

  • name (Symbol)

    input name



27
28
29
30
31
32
33
34
35
# File 'lib/assistant/input_builder/accessors.rb', line 27

def input_checker_meth(name:)
  define_method("#{name}?") do
    val = @inputs[name]
    return false if val.nil? || val == false
    return !val.whitespace? if val.is_a?(String)

    val.respond_to?(:empty?) ? !val.empty? : true
  end
end

#input_getter_meth(name:) ⇒ void

This method returns an undefined value.

Define #name reader on the host class. Returns the raw value stored under @inputs[name].

Parameters:

  • name (Symbol)

    input name



16
17
18
19
20
# File 'lib/assistant/input_builder/accessors.rb', line 16

def input_getter_meth(name:)
  define_method(name) do
    @inputs[name]
  end
end