module Lux::Config
Public Instance Methods
init!()
click to toggle source
# File lib/lux/config/config.rb, line 90 def init! # Show server errors to a client Lux.config.dump_errors = Lux.dev? # Log debug output to stdout Lux.config.log_to_stdout = Lux.dev? # Automatic code reloads in development Lux.config.auto_code_reload = Lux.dev? # Runtime compile js and css assets Lux.config.compile_assets = Lux.dev? Lux.config.session_cookie_domain = false Lux.config.asset_root = false ### if ENV['LUX_MODE'].to_s.downcase == 'log' Lux.config.dump_errors = false Lux.config.auto_code_reload = false Lux.config.compile_assets = false end ### # Default error logging Lux.config.error_logger = proc do |error| ap [error.class, error.message, Lux.error.split_backtrace(error)] 'no-key' end # Default mail logging Lux.config.on_mail = proc do |mail| Lux.logger(:email).info "[#{self.class}.#{@_template} to #{mail.to}] #{mail.subject}" end # default event bus error handle Lux.config.on_event_bus_error = proc do |error, name| Lux.logger(:event_bus).error '[%s] %s' % [name, error.message] end # server static files Lux.config.serve_static_files = true # Template to show when displaying unhandled server side errors Lux.config.server_error_template = proc do |text| text = text.to_s.gsub('<', '<') text = text.to_s.gsub($/,'<br />') %[<html> <head> <title>Server error (#{Lux.current.response.status})</title> </head> <body style="background:#fff; font-size:12pt; font-family: Arial; padding: 20px;"> <h3>HTTP error #{Lux.current.response.status} in #{Lux.config.app.name}</h3> <pre style="color:red; padding:10px; background-color: #eee; border: 1px solid #ccc; font-family:'Lucida console'; line-height: 15pt;">#{text}</pre> <br> <a href="https://httpstatuses.com/#{Lux.current.response.status}" target="http_error">more info on http error</a> </body> </html>] end # inflector String.inflections do |inflect| inflect.plural 'bonus', 'bonuses' inflect.plural 'clothing', 'clothes' inflect.plural 'people', 'people' inflect.singular /news$/, 'news' end end
live_require_check!()
click to toggle source
# File lib/lux/config/config.rb, line 29 def live_require_check! $live_require_check ||= Time.now changed_files = $LOADED_FEATURES .select{ |f| f.include?('/app/') || f.include?('lux') } .select {|f| File.mtime(f) > $live_require_check } for file in changed_files Lux.log ' Reloaded: %s' % file.split(Lux.root.to_s).last.red load file end $live_require_check = Time.now end
ram()
click to toggle source
# File lib/lux/config/config.rb, line 44 def ram `ps -o rss -p #{$$}`.chomp.split("\n").last.to_i / 1000 end
require_all(dir_path)
click to toggle source
requires all files recrusive in, with spart sort
# File lib/lux/config/config.rb, line 11 def require_all dir_path dir_path = dir_path.to_s.sub(/\/$/,'') raise '* is not allowed' if dir_path.include?('*') glob = `echo #{dir_path}/* #{dir_path}/*/* #{dir_path}/*/*/* #{dir_path}/*/*/*/* #{dir_path}/*/*/*/*/* #{dir_path}/*/*/*/*/*/* |tr ' ' '\n' | grep .rb`.split("\n") glob.select{ |o| o.index('.rb') }.each do |ruby_file| require ruby_file end end
show_config()
click to toggle source
preview config in development
# File lib/lux/config/config.rb, line 22 def show_config for k,v in Lux.config next if v.kind_of?(Hash) puts "* config :#{k} = #{v.kind_of?(Hash) ? '{...}' : v}" end end
start!()
click to toggle source
# File lib/lux/config/config.rb, line 48 def start! Object.class_callback :config, Lux::Application start_info $lux_start_time end
start_info(start=nil)
click to toggle source
# File lib/lux/config/config.rb, line 53 def start_info start=nil return @load_info if @load_info production_mode = true production_opts = [ [:compile_assets, false], [:auto_code_reload, false], [:dump_errors, false], [:log_to_stdout, false], ] opts = production_opts.map do |key, production_value| config_test = Lux.config(key) config_ok = production_value == config_test production_mode = false unless config_ok data = "#{key} (%s)" % [config_test ? :yes : :no] config_ok ? data : data.yellow end mode = production_mode ? 'production'.green : 'development'.yellow speed = if start text = ((Time.now - start)*1000).round.to_s.sub(/(\d)(\d{3})$/,'\1s \2') ' in %s ms' % text.to_s.white else end info = [] info.push '* Config: %s' % opts.join(', ') info.push "* Lux loaded #{mode} mode#{speed}, uses #{ram.to_s.white} MB RAM with total of #{Gem.loaded_specs.keys.length.to_s.white} gems in spec" @@load_info = info.join($/) puts @@load_info if start end