Class: TF::EnvTypeTest

Inherits:
Object
  • Object
show all
Defined in:
lib/plugins/tf/env_type_test.rb

Constant Summary collapse

MATCHER =
/^env\[([a-zA-Z_][a-zA-Z0-9_]*)\]\?([!]?=)(array|string|nil)/

Instance Method Summary collapse

Instance Method Details

#execute(test, _stdout, _stderr, _stdboth, _status, env) ⇒ Object



8
9
10
11
12
13
14
15
16
17
# File 'lib/plugins/tf/env_type_test.rb', line 8

def execute test, _stdout, _stderr, _stdboth, _status, env
  test =~ TF::EnvTypeTest::MATCHER
  variable, sign, type = $1.strip, $2, $3
  var_type = variable_type( env[ variable ] )
  if ( sign == "=" ) ^ ( var_type == type )
    [ false, "failed: env? #{variable} #{sign} #{type} # was #{var_type}" ]
  else
    [ true, "passed: env? #{variable} #{sign} #{type}" ]
  end
end

#matches?(test) ⇒ Boolean

Returns:

  • (Boolean)


4
5
6
# File 'lib/plugins/tf/env_type_test.rb', line 4

def matches? test
  test =~ TF::EnvTypeTest::MATCHER
end

#variable_type(value) ⇒ Object



19
20
21
22
# File 'lib/plugins/tf/env_type_test.rb', line 19

def variable_type value
  value.nil? ? 'nil' :
    value.is_a?(Hash) ? 'array' : 'string'
end