2010-07-23 20:09:54 +00:00
|
|
|
module Locomotive
|
2010-04-22 23:52:11 +00:00
|
|
|
class Configuration
|
|
|
|
|
|
|
|
@@defaults = {
|
2011-04-03 23:59:41 +00:00
|
|
|
:name => 'LocomotiveApp',
|
|
|
|
:domain => 'example.com',
|
2011-04-05 00:18:17 +00:00
|
|
|
:reserved_subdomains => %w{www admin email blog webmail mail support help site sites},
|
2011-04-03 23:59:41 +00:00
|
|
|
# :forbidden_paths => %w{layouts snippets stylesheets javascripts assets admin system api},
|
|
|
|
:reserved_slugs => %w{stylesheets javascripts assets admin images api pages edit},
|
2011-09-19 14:15:25 +00:00
|
|
|
:locales => %w{en de fr pt-BR it nl no es ru},
|
2011-04-03 23:59:41 +00:00
|
|
|
:cookie_key => '_locomotive_session',
|
|
|
|
:enable_logs => false,
|
|
|
|
:hosting => :auto,
|
2011-04-28 15:17:15 +00:00
|
|
|
:delayed_job => false,
|
2011-04-03 23:59:41 +00:00
|
|
|
:default_locale => :en,
|
2011-11-06 11:18:34 +00:00
|
|
|
:mailer_sender => 'support@example.com',
|
2011-04-03 23:59:41 +00:00
|
|
|
:manage_subdomain => false,
|
2011-04-24 23:21:38 +00:00
|
|
|
:manage_manage_domains => false,
|
2011-06-28 13:38:13 +00:00
|
|
|
:lastest_items_nb => 5,
|
|
|
|
:rack_cache => {
|
|
|
|
:verbose => true,
|
|
|
|
:metastore => URI.encode("file:#{Rails.root}/tmp/dragonfly/cache/meta"), # URI encoded in case of spaces
|
|
|
|
:entitystore => URI.encode("file:#{Rails.root}/tmp/dragonfly/cache/body")
|
2011-07-25 21:07:32 +00:00
|
|
|
},
|
2011-11-04 15:55:51 +00:00
|
|
|
:devise_modules => [:rememberable, :database_authenticatable, :recoverable, :trackable, :validatable, :encryptable, { :encryptor => :sha1 }],
|
2011-07-28 13:03:13 +00:00
|
|
|
:context_assign_extensions => { }
|
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
|
|
|
|
|
2011-04-03 23:59:41 +00:00
|
|
|
def multi_sites?
|
|
|
|
self.multi_sites != false
|
|
|
|
end
|
|
|
|
|
|
|
|
def manage_subdomain?
|
|
|
|
self.manage_subdomain == true
|
|
|
|
end
|
|
|
|
|
|
|
|
def manage_domains?
|
|
|
|
self.manage_domains == true
|
|
|
|
end
|
|
|
|
|
|
|
|
def manage_subdomain_n_domains?
|
|
|
|
self.manage_subdomain? && self.manage_domains?
|
|
|
|
end
|
|
|
|
|
2011-07-08 22:47:05 +00:00
|
|
|
def reserved_subdomains
|
2011-04-05 00:18:17 +00:00
|
|
|
if self.multi_sites?
|
|
|
|
if self.multi_sites.reserved_subdomains.blank?
|
|
|
|
@@defaults[:reserved_subdomains]
|
|
|
|
else
|
|
|
|
self.multi_sites.reserved_subdomains
|
|
|
|
end
|
|
|
|
else
|
|
|
|
[]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-04-22 23:52:11 +00:00
|
|
|
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)
|
2011-04-05 00:18:17 +00:00
|
|
|
if block_given?
|
|
|
|
self.delete(key) unless super(key).respond_to?(:keys)
|
|
|
|
yield(super(key))
|
|
|
|
else
|
|
|
|
super(key)
|
|
|
|
end
|
|
|
|
|
|
|
|
# block_given? ? yield(super(key)) : super(key)
|
2010-04-22 23:52:11 +00:00
|
|
|
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
|