Class: YamlEnvTag::EnvVariable

Inherits:
String
  • Object
show all
Defined in:
lib/yaml_env_tag/env_variable.rb

Overview

A specialized String that holds a value of environment variable specified by !ENV tag.

Instance Method Summary collapse

Instance Method Details

#init_with(coder) ⇒ Object

Deserializes from YAML. This method is called by Psych.

Parameters:

  • coder (Psych::Coder)

    coder with :scalar or :seq.

Raises:

  • MissingEnvVariableError if the specified environment variable is not set (i.e. does not exist in ENV).



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/yaml_env_tag/env_variable.rb', line 14

def init_with(coder)
  *variables, default =
    case coder.type
    when :scalar
      [coder.scalar, nil]
    when :seq
      coder.seq.size < 2 ? [*coder.seq, nil] : coder.seq
    else
      raise InvalidUsageError, "#{coder.tag} tag cannot be used on a #{coder.type} node"
    end

  initialize(variables, default)
end