Class: Tzispa::Config::AppConfig

Inherits:
Object
  • Object
show all
Includes:
Helpers::Security
Defined in:
lib/tzispa/config/appconfig.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.



16
17
18
19
# File 'lib/tzispa/config/appconfig.rb', line 16

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

Instance Attribute Details

#cfnameObject (readonly)

Returns the value of attribute cfname.



14
15
16
# File 'lib/tzispa/config/appconfig.rb', line 14

def cfname
  @cfname
end

#domainObject (readonly)

Returns the value of attribute domain.



14
15
16
# File 'lib/tzispa/config/appconfig.rb', line 14

def domain
  @domain
end

Instance Method Details

#create_default(host:, default_layout: 'index', locale: 'en') ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/tzispa/config/appconfig.rb', line 37

def create_default(host:, default_layout: 'index', locale: 'en')
  hcfg = Hash.new.tap { |cfg|
    cfg['developing'] = true
    cfg['id'] = domain.name
    cfg['default_layout'] = default_layout
    cfg['default_format'] = 'htm'
    cfg['host_name'] = host
    cfg['canonical_url'] = "http://#{host}"
    cfg['default_encoding'] = 'utf-8'
    cfg['auth_required'] = false
    cfg['absolute_redirects'] = true
    cfg['salt'] = secret(24)
    cfg['secret'] = secret(36)
    cfg['temp_dir'] = 'tmp'
    cfg['temp_dir'] = true
    cfg['template_cache'] = Hash.new.tap { |tpc|
      tpc['enabled'] = false
      tpc['size'] = 0
    }
    cfg['locales'] = Hash.new.tap { |loc|
      loc['preload'] = true
      loc['default'] = locale
    }
    cfg['logging'] = Hash.new.tap { |log|
      log['enabled'] = true
      log['shift_age'] = 'daily'
    }
    cfg['sessions'] = Hash.new.tap { |ses|
      ses['enabled'] = true
      ses['timeout'] = 3600
      ses['store_path'] = 'data/session'
      ses['secret'] = secret(32)
    }
  }
  Tzispa::Config::Yaml.save(hcfg, filename)
  load!
end

#filenameObject



21
22
23
# File 'lib/tzispa/config/appconfig.rb', line 21

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

#load!Object



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/tzispa/config/appconfig.rb', line 25

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