Class: Inspec::Resources::NginxConf

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
FileReader, FindFiles
Defined in:
lib/inspec/resources/nginx_conf.rb

Constant Summary

Constants included from FindFiles

FindFiles::TYPES

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from FileReader

#read_file_content

Methods included from FindFiles

#find_files, #find_files_or_warn

Constructor Details

#initialize(conf_path = nil) ⇒ NginxConf

Returns a new instance of NginxConf.



32
33
34
35
36
37
38
# File 'lib/inspec/resources/nginx_conf.rb', line 32

def initialize(conf_path = nil)
  @conf_path = conf_path || "/etc/nginx/nginx.conf"
  @contents = {}
  return skip_resource "The `nginx_conf` resource is currently not supported on Windows." if inspec.os.windows?

  read_content(@conf_path)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name) ⇒ Object



61
62
63
64
65
66
67
68
# File 'lib/inspec/resources/nginx_conf.rb', line 61

def method_missing(name)
  return super if name.to_s.match?(/^to_/)

  v = params[name.to_s]
  return v.flatten unless v.nil?

  nil
end

Instance Attribute Details

#contentsObject (readonly)

Returns the value of attribute contents.



30
31
32
# File 'lib/inspec/resources/nginx_conf.rb', line 30

def contents
  @contents
end

Instance Method Details

#httpObject



47
48
49
# File 'lib/inspec/resources/nginx_conf.rb', line 47

def http
  NginxConfHttp.new(params["http"], self)
end

#paramsObject



40
41
42
43
44
45
# File 'lib/inspec/resources/nginx_conf.rb', line 40

def params
  @params ||= parse_nginx(@conf_path)
rescue StandardError => e
  skip_resource e.message
  @params = {}
end

#resource_idObject



53
54
55
# File 'lib/inspec/resources/nginx_conf.rb', line 53

def resource_id
  @conf_path || "nginx_conf"
end

#respond_to_missing?(name, include_all = false) ⇒ Boolean

Returns:

  • (Boolean)


70
71
72
73
74
# File 'lib/inspec/resources/nginx_conf.rb', line 70

def respond_to_missing?(name, include_all = false)
  return super if name.to_s.match?(/^to_/)

  true
end

#to_sObject



57
58
59
# File 'lib/inspec/resources/nginx_conf.rb', line 57

def to_s
  "nginx_conf #{@conf_path}"
end