Class: Tzispa::Config::AppConfig

Inherits:
Object
  • Object
show all
Includes:
Helpers::Security
Defined in:
lib/tzispa/config/app_config.rb

Constant Summary collapse

CONFIG_FILENAME =
:appconfig

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(domain) ⇒ AppConfig

Returns a new instance of AppConfig.



15
16
17
18
# File 'lib/tzispa/config/app_config.rb', line 15

def initialize(domain)
  @domain = domain
  @cftime = nil
end

Instance Attribute Details

#cfnameObject (readonly)

Returns the value of attribute cfname.



13
14
15
# File 'lib/tzispa/config/app_config.rb', line 13

def cfname
  @cfname
end

#domainObject (readonly)

Returns the value of attribute domain.



13
14
15
# File 'lib/tzispa/config/app_config.rb', line 13

def domain
  @domain
end

Instance Method Details

#create_default(default_layout, locale) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/tzispa/config/app_config.rb', line 34

def create_default(default_layout, locale)
  hcfg = {}.tap do |cfg|
    cfg['default_layout'] = default_layout
    cfg['default_format'] = 'htm'
    cfg['default_encoding'] = 'utf-8'
    cfg['absolute_redirects'] = true
    cfg['salt'] = secret(24)
    cfg['secret'] = secret(36)
    cfg['locales'] = {}.tap do |loc|
      loc['preload'] = true
      loc['default'] = locale
    end
    cfg['logging'] = {}.tap do |log|
      log['enabled'] = true
      log['shift_age'] = 'daily'
    end
    cfg['sessions'] = {}.tap { |ses| ses['enabled'] = false }
  end
  Tzispa::Config::Yaml.save(hcfg, filename)
  load!
end

#filenameObject



20
21
22
# File 'lib/tzispa/config/app_config.rb', line 20

def filename
  @filename ||= "config/#{domain.name}.yml"
end

#load!Object



24
25
26
27
28
29
30
31
32
# File 'lib/tzispa/config/app_config.rb', line 24

def load!
  if @cftime.nil?
    @cftime = File.ctime(filename)
  elsif @cftime != File.ctime(filename)
    @config = nil
    @cftime = File.ctime(filename)
  end
  @config ||= Tzispa::Config::Yaml.load(filename)
end