lib/spontaneous/plugins/application/state.rb in spontaneous-0.2.0.beta1 vs lib/spontaneous/plugins/application/state.rb in spontaneous-0.2.0.beta2

- old
+ new

@@ -3,22 +3,29 @@ module Spontaneous::Plugins::Application module State extend Spontaneous::Concern module ClassMethods + @@semaphore = Mutex.new + def init(options={}) - # return false if loaded? - self.environment = (options.delete(:environment) || ENV["SPOT_ENV"] || :development) - self.mode = options.delete(:mode) || ENV["SPOT_MODE"] || :back - root = options.delete(:root) || ENV["SPOT_ROOT"] || Dir.pwd - site = Spontaneous::Site.instantiate(root, environment, mode) - lib = File.expand_path(File.join(root, "lib")) - $:.push(lib) unless $:.include?(lib) - Spontaneous::Logger.setup(:log_level => options[:log_level], :logfile => options[:logfile], :cli => options[:cli]) - site.initialize! - site.schema.validate! if self.mode == :console - logger.warn "Auto login is enabled and set to '#{site.config.auto_login}'. Please ensure this is disabled in production mode by removing the 'auto_login' setting from your environment file." if site.config.auto_login and mode == :back - Thread.current[:spontaneous_loaded] = true + @@semaphore.synchronize do + self.environment = (options.delete(:environment) || ENV["SPOT_ENV"] || :development) + self.mode = options.delete(:mode) || ENV["SPOT_MODE"] || :back + root = options.delete(:root) || ENV["SPOT_ROOT"] || Dir.pwd + site = Spontaneous::Site.instantiate(root, environment, mode) + lib = File.expand_path(File.join(root, "lib")) + $:.push(lib) unless $:.include?(lib) + Spontaneous::Logger.setup(:log_level => options[:log_level], :logfile => options[:logfile], :cli => options[:cli]) + site.initialize! + site.schema.validate! if self.mode == :console + if site.config.auto_login && mode == :back + logger.warn "Auto login is enabled and set to '#{site.config.auto_login}'.\n" \ + " Please ensure this is disabled in production mode by removing the\n" \ + " 'auto_login' setting from your environment file." + end + Thread.current[:spontaneous_loaded] = true + end end # This is called after definition of the Content model. # # Site = Spontaneous.site(Content)