Class: S3Antivirus::Config

Inherits:
Object
  • Object
show all
Includes:
Logger
Defined in:
lib/s3_antivirus/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logger

#logger

Constructor Details

#initialize(path = nil) ⇒ Config

Returns a new instance of Config.



6
7
8
# File 'lib/s3_antivirus/config.rb', line 6

def initialize(path=nil)
  @data = load(path)
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



5
6
7
# File 'lib/s3_antivirus/config.rb', line 5

def data
  @data
end

Instance Method Details

#load(path) ⇒ Object



10
11
12
# File 'lib/s3_antivirus/config.rb', line 10

def load(path)
  YAML.load_file(lookup_path(path))
end

#lookup_path(path = nil) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/s3_antivirus/config.rb', line 14

def lookup_path(path=nil)
  paths = [
    path,
    "./s3-antivirus.conf",
    "#{ENV['HOME']}/.s3-antivirus.conf",
    "/etc/s3-antivirus.conf"
  ].compact
  found = paths.find { |p| File.exist?(p) }
  unless found
    logger.fatal("FATAL: unable to find the s3-antivirus.conf file. Paths considered: #{paths}")
    exit 1
  end
  found
end