Method: Inspec::Resources::SecurityPolicy#method_missing

Defined in:
lib/resources/security_policy.rb

#method_missing(method) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/resources/security_policy.rb', line 52

def method_missing(method)
  # load data if needed
  if @loaded == false
    load
  end

  # find line with key
  key = Regexp.escape(method.to_s)
  target = ''
  @policy.each_line {|s|
    target = s.strip if s =~ /^\s*#{key}\s*=\s*(.*)\b/
  }

  # extract variable value
  result = target.match(/[=]{1}\s*(?<value>.*)/)

  if !result.nil?
    val = result[:value]
    val = val.to_i if val =~ /^\d+$/
  else
    # TODO: we may need to return skip or failure if the
    # requested value is not available
    val = nil
  end

  val
end