Simplified the configuration code base

* Merged the Config mix-in module with the main StopTime module.
* Renamed Models::Config#load to initialize, remove the old initialize.
This commit is contained in:
Paul van Tilburg 2012-01-02 15:59:06 +01:00
parent 1f350950ec
commit f11ddbbd53
1 changed files with 10 additions and 25 deletions

View File

@ -43,28 +43,24 @@ unless defined? PUBLIC_DIR
:month_and_year => "%B %Y") :month_and_year => "%B %Y")
end end
# = Mix-in module # = The main application module
# module StopTime
# This module enables configuration support available for specific
# controllers or the entire application.
module StopTime::Config
# The parsed configuration (Hash). # The parsed configuration (Hash).
attr_reader :config attr_reader :config
# Override controller call handler so that the configuration is available # Override controller call handler so that the configuration is available
# for all controllers and views. # for all controllers and views.
# See also: http://code.whytheluckystiff.net/camping/wiki/BeforeAndAfterOverrides
def service(*a) def service(*a)
# FIXME: config path should be configurable!
@config = StopTime::Models::Config.instance @config = StopTime::Models::Config.instance
super(*a) super(*a)
end end
end #module Photos::Config # Trap the HUP signal and reload the configuration.
Signal.trap("HUP") do
# = The main application module $stderr.puts "I: caught signal HUP, reloading config"
module StopTime Models::Config.instance.reload
end
# Enable SASS CSS generation from templates/sass. # Enable SASS CSS generation from templates/sass.
use Sass::Plugin::Rack use Sass::Plugin::Rack
@ -74,14 +70,6 @@ module StopTime
StopTime::Models.create_schema StopTime::Models.create_schema
end end
# Automatically mix-in the configuration support in the application.
include StopTime::Config
Signal.trap("HUP") do
$stderr.puts "I: caught signal HUP, reloading config"
Models::Config.instance.reload
end
end end
# = The Stop… Camping Time! models # = The Stop… Camping Time! models
@ -99,6 +87,7 @@ module StopTime::Models
# The default configuation file. (FIXME: shouldn't be hardcoded!) # The default configuation file. (FIXME: shouldn't be hardcoded!)
ConfigFile = File.dirname(__FILE__) + "/config.yaml" ConfigFile = File.dirname(__FILE__) + "/config.yaml"
# The default configuration. Note that the configuration of the root # The default configuration. Note that the configuration of the root
# will be merged with this configuration. # will be merged with this configuration.
DefaultConfig = { "invoice_id" => "%Y%N", DefaultConfig = { "invoice_id" => "%Y%N",
@ -106,13 +95,9 @@ module StopTime::Models
"vat_rate" => 19.0 } "vat_rate" => 19.0 }
# Creates a new configuration object and loads the configuation. # Creates a new configuration object and loads the configuation.
# by reading the file @config.yaml@ on disk, parsing it, and
# performing a merge with the default config (DefaultConfig).
def initialize def initialize
load
end
# Loads the configuration by reaiding the file file, parsing it, and
# performing a merge with descendants.
def load
@config = DefaultConfig.dup @config = DefaultConfig.dup
cfg = nil cfg = nil
# Read and parse the configuration. # Read and parse the configuration.