Class: DansGuardian::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/dansguardian/config.rb,
lib/dansguardian/config/auth.rb,
lib/dansguardian/config/main.rb,
lib/dansguardian/config/auth/sql.rb,
lib/dansguardian/config/constants.rb,
lib/dansguardian/config/filtergroup.rb

Defined Under Namespace

Modules: Auth Classes: FilterGroup, Main, ValidationFailed

Constant Summary collapse

INFINITY =

Useful constants

::Float::INFINITY
BOOL =

Recurring converters

{
  'on'  => true, 
  'off' => false
}
REPORTING_LEVEL =
{
 '-1'   =>    :log_only,
  '0'   =>    :access_denied_only,
  '1'   =>    :why_but_not_what,
  '2'   =>    :full,
  '3'   =>    :html_template        
}

Instance Method Summary collapse

Constructor Details

#initialize(arg = '/etc/dansguardian/dansguardian.conf') ⇒ Config

arg May be String-like (the main config file name) or Hash-like :

DansGuardian::Config.new('path/to/dansguardian.conf')

DansGuardian::Config.new(:mainfile => '/path/to/dansguardian.conf')


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

def initialize(arg='/etc/dansguardian/dansguardian.conf')
  h = {}
  if arg.respond_to? :[]
    h = arg
  else # String-like assumed
    h = {:mainfile => arg}
  end
  @mainfile = h[:mainfile] 
  @mainconfig = nil
  @filtergroups = []
end

Instance Method Details

#filtergroup(n = 1, opt_h = {:cached => true}) ⇒ Object

get filtergroup configuration data



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/dansguardian/config.rb', line 41

def filtergroup(n=1, opt_h={:cached => true})
  if opt_h[:cached]
    if @filtergroups[n]
      return @filtergroups[n]
    else
      get_filtergroup n
    end
  else
    get_filtergroup n
  end
end

#filtergroupfile(n = 1) ⇒ Object



53
54
55
# File 'lib/dansguardian/config.rb', line 53

def filtergroupfile(n=1)
  File.join File.dirname(@mainfile), "dansguardianf#{n}.conf"
end

#main(opt_h = {:cached => false}) ⇒ Object

get data from the main configuration file



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/dansguardian/config.rb', line 28

def main(opt_h={:cached => false})
  if opt_h[:cached]
    if @mainconfig
      return @mainconfig
    else
      get_main
    end
  else
    get_main
  end
end