2010-07-23 20:09:54 +00:00
|
|
|
module Locomotive
|
2010-04-22 23:52:11 +00:00
|
|
|
class Configuration
|
|
|
|
|
|
|
|
@@defaults = {
|
|
|
|
:name => 'LocomotiveApp',
|
2010-06-14 13:04:01 +00:00
|
|
|
:default_domain => 'example.com',
|
2010-04-25 00:33:38 +00:00
|
|
|
:reserved_subdomains => %w{www admin email blog webmail mail support help site sites},
|
2010-04-30 14:05:53 +00:00
|
|
|
# :forbidden_paths => %w{layouts snippets stylesheets javascripts assets admin system api},
|
2010-09-02 23:03:20 +00:00
|
|
|
:reserved_slugs => %w{stylesheets javascripts assets admin images api pages edit},
|
2010-06-03 15:32:40 +00:00
|
|
|
:locales => %w{en fr},
|
2010-06-11 09:29:51 +00:00
|
|
|
:cookie_key => '_locomotive_session',
|
2010-06-14 13:04:01 +00:00
|
|
|
:enable_logs => false,
|
2010-10-27 00:11:44 +00:00
|
|
|
:heroku => false,
|
2010-12-16 23:42:38 +00:00
|
|
|
:delayed_job => true,
|
2011-01-18 14:24:42 +00:00
|
|
|
:default_locale => :en,
|
|
|
|
:mailer_sender => 'support@example.com'
|
2010-04-22 23:52:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cattr_accessor :settings
|
|
|
|
|
|
|
|
def initialize
|
|
|
|
@@settings = self.class.get_from_hash(@@defaults)
|
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-04-22 23:52:11 +00:00
|
|
|
def self.settings
|
|
|
|
@@settings
|
|
|
|
end
|
|
|
|
|
|
|
|
def method_missing(name, *args, &block)
|
|
|
|
self.settings.send(name, *args, &block)
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
# converts a hash map into a ConfigurationHash
|
|
|
|
def self.get_from_hash(hash)
|
|
|
|
config = ConfigurationHash.new
|
|
|
|
|
|
|
|
hash.each_pair do |key, value|
|
|
|
|
config[key] = value.is_a?(Hash) ? self.get_from_hash(value) : value
|
|
|
|
end
|
|
|
|
|
|
|
|
config
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# specialized hash for storing configuration settings
|
|
|
|
class ConfigurationHash < Hash
|
2010-07-23 20:09:54 +00:00
|
|
|
# ensure that default entries always produce
|
2010-04-22 23:52:11 +00:00
|
|
|
# instances of the ConfigurationHash class
|
|
|
|
def default(key=nil)
|
|
|
|
include?(key) ? self[key] : self[key] = self.class.new
|
|
|
|
end
|
|
|
|
|
|
|
|
# retrieves the specified key and yields it
|
|
|
|
# if a block is provided
|
|
|
|
def [](key, &block)
|
|
|
|
block_given? ? yield(super(key)) : super(key)
|
|
|
|
end
|
|
|
|
|
|
|
|
# provides member-based access to keys
|
|
|
|
# i.e. params.id === params[:id]
|
|
|
|
# note: all keys are converted to symbols
|
|
|
|
def method_missing(name, *args, &block)
|
2010-07-23 20:09:54 +00:00
|
|
|
if name.to_s.ends_with? '='
|
2010-04-22 23:52:11 +00:00
|
|
|
send :[]=, name.to_s.chomp('=').to_sym, *args
|
|
|
|
else
|
|
|
|
send(:[], name.to_sym, &block)
|
2010-07-23 20:09:54 +00:00
|
|
|
end
|
|
|
|
end
|
2010-04-22 23:52:11 +00:00
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
end
|