Class: Inspec::Resources::OracledbListenerConf

Inherits:
Object
  • Object
show all
Includes:
FileReader, FindFiles, ObjectTraverser
Defined in:
lib/inspec/resources/oracledb_listener_conf.rb

Constant Summary

Constants included from FindFiles

FindFiles::TYPES

Instance Method Summary collapse

Methods included from ObjectTraverser

#extract_value

Methods included from FileReader

#read_file_content

Methods included from FindFiles

#find_files, #find_files_or_warn

Constructor Details

#initialize(conf_path = nil) ⇒ OracledbListenerConf

Returns a new instance of OracledbListenerConf.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/inspec/resources/oracledb_listener_conf.rb', line 23

def initialize(conf_path = nil)
  oracle = nil
  if conf_path.nil?
    oracle = inspec.oracle
    @conf_path = oracle.conf_path
  else
    @conf_path = conf_path
  end

  if oracle && oracle.resource_failed?
    raise oracle.resource_exception_message
  elsif @conf_path.nil?
    return skip_resource "Oracle Listener conf path is not set"
  end

  @conf_dir = File.expand_path(File.dirname(@conf_path))
  @files_contents = {}
  @content = nil
  @params = nil
  read_content
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*keys) ⇒ Object



62
63
64
65
66
67
68
69
70
# File 'lib/inspec/resources/oracledb_listener_conf.rb', line 62

def method_missing(*keys)
  keys.shift if keys.is_a?(Array) && keys[0] == :[]
  param = value(keys)
  return nil if param.nil?
  # extract first value if we have only one value in array
  return param[0] if param.length == 1

  param
end

Instance Method Details

#contentObject



45
46
47
# File 'lib/inspec/resources/oracledb_listener_conf.rb', line 45

def content
  @content ||= read_content
end

#params(*opts) ⇒ Object



49
50
51
52
53
54
55
56
# File 'lib/inspec/resources/oracledb_listener_conf.rb', line 49

def params(*opts)
  @params || read_content
  res = @params
  opts.each do |opt|
    res = res[opt] unless res.nil?
  end
  res
end

#resource_idObject



76
77
78
# File 'lib/inspec/resources/oracledb_listener_conf.rb', line 76

def resource_id
  @conf_path
end

#to_sObject



72
73
74
# File 'lib/inspec/resources/oracledb_listener_conf.rb', line 72

def to_s
  "Oracle Listener Configuration"
end

#value(key) ⇒ Object



58
59
60
# File 'lib/inspec/resources/oracledb_listener_conf.rb', line 58

def value(key)
  extract_value(key, @params)
end