Class: Inspec::Resources::PConfig

Inherits:
Object
  • Object
show all
Includes:
FileReader
Defined in:
lib/inspec/resources/parse_config.rb

Direct Known Subclasses

PConfigFile

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from FileReader

#read_file_content

Constructor Details

#initialize(content = nil, useropts = nil) ⇒ PConfig

Returns a new instance of PConfig.



49
50
51
52
53
54
55
56
# 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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*name) ⇒ Object



58
59
60
61
62
63
# 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

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



48
49
50
# File 'lib/inspec/resources/parse_config.rb', line 48

def content
  @content
end

Instance Method Details

#params(*opts) ⇒ Object



65
66
67
68
69
# 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

#resource_idObject



71
72
73
# File 'lib/inspec/resources/parse_config.rb', line 71

def resource_id
  @content || "parse_config"
end

#to_sObject



75
76
77
# File 'lib/inspec/resources/parse_config.rb', line 75

def to_s
  "Parse Config #{@conf_path}"
end