lux-fw 0.2.3 → 0.5.32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.version +1 -1
- data/bin/README.md +33 -0
- data/bin/build_gem +76 -0
- data/bin/cli/config.rb +44 -0
- data/bin/cli/console.rb +61 -0
- data/bin/cli/dbconsole.rb +8 -0
- data/bin/cli/eval.rb +32 -0
- data/bin/cli/generate.rb +88 -0
- data/bin/cli/get.rb +12 -0
- data/bin/cli/new.rb +22 -0
- data/bin/cli/routes.rb +90 -0
- data/bin/cli/secrets.rb +40 -0
- data/bin/cli/server.rb +24 -0
- data/bin/cli/stats.rb +133 -0
- data/bin/lux +24 -65
- data/lib/common/class_attributes.rb +40 -64
- data/lib/common/class_callbacks.rb +34 -51
- data/lib/common/crypt.rb +10 -8
- data/lib/common/free_struct.rb +42 -0
- data/lib/common/hash_with_indifferent_access.rb +1 -1
- data/lib/common/html_tag_builder.rb +26 -2
- data/lib/common/url.rb +58 -40
- data/lib/lux/application/application.rb +290 -117
- data/lib/lux/application/lib/nav.rb +64 -38
- data/lib/lux/application/lib/render.rb +2 -1
- data/lib/lux/cache/cache.rb +87 -62
- data/lib/lux/cache/lib/{ram.rb → memory.rb} +5 -7
- data/lib/lux/cache/lib/null.rb +6 -8
- data/lib/lux/config/config.rb +109 -52
- data/lib/lux/config/lib/plugin.rb +65 -0
- data/lib/lux/config/lib/secrets.rb +48 -0
- data/lib/lux/controller/controller.rb +241 -0
- data/lib/lux/current/current.rb +33 -47
- data/lib/lux/current/lib/session.rb +72 -0
- data/lib/lux/delayed_job/delayed_job.rb +14 -7
- data/lib/lux/delayed_job/lib/memory.rb +7 -5
- data/lib/lux/delayed_job/lib/redis.rb +1 -1
- data/lib/lux/error/error.rb +164 -62
- data/lib/lux/event_bus/event_bus.rb +27 -0
- data/lib/lux/lux.rb +103 -66
- data/lib/lux/mailer/mailer.rb +23 -25
- data/lib/lux/response/lib/file.rb +81 -0
- data/lib/lux/response/lib/header.rb +14 -1
- data/lib/lux/response/response.rb +64 -56
- data/lib/lux/view/cell.rb +102 -0
- data/lib/lux/{helper → view}/helper.rb +39 -23
- data/lib/lux/view/lib/cell_helpers.rb +29 -0
- data/lib/lux/{helper/helpers/mailer_helper.rb → view/lib/helper_modules.rb} +7 -1
- data/lib/lux/{template/template.rb → view/view.rb} +21 -24
- data/lib/lux-fw.rb +4 -2
- data/lib/overload/array.rb +12 -6
- data/lib/overload/blank.rb +0 -1
- data/lib/overload/dir.rb +18 -0
- data/lib/overload/file.rb +1 -6
- data/lib/overload/hash.rb +56 -13
- data/lib/overload/integer.rb +2 -2
- data/lib/overload/it.rb +4 -4
- data/lib/overload/object.rb +37 -8
- data/lib/overload/{r.rb → raise_variants.rb} +23 -4
- data/lib/overload/string.rb +22 -6
- data/misc/demo/app/cells/demo_cell.rb +12 -0
- data/misc/demo/app/controllers/application_controller.rb +7 -0
- data/misc/demo/app/controllers/main/root_controller.rb +9 -0
- data/misc/demo/app/routes.rb +5 -0
- data/misc/demo/config/application.rb +14 -0
- data/misc/demo/config/assets.rb +6 -0
- data/misc/demo/config/environment.rb +7 -0
- data/misc/puma_auto_tune.rb +43 -0
- data/misc/unicorn.rb +37 -0
- data/{lib/lux → plugins}/api/api.rb +46 -29
- data/plugins/api/lib/attr.rb +31 -0
- data/{lib/lux → plugins}/api/lib/dsl.rb +3 -6
- data/{lib/lux → plugins}/api/lib/error.rb +0 -0
- data/{lib/lux → plugins}/api/lib/model_api.rb +51 -12
- data/{lib/lux → plugins}/api/lib/response.rb +31 -17
- data/{bin/cli/am → plugins/db/auto_migrate/auto_migrate.rb} +18 -35
- data/plugins/db/helpers/array_search.rb +27 -0
- data/plugins/db/helpers/before_save_filters.rb +32 -0
- data/plugins/db/helpers/composite_primary_keys.rb +36 -0
- data/plugins/db/helpers/core.rb +94 -0
- data/plugins/db/helpers/dataset_methods.rb +138 -0
- data/plugins/db/helpers/enums_plugin.rb +52 -0
- data/plugins/db/helpers/find_precache.rb +31 -0
- data/plugins/db/helpers/link_objects.rb +84 -0
- data/plugins/db/helpers/schema_checks.rb +83 -0
- data/plugins/db/helpers/typero_adapter.rb +71 -0
- data/plugins/db/logger/config.rb +22 -0
- data/plugins/db/logger/lux_response_adapter.rb +10 -0
- data/plugins/db/paginate/helper.rb +32 -0
- data/plugins/db/paginate/sequel_adapter.rb +23 -0
- data/plugins/exceptions/simple_exception.rb +64 -0
- data/plugins/favicon/favicon.rb +10 -0
- data/plugins/html/html_form.rb +118 -0
- data/plugins/html/html_input.rb +98 -0
- data/plugins/html/html_menu.rb +79 -0
- data/plugins/html/input_types.rb +346 -0
- data/plugins/js_widgets/js_widgets.rb +15 -0
- data/plugins/oauth/lib/facebook.rb +35 -0
- data/plugins/oauth/lib/github.rb +38 -0
- data/plugins/oauth/lib/google.rb +41 -0
- data/plugins/oauth/lib/linkedin.rb +41 -0
- data/plugins/oauth/lib/stackexchange.rb +41 -0
- data/plugins/oauth/lib/twitter.rb +38 -0
- data/plugins/oauth/oauth.rb +42 -0
- data/{lib/common → plugins/policy}/policy.rb +6 -7
- data/tasks/loader.rb +49 -0
- metadata +151 -49
- data/bin/cli/assets +0 -41
- data/bin/cli/console +0 -51
- data/bin/cli/dev +0 -1
- data/bin/cli/eval +0 -24
- data/bin/cli/exceptions +0 -62
- data/bin/cli/generate +0 -86
- data/bin/cli/get +0 -5
- data/bin/cli/nginx +0 -34
- data/bin/cli/production +0 -1
- data/bin/cli/render +0 -18
- data/bin/cli/routes +0 -14
- data/bin/cli/server +0 -4
- data/bin/cli/stat +0 -1
- data/bin/cli/systemd +0 -36
- data/bin/txt/nginx.conf +0 -46
- data/bin/txt/siege-and-puma.txt +0 -3
- data/lib/common/base32.rb +0 -47
- data/lib/common/dynamic_class.rb +0 -28
- data/lib/common/folder_model.rb +0 -50
- data/lib/common/generic_model.rb +0 -62
- data/lib/lux/application/lib/plugs.rb +0 -10
- data/lib/lux/application/lib/route_test.rb +0 -64
- data/lib/lux/cache/lib/memcached.rb +0 -3
- data/lib/lux/cell/cell.rb +0 -261
- data/lib/lux/current/lib/static_file.rb +0 -103
- data/lib/lux/helper/helpers/application_helper.rb +0 -3
- data/lib/lux/helper/helpers/html_helper.rb +0 -3
- data/lib/overload/auto_loader.rb +0 -27
- data/lib/overload/module.rb +0 -10
- data/lib/overload/string_inflections.rb +0 -8
data/bin/cli/generate
DELETED
@@ -1,86 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
# use {{object}} and {{objects}} and {{object.classify}} as template
|
4
|
-
|
5
|
-
require 'optparse'
|
6
|
-
require 'colorize'
|
7
|
-
require 'fileutils'
|
8
|
-
require 'sequel'
|
9
|
-
require 'pp'
|
10
|
-
|
11
|
-
Sequel.extension :inflector
|
12
|
-
|
13
|
-
unless ARGV[0]
|
14
|
-
puts "./generate [object singular]".red
|
15
|
-
exit
|
16
|
-
end
|
17
|
-
|
18
|
-
template_dir = 'config/templates'
|
19
|
-
exit puts "Lux::Template dir #{template_dir} is not accessible" unless Dir.exists?(template_dir)
|
20
|
-
|
21
|
-
tpl_desc = {
|
22
|
-
p:'api',
|
23
|
-
m:'model',
|
24
|
-
a:'admin',
|
25
|
-
c:'cell',
|
26
|
-
v:'view'
|
27
|
-
}
|
28
|
-
|
29
|
-
@object = ARGV[0]
|
30
|
-
@objects = @object.pluralize
|
31
|
-
|
32
|
-
puts "Singular : #{@object.yellow}"
|
33
|
-
puts "Plural : #{@objects.yellow}"
|
34
|
-
|
35
|
-
def parse_vars(data)
|
36
|
-
object = @object
|
37
|
-
objects = @objects
|
38
|
-
klass = @object.classify
|
39
|
-
|
40
|
-
data.gsub(/\{\{([^\}]+)\}\}/) { eval $1 }
|
41
|
-
end
|
42
|
-
|
43
|
-
# get all files
|
44
|
-
templates = {}
|
45
|
-
for el in Dir["./#{template_dir}/*.*"].map{ |file| file.split('/').last }
|
46
|
-
begin
|
47
|
-
data = parse_vars(File.read("#{template_dir}/#{el}"))
|
48
|
-
rescue
|
49
|
-
puts '-'
|
50
|
-
puts "File error: #{el.red}: #{$!.message}"
|
51
|
-
exit
|
52
|
-
end
|
53
|
-
type = el[0,1]
|
54
|
-
|
55
|
-
path = el.split('|', 2)[1]
|
56
|
-
path = parse_vars(path).gsub('#','/')
|
57
|
-
|
58
|
-
templates[type] ||= []
|
59
|
-
templates[type].push [path, data]
|
60
|
-
end
|
61
|
-
|
62
|
-
# # puts "Lux::Templates : #{templates.keys.sort.map{ |el| tpl_desc[el.to_sym] ? tpl_desc[el.to_sym].sub(el, el.upcase.yellow) : el.yellow }.join(', ')}"
|
63
|
-
puts "Lux::Templates : #{templates.keys.map{ |el| "#{tpl_desc[el.to_sym]}(#{el.yellow})" }.join(', ')}"
|
64
|
-
print "Execute : "
|
65
|
-
|
66
|
-
parse_templates = STDIN.gets.chomp
|
67
|
-
|
68
|
-
for type in templates.keys
|
69
|
-
next unless parse_templates.index(type)
|
70
|
-
for el in templates[type]
|
71
|
-
file, data = *el
|
72
|
-
if File.exists?(file)
|
73
|
-
print 'exists'.yellow.rjust(20)
|
74
|
-
else
|
75
|
-
FileUtils.mkdir_p(file.sub(/\/[^\/]+$/,'')) rescue false
|
76
|
-
File.open(file, 'w') { |f| f.write(data) }
|
77
|
-
print 'created'.green.rjust(20)
|
78
|
-
end
|
79
|
-
puts ": #{file}"
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
# if parse_templates.include?('m')
|
84
|
-
# sql = %[CREATE TABLE IF NOT EXISTS "public"."#{@objects}" ("id" serial, PRIMARY KEY ("id"));]
|
85
|
-
# LuxCli.run "psql -d %s -c '%s'" % [ENV.fetch('DB_NAME'), sql]
|
86
|
-
# end
|
data/bin/cli/get
DELETED
data/bin/cli/nginx
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
command = ARGV[0]
|
4
|
-
|
5
|
-
ROOT = Dir.pwd
|
6
|
-
FOLDER = Dir.pwd.split('/').last
|
7
|
-
|
8
|
-
@local_conf = './config/nginx.conf'
|
9
|
-
@target_conf = '/etc/nginx/sites-enabled/%s.conf' % FOLDER
|
10
|
-
|
11
|
-
def build_conf
|
12
|
-
conf = File.read(@local_conf) rescue LuxCli.die('Local conf %s not found' % @local_conf)
|
13
|
-
|
14
|
-
LuxCli.die('$ROOT not found in config') unless conf.include?('$ROOT')
|
15
|
-
|
16
|
-
conf = conf.gsub(/`([^`]+)`/) { `#{$1}`.chomp }
|
17
|
-
conf = conf.gsub('$ROOT', ROOT)
|
18
|
-
conf = conf.gsub('$FOLDER', FOLDER)
|
19
|
-
conf
|
20
|
-
end
|
21
|
-
|
22
|
-
case command
|
23
|
-
when 'show'
|
24
|
-
puts build_conf
|
25
|
-
when 'install'
|
26
|
-
File.write './tmp/nginx.conf', build_conf
|
27
|
-
puts '# run this manualy'
|
28
|
-
puts
|
29
|
-
puts 'sudo cp ./tmp/nginx.conf %s && sudo nginx -t' % @target_conf
|
30
|
-
else
|
31
|
-
puts ' show # show rendered config'
|
32
|
-
puts ' install # install config/nginx.conf to %s' % @target_conf
|
33
|
-
end
|
34
|
-
|
data/bin/cli/production
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
LuxCli.run "puma -p %s -e production" % @port
|
data/bin/cli/render
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
ENV['LUX_VERBOSE'] = 'true'
|
4
|
-
|
5
|
-
require './config/application'
|
6
|
-
|
7
|
-
unless ARGV[0]
|
8
|
-
Cli.die 'lux render GET /about'
|
9
|
-
end
|
10
|
-
|
11
|
-
path, http_method = ARGV.reverse
|
12
|
-
http_method ||= :get
|
13
|
-
|
14
|
-
data = Lux(path)
|
15
|
-
|
16
|
-
data[:body] = 'BODY lenght: %s kB' % (data[:body].length.to_f/1024).round(1)
|
17
|
-
|
18
|
-
ap data
|
data/bin/cli/routes
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
ENV['LUX_PRINT_ROUTES'] = 'true'
|
4
|
-
|
5
|
-
require 'awesome_print'
|
6
|
-
require './config/application'
|
7
|
-
|
8
|
-
Lux.config.log_to_stdout = false
|
9
|
-
|
10
|
-
path = ARGV[0] || '/print-routes'
|
11
|
-
|
12
|
-
puts 'Routes for test route %s' % path.green
|
13
|
-
|
14
|
-
Lux.app.render path
|
data/bin/cli/server
DELETED
data/bin/cli/stat
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
LuxCli.run 'goaccess -ca -f /var/log/nginx/access.log -a > public/goaccess.html'
|
data/bin/cli/systemd
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
ROOT = Dir.pwd
|
4
|
-
FOLDER = Dir.pwd.split('/').last.split('.').first
|
5
|
-
|
6
|
-
command = ARGV[0]
|
7
|
-
|
8
|
-
@local_conf = './config/systemd.service'
|
9
|
-
@target_conf = '/etc/systemd/system/%s.service' % FOLDER
|
10
|
-
|
11
|
-
def build_conf
|
12
|
-
conf = File.read(@local_conf) rescue LuxCli.die('Local conf %s not found' % @local_conf)
|
13
|
-
|
14
|
-
LuxCli.die('$ROOT not found in config') unless conf.include?('$ROOT')
|
15
|
-
|
16
|
-
conf = conf.gsub(/`([^`]+)`/) { `#{$1}`.chomp }
|
17
|
-
conf = conf.gsub('$ROOT', ROOT)
|
18
|
-
conf = conf.gsub('$FOLDER', FOLDER)
|
19
|
-
conf
|
20
|
-
end
|
21
|
-
|
22
|
-
case command
|
23
|
-
when 'show'
|
24
|
-
puts build_conf
|
25
|
-
when 'install'
|
26
|
-
File.write './tmp/systemd.conf', build_conf
|
27
|
-
puts '# run this manualy'
|
28
|
-
puts
|
29
|
-
puts 'sudo cp ./tmp/systemd.conf %s && sudo systemd -t' % @target_conf
|
30
|
-
else
|
31
|
-
puts ' show # show rendered config'
|
32
|
-
puts ' install # install %s to %s' % [@local_conf, @target_conf]
|
33
|
-
puts ' ---'
|
34
|
-
puts ' sudo service %s start/stop/restart'.yellow % FOLDER
|
35
|
-
end
|
36
|
-
|
data/bin/txt/nginx.conf
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
# /etc/nginx/nginx.conf
|
2
|
-
# worker_processes 4; # one per proc "grep processor /proc/cpuinfo | wc -l"
|
3
|
-
# worker_connections 1024;
|
4
|
-
|
5
|
-
server {
|
6
|
-
listen 80 default_server;
|
7
|
-
# server_name .novi-informator.hr;
|
8
|
-
|
9
|
-
root $ROOT/public;
|
10
|
-
error_log $ROOT/log/nginx-error.log;
|
11
|
-
|
12
|
-
passenger_enabled on;
|
13
|
-
passenger_friendly_error_pages on;
|
14
|
-
|
15
|
-
# (1024 * TOTAL_RAM * 0.75) / MB_PER_PROECESS
|
16
|
-
# passenger_max_pool_size 163;
|
17
|
-
# passenger_min_instances 163;
|
18
|
-
|
19
|
-
client_body_timeout 12;
|
20
|
-
client_body_in_file_only clean;
|
21
|
-
client_body_buffer_size 32K; # form POST
|
22
|
-
client_header_timeout 12;
|
23
|
-
client_max_body_size 50M;
|
24
|
-
keepalive_timeout 20;
|
25
|
-
send_timeout 10;
|
26
|
-
sendfile on;
|
27
|
-
|
28
|
-
gzip on;
|
29
|
-
gzip_comp_level 2;
|
30
|
-
gzip_min_length 1000;
|
31
|
-
gzip_proxied expired no-cache no-store private auth;
|
32
|
-
gzip_types text/plain application/x-javascript text/xml text/css application/xml;
|
33
|
-
|
34
|
-
access_log off;
|
35
|
-
|
36
|
-
location = /favicon.ico {
|
37
|
-
log_not_found off;
|
38
|
-
access_log off;
|
39
|
-
}
|
40
|
-
|
41
|
-
location ^~ /assets/ {
|
42
|
-
gzip_static on;
|
43
|
-
expires max;
|
44
|
-
add_header Cache-Control public;
|
45
|
-
}
|
46
|
-
}
|
data/bin/txt/siege-and-puma.txt
DELETED
data/lib/common/base32.rb
DELETED
@@ -1,47 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Base32
|
4
|
-
|
5
|
-
class Chunk
|
6
|
-
def initialize(bytes)
|
7
|
-
@table = "abcdefghijklmnopqrstuvwxyz234567"
|
8
|
-
@bytes = bytes
|
9
|
-
end
|
10
|
-
|
11
|
-
def decode
|
12
|
-
bytes = @bytes.take_while {|c| c != 61} # strip padding
|
13
|
-
n = (bytes.length * 5.0 / 8.0).floor
|
14
|
-
p = bytes.length < 8 ? 5 - (n * 8) % 5 : 0
|
15
|
-
c = bytes.inject(0) {|m,o| (m << 5) + @table.index(o.chr)} >> p
|
16
|
-
(0..n-1).to_a.reverse.collect {|i| ((c >> i * 8) & 0xff).chr} # bla
|
17
|
-
end
|
18
|
-
|
19
|
-
def encode
|
20
|
-
n = (@bytes.length * 8.0 / 5.0).ceil
|
21
|
-
p = n < 8 ? 5 - (@bytes.length * 8) % 5 : 0
|
22
|
-
c = @bytes.inject(0) {|m,o| (m << 8) + o} << p
|
23
|
-
[(0..n-1).to_a.reverse.collect {|i| @table[(c >> i * 5) & 0x1f].chr},
|
24
|
-
("=" * (8-n))]
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
class << self
|
29
|
-
def chunks(str, size)
|
30
|
-
result = []
|
31
|
-
bytes = str.bytes
|
32
|
-
while bytes.any? do
|
33
|
-
result << Chunk.new(bytes.take(size))
|
34
|
-
bytes = bytes.drop(size)
|
35
|
-
end
|
36
|
-
result
|
37
|
-
end
|
38
|
-
|
39
|
-
def encode(str)
|
40
|
-
chunks(str, 5).collect(&:encode).flatten.join.sub(/=+$/,'')
|
41
|
-
end
|
42
|
-
|
43
|
-
def decode(str)
|
44
|
-
chunks(str, 8).collect(&:decode).flatten.join
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
data/lib/common/dynamic_class.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
# o = DynamicClass.new name: 'a'
|
2
|
-
# o.name -> 'a'
|
3
|
-
# o.name = 'b'
|
4
|
-
# o.name 'b'
|
5
|
-
# o.name -> 'b'
|
6
|
-
# o.name = nil
|
7
|
-
# o.name -> nil
|
8
|
-
# o.title -> raises error
|
9
|
-
class DynamicClass
|
10
|
-
def initialize data, &block
|
11
|
-
@data = data
|
12
|
-
@block = block if block
|
13
|
-
end
|
14
|
-
|
15
|
-
def method_missing m, arg=:_UNDEF
|
16
|
-
key = m.to_s.sub('=','').to_sym
|
17
|
-
|
18
|
-
unless @data.has_key?(key)
|
19
|
-
raise ArgumentError.new('Key :%s not found in DynamicOptions' % key)
|
20
|
-
end
|
21
|
-
|
22
|
-
if arg == :_UNDEF
|
23
|
-
@data[key]
|
24
|
-
else
|
25
|
-
@data[key] = arg
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
data/lib/common/folder_model.rb
DELETED
@@ -1,50 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
class FolderModel
|
4
|
-
|
5
|
-
class << self
|
6
|
-
def find(key)
|
7
|
-
new(key)
|
8
|
-
end
|
9
|
-
|
10
|
-
def all
|
11
|
-
Dir["db/#{self.to_s.tableize}/*.json"].map{|file| new file.split('/').last.sub('.json') }
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
###
|
16
|
-
|
17
|
-
def [](key)
|
18
|
-
@data[key]
|
19
|
-
end
|
20
|
-
|
21
|
-
def []=(key, value)
|
22
|
-
@data[key] = value
|
23
|
-
end
|
24
|
-
|
25
|
-
def method_missing(name, *args)
|
26
|
-
func = name.to_s.split('=')[0].to_sym
|
27
|
-
|
28
|
-
if name.to_s.index('=')
|
29
|
-
@data[func] = args[0]
|
30
|
-
else
|
31
|
-
# raise "Field #{name} not found"
|
32
|
-
@data[func]
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def save
|
37
|
-
@storage.write JSON.pretty_generate(@data)
|
38
|
-
@data
|
39
|
-
end
|
40
|
-
alias :save! :save
|
41
|
-
|
42
|
-
def initialize(key)
|
43
|
-
@key = key
|
44
|
-
@storage = Pathname.new("db/#{self.class.to_s.tableize}/#{key}.json")
|
45
|
-
@data = JSON.parse @storage.read
|
46
|
-
@data = @data.h
|
47
|
-
end
|
48
|
-
|
49
|
-
end
|
50
|
-
|
data/lib/common/generic_model.rb
DELETED
@@ -1,62 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# class FooBar < GenericModel
|
4
|
-
#
|
5
|
-
# values [1, 'LinkedIn'],
|
6
|
-
# [2, 'Facebook'],
|
7
|
-
# [3, 'Twitter'],
|
8
|
-
# [4, 'Google'],
|
9
|
-
# [5, 'Email'],
|
10
|
-
# [6, 'Mobile']
|
11
|
-
#
|
12
|
-
# def ico
|
13
|
-
# %{<img src="/images/type/#{code}.png" style="width:16px; height:16px; vertical-align:middle; " />}
|
14
|
-
# end
|
15
|
-
#
|
16
|
-
# end
|
17
|
-
|
18
|
-
class GenericModel
|
19
|
-
|
20
|
-
@@values = {}
|
21
|
-
|
22
|
-
class << self
|
23
|
-
def values vals
|
24
|
-
@@values[self.to_s] = []
|
25
|
-
vals.map { |el| add_value(el) }
|
26
|
-
end
|
27
|
-
|
28
|
-
def add_value val
|
29
|
-
o = new(val)
|
30
|
-
for key in val.keys
|
31
|
-
eval %[def o.#{key}; @_vals[:#{key}]; end]
|
32
|
-
end
|
33
|
-
@@values[self.to_s].push(o)
|
34
|
-
end
|
35
|
-
|
36
|
-
def find id
|
37
|
-
for el in all
|
38
|
-
return el if el.id == id
|
39
|
-
end
|
40
|
-
nil
|
41
|
-
end
|
42
|
-
|
43
|
-
def all
|
44
|
-
@@values[self.to_s]
|
45
|
-
end
|
46
|
-
|
47
|
-
def where opts
|
48
|
-
@@values[self.to_s].select{ |el| el[opts.keys[0]] == opts.values[0] }
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
###
|
53
|
-
|
54
|
-
def initialize vals
|
55
|
-
@_vals = vals
|
56
|
-
end
|
57
|
-
|
58
|
-
def [] key
|
59
|
-
@_vals[key]
|
60
|
-
end
|
61
|
-
|
62
|
-
end
|
@@ -1,64 +0,0 @@
|
|
1
|
-
# called by Lux::Application to test route matching
|
2
|
-
class Lux::Application::RouteTest
|
3
|
-
LUX_PRINT_ROUTES = !!ENV['LUX_PRINT_ROUTES'] unless defined?(LUX_PRINT_ROUTES)
|
4
|
-
|
5
|
-
def initialize controller
|
6
|
-
@controller = controller
|
7
|
-
end
|
8
|
-
|
9
|
-
def current
|
10
|
-
Lux.current
|
11
|
-
end
|
12
|
-
|
13
|
-
def action route_object, opts={}
|
14
|
-
if route_object.class == Hash
|
15
|
-
route_test = route_object.keys.first
|
16
|
-
route_to = route_object.values.first
|
17
|
-
else
|
18
|
-
route_test = route_object
|
19
|
-
route_to = opts[:to] || route_object
|
20
|
-
end
|
21
|
-
|
22
|
-
puts '/%s => %s#%s' % [route_test.to_s.ljust(20), @controller.route_target, route_to] if LUX_PRINT_ROUTES
|
23
|
-
|
24
|
-
if test? route_test
|
25
|
-
@controller.call @controller.route_target, route_to
|
26
|
-
end
|
27
|
-
end
|
28
|
-
alias :map :action
|
29
|
-
|
30
|
-
def call route
|
31
|
-
if test? route
|
32
|
-
@controller.call @controller.route_target
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
# calls base index if root
|
37
|
-
def root
|
38
|
-
@controller.call @controller.route_target unless current.nav.root
|
39
|
-
end
|
40
|
-
|
41
|
-
def test? route
|
42
|
-
case route
|
43
|
-
when String
|
44
|
-
current.request.path.starts_with?(route)
|
45
|
-
when Symbol
|
46
|
-
route.to_s == current.nav.root
|
47
|
-
when Regexp
|
48
|
-
!!(route =~ current.nav.root)
|
49
|
-
when Array
|
50
|
-
!!route.map(&:to_s).include?(current.nav.root)
|
51
|
-
else
|
52
|
-
raise 'Route type %s is not supported' % route.class
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
def print_route route, action=nil
|
57
|
-
return unless LUX_PRINT_ROUTES
|
58
|
-
|
59
|
-
target = @controller.route_target.to_s
|
60
|
-
target += '#%s' % action if action
|
61
|
-
|
62
|
-
puts '/%s => %s' % [route.to_s.ljust(20), target]
|
63
|
-
end
|
64
|
-
end
|