class Inspec::Resources::PConfig

Attributes

content[R]

Public Class Methods

new(content = nil, useropts = nil) click to toggle source
# File lib/inspec/resources/parse_config.rb, line 49
def initialize(content = nil, useropts = nil)
  @opts = {}
  @opts = useropts.dup unless useropts.nil?
  @files_contents = {}

  @content = content
  read_params unless @content.nil?
end

Public Instance Methods

method_missing(*name) click to toggle source
# File lib/inspec/resources/parse_config.rb, line 58
def method_missing(*name)
  # catch bahavior of rspec its implementation
  # @see https://github.com/rspec/rspec-its/blob/v1.2.0/lib/rspec/its.rb#L110
  name.shift if name.is_a?(Array) && name[0] == :[]
  read_params[name[0].to_s]
end
params(*opts) click to toggle source
# File lib/inspec/resources/parse_config.rb, line 65
def params(*opts)
  opts.inject(read_params) do |res, nxt|
    res.respond_to?(:key) ? res[nxt] : nil
  end
end
to_s() click to toggle source
# File lib/inspec/resources/parse_config.rb, line 71
def to_s
  "Parse Config #{@conf_path}"
end

Private Instance Methods

parse_file(conf_path) click to toggle source
# File lib/inspec/resources/parse_config.rb, line 77
def parse_file(conf_path)
  @conf_path = conf_path
  @content = read_file(conf_path).to_s

  read_params
end
read_file(path) click to toggle source
# File lib/inspec/resources/parse_config.rb, line 84
def read_file(path)
  @files_contents[path] ||= read_file_content(path)
end
read_params() click to toggle source
# File lib/inspec/resources/parse_config.rb, line 88
def read_params
  @params ||= if content.nil?
                {}
              else
                SimpleConfig.new(content, @opts).params
              end
end