Module: Lux
- Extended by:
- Lux
- Included in:
- Lux
- Defined in:
- lib/lux/error/error.rb,
lib/lux/lux.rb,
lib/lux/cache/cache.rb,
lib/lux/config/config.rb,
lib/lux/mailer/mailer.rb,
lib/lux/plugin/plugin.rb,
lib/lux/render/render.rb,
lib/lux/current/current.rb,
lib/lux/template/helper.rb,
lib/lux/cache/lux_adapter.rb,
lib/lux/error/lux_adapter.rb,
lib/lux/response/lib/file.rb,
lib/lux/response/response.rb,
lib/lux/template/template.rb,
lib/lux/config/lux_adapter.rb,
lib/lux/logger/lux_adapter.rb,
lib/lux/plugin/lux_adapter.rb,
lib/lux/response/lib/flash.rb,
lib/lux/application/lib/nav.rb,
lib/lux/current/lib/session.rb,
lib/lux/current/lux_adapter.rb,
lib/lux/response/lib/header.rb,
lib/lux/template/lux_adapter.rb,
lib/lux/cache/lib/null_server.rb,
lib/lux/controller/controller.rb,
lib/lux/application/lib/render.rb,
lib/lux/application/lib/routes.rb,
lib/lux/application/lib/shared.rb,
lib/lux/application/application.rb,
lib/lux/application/lux_adapter.rb,
lib/lux/cache/lib/memory_server.rb,
lib/lux/cache/lib/sqlite_server.rb,
lib/lux/environment/environment.rb,
lib/lux/environment/lux_adapter.rb,
lib/lux/cache/lib/memcached_server.rb,
lib/lux/current/lib/encrypt_params.rb,
lib/lux/application/lib/magic_routes.rb,
lib/lux/template/inline_render_proxy.rb
Overview
enables variable access as a method call to render helper
render.foo # 123 render.bar ||= 456 render.bar # 456
Defined Under Namespace
Modules: Config, Plugin
Classes: Application, Cache, Controller, Current, Environment, Error, InlineRenderProxy, Mailer, Response, Template
Instance Method Summary
collapse
Instance Method Details
24
25
26
|
# File 'lib/lux/template/inline_render_proxy.rb', line 24
def [] name
@context.instance_variable_get("@_#{name}")
end
|
#[]=(name, value) ⇒ Object
28
29
30
|
# File 'lib/lux/template/inline_render_proxy.rb', line 28
def []= name, value
@context.instance_variable_set("@_#{name}", value)
end
|
#app(&block) ⇒ Object
Also known as:
application
#app_caller ⇒ Object
63
64
65
66
|
# File 'lib/lux/lux.rb', line 63
def app_caller
app_line = caller.find { |line| !line.include?('/lux-') && !line.include?('/.') && !line.include?('(eval)') }
app_line ? app_line.split(':in ').first.sub(Lux.root.to_s, '.') : nil
end
|
#cache(key = nil) ⇒ Object
Lux.cache.fetch … -> pass to cache server Lux.cache(:key) {} -> in memory no clear cache
11
12
13
14
15
16
17
18
|
# File 'lib/lux/cache/lux_adapter.rb', line 11
def cache key=nil
if block_given?
raise AargumentError.new('Cache key not given') unless key
CACHE[key] ||= yield
else
CACHE_SERVER
end
end
|
#call(env = nil) ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/lux/lux.rb', line 15
def call env = nil
Timeout::timeout Lux::Config.app_timeout do
app = Lux::Application.new env
app.render_base || raise('No RACK response given')
end
rescue => err
Lux::Error.log err
if Lux.env.show_errors?
raise err
else
[500, {}, ['Server error: %s' % err.message]]
end
end
|
#config ⇒ Object
Also known as:
secrets
get config hash pointer or die if key provided and not found
3
4
5
|
# File 'lib/lux/config/lux_adapter.rb', line 3
def config
@lux_config ||= Lux::Config.load.to_hwia
end
|
2
3
4
|
# File 'lib/lux/current/lux_adapter.rb', line 2
def current
Thread.current[:lux] ||= Lux::Current.new('/mock')
end
|
#delay(time_to_live = nil) ⇒ Object
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/lux/lux.rb', line 68
def delay time_to_live = nil
Thread.new do
time_to_live ||= Lux.config.delay_timeout
unless time_to_live.is_a?(Numeric)
raise 'Time to live is not integer (seconds)'
end
Timeout::timeout time_to_live do
yield
end
end
end
|
#die(text) ⇒ Object
57
58
59
60
61
|
# File 'lib/lux/lux.rb', line 57
def die text
puts "Lux FATAL: #{text}".red
logger(:system_die).error text
exit
end
|
#env(test = nil) ⇒ Object
8
9
10
11
12
|
# File 'lib/lux/environment/lux_adapter.rb', line 8
def env test=nil
@env_base ||= Lux::Environment.new ENV.fetch('RACK_ENV')
test ? @env_base == test : @env_base
end
|
10
11
12
|
# File 'lib/lux/lux.rb', line 10
def fw_root
@lux_fw_root ||= Pathname.new(File.expand_path('../../', File.dirname(__FILE__))).freeze
end
|
#info(text) ⇒ Object
42
43
44
45
46
47
48
|
# File 'lib/lux/lux.rb', line 42
def info text
if text.class == Array
text.each {|line| self.info line }
else
puts '* %s' % text.magenta
end
end
|
#load_tasks ⇒ Object
load rake tasks + including ones in plugins
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/lux/config/lux_adapter.rb', line 9
def load_tasks
name = ARGV.first.to_s
if name.end_with?(':')
data = `rake #{name}info 2>&1`
unless data.include?('rake aborted!')
puts "rake #{name}".gray
puts data
puts '---'
end
run 'rake -T | grep --color=never %s' % ARGV.first
exit
end
require_relative '../../../tasks/loader'
end
|
#log(what = nil, &block) ⇒ Object
21
22
23
24
25
26
|
# File 'lib/lux/logger/lux_adapter.rb', line 21
def log what = nil, &block
return unless Lux.env.screen_log?
what = block.call if block
print what.to_s + "\n" if what
end
|
#logger(name = nil) ⇒ Object
Lux.logger(:foo).warn ‘bar’
7
8
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/lux/logger/lux_adapter.rb', line 7
def logger name = nil
raise "Logger name is required" unless name
LOGGER_CACHE[name] ||= begin
output_location = Lux.config.logger_path_mask % name
LOGGER_CACHE[name] = Logger.new output_location, Lux.config.logger_files_to_keep, Lux.config.logger_file_max_size
if Lux.config.logger_formatter
LOGGER_CACHE[name].formatter = Lux.config.logger_formatter
end
LOGGER_CACHE[name]
end
end
|
#plugin(*args) ⇒ Object
simple interface to plugins Lux.plugin :foo Lux.plugin
5
6
7
|
# File 'lib/lux/plugin/lux_adapter.rb', line 5
def plugin *args
args.first ? ::Lux::Plugin.load(*args) : ::Lux::Plugin
end
|
#render(*args) ⇒ Object
Lux.app.new(path, full_opts).info Lux.render.post(path, params, rest_of_opts).info Lux.render.get(‘/search’, { q: ‘london’ }, { session: 1 }).info def render *args
5
6
7
8
9
10
11
|
# File 'lib/lux/render/render.rb', line 5
def render *args
if args.first
app.new(*args)
else
app::Render
end
end
|
6
7
8
|
# File 'lib/lux/lux.rb', line 6
def root
@lux_app_root ||= Pathname.new(ENV.fetch('APP_ROOT') { Dir.pwd }).freeze
end
|
#run(command, get_result = false) ⇒ Object
Cdn.run has maybe better runner, inspect
51
52
53
54
55
|
# File 'lib/lux/lux.rb', line 51
def run command, get_result = false
puts command.light_black
logger(:system_run).info command
get_result ? `${command}` : system(command)
end
|
simple block to calc block execution speed
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/lux/lux.rb', line 31
def speed
render_start = Time.monotonic
yield
num = (Time.monotonic - render_start) * 1000
if num > 1000
'%s sec' % (num/1000).round(2)
else
'%s ms' % num.round(1)
end
end
|
2
3
4
|
# File 'lib/lux/template/lux_adapter.rb', line 2
def template
Lux::Template
end
|
5
6
7
|
# File 'lib/lux/cache/lux_adapter.rb', line 5
def var
CACHE
end
|