Module: NeverBounce::CLI::Feature::Envars::ClassMethods

Defined in:
lib/never_bounce/cli/feature/envars.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#envarsObject


19
20
21
22
23
24
25
# File 'lib/never_bounce/cli/feature/envars.rb', line 19

def envars
  @envars ||= if superclass.respond_to? :envars
    superclass.envars.dup
  else
    []
  end
end

Instance Method Details

#define_envar(name, comment, is_mandatory: false, examples: [], default: nil) ⇒ Item (private)

Define an envar in a formal way.

Parameters:

  • name (String)
  • comment (String)

Returns:


34
35
36
37
38
39
40
41
42
43
# File 'lib/never_bounce/cli/feature/envars.rb', line 34

def define_envar(name, comment, is_mandatory: false, examples: [], default: nil)
  Item.new({
    name: name,

    comment: comment,
    default: default,
    examples: examples,
    is_mandatory: is_mandatory,
  }).tap { |_| envars << _ }
end

#envar(name, comment, examples = []) ⇒ Object (private)

Declare an envar in a concise and magical way.

envar "ID", "Job ID"
=> define_envar "ID", "Job ID"
envar "API_KEY*", "API key", ["2ed45186c72f9319dc64338cdf16ab76b44cf3d1"]
# => define_envar "API_KEY", "API key", is_mandatory: true, examples: [...]
envar "RAW", "Print raw response body", ["y", default: "N"]
# => define_envar "RAW", "Print raw response body", examples: ["y", "N"], default: "N"

53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/never_bounce/cli/feature/envars.rb', line 53

def envar(name, comment, examples = [])
  options = {}

  real_name = if name[-1] == "*"
    options[:is_mandatory] = true
    name[0..-2]
  else
    name
  end

  if not examples.empty?
    h = ExamplesMapper.new[examples]
    options[:examples] = h[:values]
    options[:default] = h[:default] if h.include?(:default)
  end

  define_envar(real_name, comment, options)
end