Class: Inspec::Resources::NginxConfServer

Inherits:
Object
  • Object
show all
Defined in:
lib/inspec/resources/nginx_conf.rb

Overview

TODO: rename NginxServer

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params, parent) ⇒ NginxConfServer

Returns a new instance of NginxConfServer.



218
219
220
221
# File 'lib/inspec/resources/nginx_conf.rb', line 218

def initialize(params, parent)
  @parent = parent
  @params = params || {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name) ⇒ Object



241
242
243
244
245
# File 'lib/inspec/resources/nginx_conf.rb', line 241

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

  (@params[name.to_s] || []).flatten
end

Instance Attribute Details

#paramsObject (readonly)

Returns the value of attribute params.



217
218
219
# File 'lib/inspec/resources/nginx_conf.rb', line 217

def params
  @params
end

#parentObject (readonly)

Returns the value of attribute parent.



217
218
219
# File 'lib/inspec/resources/nginx_conf.rb', line 217

def parent
  @parent
end

Instance Method Details

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

Returns:

  • (Boolean)


247
248
249
250
251
# File 'lib/inspec/resources/nginx_conf.rb', line 247

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

  true
end

#to_sObject Also known as: inspect



227
228
229
230
231
232
233
234
235
236
237
238
# File 'lib/inspec/resources/nginx_conf.rb', line 227

def to_s
  server = ""
  name = Array(params["server_name"]).flatten.first
  unless name.nil?
    server += name
    listen = Array(params["listen"]).flatten.first
    server += ":#{listen}" unless listen.nil?
  end

  # go two levels up: 1. to the http entry and 2. to the root nginx conf
  @parent.parent.to_s + ", server #{server}"
end