Module: Lux::Config
Defined Under Namespace
Modules: Plugin Classes: Secrets
Instance Method Summary collapse
- #init! ⇒ Object
- #live_require_check! ⇒ Object
- #ram ⇒ Object
-
#require_all(dir_path) ⇒ Object
requires all files recrusive in, with spart sort.
-
#show_config ⇒ Object
preview config in development.
- #start! ⇒ Object
- #start_info(start = nil) ⇒ Object
Instance Method Details
#init! ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# 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. = 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., 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.] 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! ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# 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 ⇒ Object
44 45 46 |
# 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) ⇒ Object
requires all files recrusive in, with spart sort
11 12 13 14 15 16 17 18 19 |
# 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 ⇒ Object
preview config in development
22 23 24 25 26 27 |
# 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! ⇒ Object
48 49 50 51 |
# 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) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# 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 |