module Lux
Constants
- ENV_PROD
Public Instance Methods
app(&block)
click to toggle source
# File lib/lux/lux.rb, line 76 def app &block block ? Lux::Application.class_eval(&block) : Lux::Application end
call(env=nil)
click to toggle source
main rack response
# File lib/lux/lux.rb, line 35 def call env=nil state = Lux::Current.new env app = Lux::Application.new state app.render rescue => error if Lux.config(:dump_errors) raise error else log error.backtrace [500, {}, ['Server error: %s' % error.message]] end end
config(key=nil)
click to toggle source
# File lib/lux/lux.rb, line 58 def config key=nil if key value = CONFIG[key] die 'Lux.config.%s not found' % key if value.nil? value.kind_of?(Proc) ? value.call() : value else CONFIG end end
current()
click to toggle source
# File lib/lux/lux.rb, line 68 def current Thread.current[:lux][:page] ||= Lux::Current.new('/mock') end
current=(what)
click to toggle source
# File lib/lux/lux.rb, line 72 def current=(what) Thread.current[:lux][:page] = what end
delay(*args, &block)
click to toggle source
if block given, simple new thread bg job if string given, eval it in bg if object given, instance it and run it
# File lib/lux/lux.rb, line 100 def delay *args, &block if block_given? puts 'add' t = Thread.new do begin block.call rescue => e Lux.logger(:delay_errors).error [e.message, e.backtrace] end end BACKGROUND_THREADS.push t elsif args[0] # Lux.delay(mail_object, :deliver) Lux::DelayedJob.push(*args) else Lux::DelayedJob end end
env(key=nil)
click to toggle source
# File lib/lux/lux.rb, line 48 def env key=nil if key value = ENV[key] die "ENV['#{key}'] not found" if value.nil? value else ENV['RACK_ENV'] end end
error(data=nil)
click to toggle source
# File lib/lux/lux.rb, line 80 def error data=nil data ? Lux::Error.render(data) : Lux::Error end
load_tasks()
click to toggle source
load rake tasks + including ones in plugins
# File lib/lux/lux.rb, line 122 def load_tasks require_relative '../../tasks/loader.rb' end
log(what=nil) { || ... }
click to toggle source
simple log to stdout
# File lib/lux/lux.rb, line 85 def log what=nil return unless Lux.config(:log_to_stdout) puts what || yield end
logger(name=nil)
click to toggle source
Lux.logger
(:foo).warn 'bar'
# File lib/lux/lux.rb, line 157 def logger name=nil name ||= ENV.fetch('RACK_ENV').downcase MCACHE['lux-logger-%s' % name] ||= Logger.new('./log/%s.log' % name).tap do |it| it.formatter = Lux.config.logger_formater end end
plugin(*args)
click to toggle source
simple interface to plugins Lux.plugin
:foo Lux.plugin
# File lib/lux/lux.rb, line 93 def plugin *args args.first ? Lux::Config::Plugin.load(*args) : Lux::Config::Plugin end
ram_cache(key) { || ... }
click to toggle source
in memory cache, used on app init, no need for Mutex
# File lib/lux/lux.rb, line 127 def ram_cache key MCACHE[key] = nil if Lux.config(:compile_assets) MCACHE[key] ||= yield end
serve(rack_handler)
click to toggle source
must be called when serving web pages from rackup
# File lib/lux/lux.rb, line 140 def serve rack_handler @rackup_start = true # Boot Lux Object.class_callback :rack_boot, Lux::Application, rack_handler rack_handler.run self end
speed() { || ... }
click to toggle source
simple block to calc block execution speed
# File lib/lux/lux.rb, line 149 def speed render_start = Time.monotonic yield num = (Time.monotonic - render_start) * 1000 '%s ms' % num.round(1) end
start()
click to toggle source
initialize the Lux
application
# File lib/lux/lux.rb, line 133 def start Lux.config.lux_config_loaded = true Config.start! end