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.
Files changed (138) hide show
  1. checksums.yaml +4 -4
  2. data/.version +1 -1
  3. data/bin/README.md +33 -0
  4. data/bin/build_gem +76 -0
  5. data/bin/cli/config.rb +44 -0
  6. data/bin/cli/console.rb +61 -0
  7. data/bin/cli/dbconsole.rb +8 -0
  8. data/bin/cli/eval.rb +32 -0
  9. data/bin/cli/generate.rb +88 -0
  10. data/bin/cli/get.rb +12 -0
  11. data/bin/cli/new.rb +22 -0
  12. data/bin/cli/routes.rb +90 -0
  13. data/bin/cli/secrets.rb +40 -0
  14. data/bin/cli/server.rb +24 -0
  15. data/bin/cli/stats.rb +133 -0
  16. data/bin/lux +24 -65
  17. data/lib/common/class_attributes.rb +40 -64
  18. data/lib/common/class_callbacks.rb +34 -51
  19. data/lib/common/crypt.rb +10 -8
  20. data/lib/common/free_struct.rb +42 -0
  21. data/lib/common/hash_with_indifferent_access.rb +1 -1
  22. data/lib/common/html_tag_builder.rb +26 -2
  23. data/lib/common/url.rb +58 -40
  24. data/lib/lux/application/application.rb +290 -117
  25. data/lib/lux/application/lib/nav.rb +64 -38
  26. data/lib/lux/application/lib/render.rb +2 -1
  27. data/lib/lux/cache/cache.rb +87 -62
  28. data/lib/lux/cache/lib/{ram.rb → memory.rb} +5 -7
  29. data/lib/lux/cache/lib/null.rb +6 -8
  30. data/lib/lux/config/config.rb +109 -52
  31. data/lib/lux/config/lib/plugin.rb +65 -0
  32. data/lib/lux/config/lib/secrets.rb +48 -0
  33. data/lib/lux/controller/controller.rb +241 -0
  34. data/lib/lux/current/current.rb +33 -47
  35. data/lib/lux/current/lib/session.rb +72 -0
  36. data/lib/lux/delayed_job/delayed_job.rb +14 -7
  37. data/lib/lux/delayed_job/lib/memory.rb +7 -5
  38. data/lib/lux/delayed_job/lib/redis.rb +1 -1
  39. data/lib/lux/error/error.rb +164 -62
  40. data/lib/lux/event_bus/event_bus.rb +27 -0
  41. data/lib/lux/lux.rb +103 -66
  42. data/lib/lux/mailer/mailer.rb +23 -25
  43. data/lib/lux/response/lib/file.rb +81 -0
  44. data/lib/lux/response/lib/header.rb +14 -1
  45. data/lib/lux/response/response.rb +64 -56
  46. data/lib/lux/view/cell.rb +102 -0
  47. data/lib/lux/{helper → view}/helper.rb +39 -23
  48. data/lib/lux/view/lib/cell_helpers.rb +29 -0
  49. data/lib/lux/{helper/helpers/mailer_helper.rb → view/lib/helper_modules.rb} +7 -1
  50. data/lib/lux/{template/template.rb → view/view.rb} +21 -24
  51. data/lib/lux-fw.rb +4 -2
  52. data/lib/overload/array.rb +12 -6
  53. data/lib/overload/blank.rb +0 -1
  54. data/lib/overload/dir.rb +18 -0
  55. data/lib/overload/file.rb +1 -6
  56. data/lib/overload/hash.rb +56 -13
  57. data/lib/overload/integer.rb +2 -2
  58. data/lib/overload/it.rb +4 -4
  59. data/lib/overload/object.rb +37 -8
  60. data/lib/overload/{r.rb → raise_variants.rb} +23 -4
  61. data/lib/overload/string.rb +22 -6
  62. data/misc/demo/app/cells/demo_cell.rb +12 -0
  63. data/misc/demo/app/controllers/application_controller.rb +7 -0
  64. data/misc/demo/app/controllers/main/root_controller.rb +9 -0
  65. data/misc/demo/app/routes.rb +5 -0
  66. data/misc/demo/config/application.rb +14 -0
  67. data/misc/demo/config/assets.rb +6 -0
  68. data/misc/demo/config/environment.rb +7 -0
  69. data/misc/puma_auto_tune.rb +43 -0
  70. data/misc/unicorn.rb +37 -0
  71. data/{lib/lux → plugins}/api/api.rb +46 -29
  72. data/plugins/api/lib/attr.rb +31 -0
  73. data/{lib/lux → plugins}/api/lib/dsl.rb +3 -6
  74. data/{lib/lux → plugins}/api/lib/error.rb +0 -0
  75. data/{lib/lux → plugins}/api/lib/model_api.rb +51 -12
  76. data/{lib/lux → plugins}/api/lib/response.rb +31 -17
  77. data/{bin/cli/am → plugins/db/auto_migrate/auto_migrate.rb} +18 -35
  78. data/plugins/db/helpers/array_search.rb +27 -0
  79. data/plugins/db/helpers/before_save_filters.rb +32 -0
  80. data/plugins/db/helpers/composite_primary_keys.rb +36 -0
  81. data/plugins/db/helpers/core.rb +94 -0
  82. data/plugins/db/helpers/dataset_methods.rb +138 -0
  83. data/plugins/db/helpers/enums_plugin.rb +52 -0
  84. data/plugins/db/helpers/find_precache.rb +31 -0
  85. data/plugins/db/helpers/link_objects.rb +84 -0
  86. data/plugins/db/helpers/schema_checks.rb +83 -0
  87. data/plugins/db/helpers/typero_adapter.rb +71 -0
  88. data/plugins/db/logger/config.rb +22 -0
  89. data/plugins/db/logger/lux_response_adapter.rb +10 -0
  90. data/plugins/db/paginate/helper.rb +32 -0
  91. data/plugins/db/paginate/sequel_adapter.rb +23 -0
  92. data/plugins/exceptions/simple_exception.rb +64 -0
  93. data/plugins/favicon/favicon.rb +10 -0
  94. data/plugins/html/html_form.rb +118 -0
  95. data/plugins/html/html_input.rb +98 -0
  96. data/plugins/html/html_menu.rb +79 -0
  97. data/plugins/html/input_types.rb +346 -0
  98. data/plugins/js_widgets/js_widgets.rb +15 -0
  99. data/plugins/oauth/lib/facebook.rb +35 -0
  100. data/plugins/oauth/lib/github.rb +38 -0
  101. data/plugins/oauth/lib/google.rb +41 -0
  102. data/plugins/oauth/lib/linkedin.rb +41 -0
  103. data/plugins/oauth/lib/stackexchange.rb +41 -0
  104. data/plugins/oauth/lib/twitter.rb +38 -0
  105. data/plugins/oauth/oauth.rb +42 -0
  106. data/{lib/common → plugins/policy}/policy.rb +6 -7
  107. data/tasks/loader.rb +49 -0
  108. metadata +151 -49
  109. data/bin/cli/assets +0 -41
  110. data/bin/cli/console +0 -51
  111. data/bin/cli/dev +0 -1
  112. data/bin/cli/eval +0 -24
  113. data/bin/cli/exceptions +0 -62
  114. data/bin/cli/generate +0 -86
  115. data/bin/cli/get +0 -5
  116. data/bin/cli/nginx +0 -34
  117. data/bin/cli/production +0 -1
  118. data/bin/cli/render +0 -18
  119. data/bin/cli/routes +0 -14
  120. data/bin/cli/server +0 -4
  121. data/bin/cli/stat +0 -1
  122. data/bin/cli/systemd +0 -36
  123. data/bin/txt/nginx.conf +0 -46
  124. data/bin/txt/siege-and-puma.txt +0 -3
  125. data/lib/common/base32.rb +0 -47
  126. data/lib/common/dynamic_class.rb +0 -28
  127. data/lib/common/folder_model.rb +0 -50
  128. data/lib/common/generic_model.rb +0 -62
  129. data/lib/lux/application/lib/plugs.rb +0 -10
  130. data/lib/lux/application/lib/route_test.rb +0 -64
  131. data/lib/lux/cache/lib/memcached.rb +0 -3
  132. data/lib/lux/cell/cell.rb +0 -261
  133. data/lib/lux/current/lib/static_file.rb +0 -103
  134. data/lib/lux/helper/helpers/application_helper.rb +0 -3
  135. data/lib/lux/helper/helpers/html_helper.rb +0 -3
  136. data/lib/overload/auto_loader.rb +0 -27
  137. data/lib/overload/module.rb +0 -10
  138. data/lib/overload/string_inflections.rb +0 -8
@@ -0,0 +1,241 @@
1
+ # frozen_string_literal: true
2
+
3
+ # filters stack for call
4
+ # before, before_action, :action, after
5
+
6
+ class Lux::Controller
7
+ # define maser layout
8
+ # string is template, symbol is metod pointer and lambda is lambda
9
+ class_attribute :layout
10
+
11
+ # define helper contest, by defult derived from class name
12
+ class_attribute :helper
13
+
14
+ # before and after any action filter, ignored in controllers, after is called just before render
15
+ [:before, :before_action, :before_render, :after].each { |filter| class_callback filter }
16
+
17
+ class << self
18
+ # simple shortcut allows direct call to action, bypasing call
19
+ def action *args
20
+ new.action(*args)
21
+ end
22
+
23
+ # create mock function, to enable template rendering
24
+ # mock :index, :login
25
+ def mock *args
26
+ args.each do |el|
27
+ define_method(el) { true }
28
+ end
29
+ end
30
+ end
31
+
32
+ ### INSTANCE METHODS
33
+
34
+ attr_reader :controller_action
35
+
36
+ def initialize
37
+ # before and after should be exected only once
38
+ @executed_filters = {}
39
+ @base_template = self.class.to_s.include?('::') ? self.class.to_s.sub(/Controller$/,'').underscore : self.class.to_s.sub(/Controller$/,'').downcase
40
+ end
41
+
42
+ # because we can call action multiple times
43
+ # ensure we execute filters only once
44
+ def filter fiter_name, arg=nil
45
+ return if @executed_filters[fiter_name]
46
+ @executed_filters[fiter_name] = true
47
+
48
+ Object.class_callback fiter_name, self, @controller_action
49
+ end
50
+
51
+ def cache *args, &block
52
+ Lux.cache.fetch *args, &block
53
+ end
54
+
55
+ # action(:show)
56
+ # action(:select', ['users'])
57
+ def action method_name, *args
58
+ raise ArgumentError.new('Controller action called with blank action name argument') if method_name.blank?
59
+
60
+ method_name = method_name.to_s.gsub('-', '_').gsub(/[^\w]/, '')
61
+
62
+ # dev console log
63
+ Lux.log " #{self.class.to_s}##{method_name}".light_blue
64
+
65
+ @controller_action = method_name.to_sym
66
+ if @controller_format = current.nav.format
67
+ current.nav.format = nil
68
+ end
69
+
70
+ # format error unless method found
71
+ report_not_found_error unless respond_to? method_name
72
+
73
+ catch :done do
74
+ filter :before
75
+ filter :before_action
76
+ send method_name, *args
77
+ render
78
+ end
79
+
80
+ filter :after
81
+
82
+ throw :done
83
+ rescue => e
84
+ response.body { nil }
85
+ on_error(e)
86
+ end
87
+
88
+ def error *args
89
+ args.first.nil? ? Lux::Error::AutoRaise : Lux::Error.report(*args)
90
+ end
91
+
92
+ def on_error error
93
+ raise error
94
+ end
95
+
96
+ def send_file file, opts={}
97
+ Lux::Response::File.send(file, opts)
98
+ end
99
+
100
+ # render :index
101
+ # render 'main/root/index'
102
+ # render text: 'ok'
103
+ def render name=nil, opts={}
104
+ on_error Lux::Error.new(404, '%s document Not Found' % @controller_format.to_s.upcase) if @controller_format
105
+
106
+ if name.class == Hash
107
+ opts.merge! name
108
+ else
109
+ opts[:template] = name
110
+ end
111
+
112
+ filter :before_render
113
+
114
+ opts = opts.to_opts :text, :html, :cache, :template, :json, :layout, :render_to_string, :data, :status, :ttl, :content_type
115
+
116
+ response.status opts.status if opts.status
117
+ response.content_type = opts.content_type if opts.content_type
118
+
119
+ page =
120
+ if opts.cache
121
+ Lux.cache.fetch(opts.cache, opts.ttl || 3600) { render_resolve(opts) }
122
+ else
123
+ render_resolve(opts)
124
+ end
125
+
126
+ if opts.render_to_string
127
+ page
128
+ else
129
+ response.body { page }
130
+ throw :done
131
+ end
132
+ end
133
+
134
+ def render_to_string name=nil, opts={}
135
+ opts[:render_to_string] = true
136
+ render name, opts
137
+ end
138
+
139
+ def render_javascript name=nil, opts={}
140
+ opts[:content_type] = :javascript
141
+ opts[:layout] = false
142
+ render name, opts
143
+ end
144
+
145
+ private
146
+
147
+ # delegated to current
148
+ define_method(:current) { Lux.current }
149
+ define_method(:request) { current.request }
150
+ define_method(:response) { current.response }
151
+ define_method(:params) { current.request.params }
152
+ define_method(:nav) { current.nav }
153
+ define_method(:session) { current.session }
154
+ define_method(:get?) { request.request_method == 'GET' }
155
+ define_method(:post?) { request.request_method == 'POST' }
156
+ define_method(:redirect) { |where, flash={}| current.redirect where, flash }
157
+ define_method(:etag) { |*args| current.response.etag *args }
158
+ define_method(:layout) { |arg| current.var[:controller_layout] = arg }
159
+
160
+ # called be render
161
+ def render_resolve opts
162
+ # resolve page data, without template
163
+ page_part = opts.data || render_body(opts)
164
+
165
+ # resolve data with layout
166
+ layout = opts.layout
167
+ layout = nil if layout.class == TrueClass
168
+ layout = false if current.var[:controller_layout].class == FalseClass
169
+
170
+ if layout.class == FalseClass
171
+ page_part
172
+ else
173
+ layout_define = layout || self.class.layout
174
+
175
+ layout = case layout_define
176
+ when String
177
+ 'layouts/%s' % layout_define
178
+ when Symbol
179
+ send(layout_define)
180
+ when Proc
181
+ layout_define.call
182
+ else
183
+ 'layouts/%s' % @base_template.split('/')[0]
184
+ end
185
+
186
+ Lux::View.new(layout, helper).render_part { page_part }
187
+ end
188
+ end
189
+
190
+ def render_body opts
191
+ if template = opts.template
192
+ template = template.to_s
193
+ template = "#{@base_template}/#{template}" unless template.starts_with?('/')
194
+ else
195
+ template = "#{@base_template}/#{@controller_action}"
196
+ end
197
+
198
+ Lux::View.render_part(template, helper)
199
+ end
200
+
201
+ def halt status, desc=nil
202
+ response.status = status
203
+ response.body = desc || "Hatlt code #{status}"
204
+
205
+ throw :done
206
+ end
207
+
208
+ def namespace
209
+ @base_template.split('/')[0].to_sym
210
+ end
211
+
212
+ def helper ns=nil
213
+ Lux::View::Helper.new self, :html, self.class.helper, ns
214
+ end
215
+
216
+ def report_not_found_error
217
+ raise Lux::Error.not_found unless Lux.config(:dump_errors)
218
+
219
+ err = [%[Method "#{@controller_action}" not found found in #{self.class.to_s}]]
220
+ err.push "You have defined \n- %s" % (methods - Lux::Controller.instance_methods).join("\n- ")
221
+
222
+ return Lux.error err.join("\n\n")
223
+ end
224
+
225
+ def respond_to ext=nil
226
+ fmt = @controller_format
227
+ @controller_format = nil
228
+
229
+ if ext
230
+ if ext == fmt
231
+ yield if block_given?
232
+ true
233
+ elsif fmt
234
+ on_error Lux::Error.new(404, '%s document Not Found' % fmt.to_s.upcase)
235
+ end
236
+ else
237
+ yield fmt
238
+ end
239
+ end
240
+
241
+ end
@@ -8,11 +8,11 @@ class Lux::Current
8
8
  attr_accessor :can_clear_cache
9
9
 
10
10
  attr_accessor :session, :locale
11
- attr_reader :request, :response, :params, :nav, :cookies
11
+ attr_reader :request, :response, :nav
12
12
 
13
13
  def initialize env=nil
14
14
  env ||= '/mock'
15
- env = ::Rack::MockRequest.env_for(env) if env.class == String
15
+ env = ::Rack::MockRequest.env_for(env) if env.is_a?(String)
16
16
  request = ::Rack::Request.new env
17
17
 
18
18
  # reset page cache
@@ -21,52 +21,24 @@ class Lux::Current
21
21
  @files_in_use = []
22
22
  @response = Lux::Response.new
23
23
  @request = request
24
- @cookies = {}
25
- @session = {}
24
+ @session = Lux::Current::Session.new request
26
25
 
27
- for cookie in request.env['HTTP_COOKIE'].to_s.split(/;\s*/).map{ |el| el.split('=',2) }
28
- @cookies[cookie[0]] = cookie[1]
26
+ # remove empty paramsters in GET request
27
+ if request.request_method == 'GET'
28
+ for el in request.params.keys
29
+ request.params.delete(el) if request.params[el].blank?
30
+ end
29
31
  end
30
32
 
31
- @session = JSON.parse(Crypt.decrypt(@cookies['__luxs'] || '{}')) rescue {}
32
-
33
- # check for session
34
- if Lux.dev? && request.env['HTTP_REFERER'] && request.env['HTTP_REFERER'].index(request.host) && @session.keys.length == 0
35
- puts "ERROR: There is no session set!".red
36
- end
37
-
38
- # hard sec, bind session to user agent and IP
39
- set_and_check_client_unique_hash
40
-
41
- @session = HashWithIndifferentAccess.new(@session)
33
+ # indiferent access
34
+ request.instance_variable_set(:@params, request.params.h_wia) if request.params.keys.length > 0
42
35
 
36
+ Lux::Current::EncryptParams.decrypt request.params
43
37
  ap request.params if request.post? && Lux.config(:log_to_stdout)
44
38
 
45
- @params = request.params.h_wia
46
- Lux::Current::EncryptParams.decrypt @params
47
-
48
39
  @nav = Lux::Application::Nav.new request
49
40
  end
50
41
 
51
- def files_in_use file=nil
52
- @files_in_use.push file if file && !@files_in_use.include?(file)
53
- @files_in_use
54
- end
55
-
56
- def set_and_check_client_unique_hash
57
- key = '_c'
58
- check = Crypt.sha1(@request.ip.to_s+@request.env['HTTP_USER_AGENT'].to_s)[0,10]
59
-
60
- # force type array
61
- @session.delete(key) unless @session[key].class == Array
62
-
63
- # allow 5 mins delay for IP change
64
- @session = {} if @session[key] && (@session[key][0] != check && @session[key][1].to_i < Time.now.to_i - Lux.config.session_forced_validity)
65
-
66
- # add new time stamp to every request
67
- @session[key] = [check, Time.now.to_i]
68
- end
69
-
70
42
  def domain
71
43
  host = Lux.current.request.host.split('.')
72
44
  host_country = host.pop
@@ -91,8 +63,8 @@ class Lux::Current
91
63
 
92
64
  # set current.can_clear_cache = true in production for admins
93
65
  def no_cache?
94
- @can_clear_cache ||= true if Lux.dev?
95
- (@can_clear_cache && @request.env['HTTP_CACHE_CONTROL'].to_s.downcase == 'no-cache') ? true : false
66
+ @can_clear_cache = true if Lux.dev?
67
+ @can_clear_cache && @request.env['HTTP_CACHE_CONTROL'].to_s.downcase == 'no-cache' ? true : false
96
68
  end
97
69
 
98
70
  def redirect *args
@@ -104,13 +76,10 @@ class Lux::Current
104
76
  id ||= Digest::SHA1.hexdigest caller[0] if block
105
77
 
106
78
  @once_hash ||= {}
107
- return @once_hash[id] if @once_hash.key?(id)
79
+ return if @once_hash[id]
80
+ @once_hash[id] = true
108
81
 
109
- @once_hash[id] = if block_given?
110
- yield
111
- else
112
- data || true
113
- end
82
+ block_given? ? yield : data
114
83
  end
115
84
 
116
85
  def uid
@@ -118,5 +87,22 @@ class Lux::Current
118
87
  "uid-#{Thread.current[:uid_cnt]+=1}"
119
88
  end
120
89
 
90
+ def files_in_use file=nil
91
+ if block_given?
92
+ return yield(file) unless @files_in_use.include?(file)
93
+ end
94
+
95
+ return @files_in_use unless file
96
+ return unless Lux.config(:log_to_stdout)
97
+
98
+ file = file.sub './', ''
99
+
100
+ if @files_in_use.include?(file)
101
+ true
102
+ else
103
+ @files_in_use.push file
104
+ false
105
+ end
106
+ end
121
107
  end
122
108
 
@@ -0,0 +1,72 @@
1
+ # vars
2
+ # Lux.config.session_cookie_name
3
+ # Lux.config.session_cookie_max_age
4
+ # Lux.config.session_cookie_domain
5
+
6
+ class Lux::Current::Session
7
+ def initialize request
8
+ # how long will session last if BROWSER or IP change
9
+ Lux.config.session_forced_validity ||= 10.minutes.to_i
10
+
11
+ # name of the session cookie
12
+ @cookie_name = Lux.config.session_cookie_name ||= 'lux_' + Crypt.sha1(Lux.config.secret)[0,4].downcase
13
+ @request = request
14
+ @session = JSON.parse(Crypt.decrypt(request.cookies[@cookie_name] || '{}')) rescue {}
15
+
16
+ security_check
17
+ end
18
+
19
+ def [] key
20
+ @session[key.to_s.downcase]
21
+ end
22
+
23
+ def []= key, value
24
+ @session[key.to_s.downcase] = value
25
+ end
26
+
27
+ def delete key
28
+ @session.delete key.to_s.downcase
29
+ end
30
+
31
+ def generate_cookie
32
+ encrypted = Crypt.encrypt(@session.to_json)
33
+
34
+ if @request.cookies[@cookie_name] != encrypted
35
+ cookie = []
36
+ cookie.push [@cookie_name, encrypted].join('=')
37
+ cookie.push 'Max-Age=%s' % (Lux.config.session_cookie_max_age || 1.week.to_i)
38
+ cookie.push "Path=/"
39
+ cookie.push "Domain=#{Lux.config.session_cookie_domain}" if Lux.config.session_cookie_domain
40
+ cookie.push "secure" if Lux.config.host.include?('https:')
41
+ cookie.push "HttpOnly"
42
+
43
+ cookie.join('; ')
44
+ else
45
+ nil
46
+ end
47
+ end
48
+
49
+ def merge! hash={}
50
+ hash.keys.each { |k| self[k] = hash[k] }
51
+ end
52
+
53
+ def hash
54
+ @session.dup
55
+ end
56
+
57
+ private
58
+
59
+ def security_check
60
+ key = '_c'
61
+ check = Crypt.sha1(@request.ip.to_s+@request.env['HTTP_USER_AGENT'].to_s)[0, 5]
62
+
63
+ # force type array
64
+ @session.delete(key) unless @session[key].class == Array
65
+
66
+ # allow 10 mins delay for IP change
67
+ @session = {} if @session[key] && (@session[key][0] != check && @session[key][1].to_i < Time.now.to_i - Lux.config.session_forced_validity)
68
+
69
+ # add new time stamp to every request
70
+ @session[key] = [check, Time.now.to_i]
71
+ end
72
+ end
@@ -1,24 +1,29 @@
1
1
  module Lux::DelayedJob
2
2
  extend self
3
3
 
4
- @@server = nil
4
+ attr_reader :server
5
+
6
+ @server = :memory
5
7
 
6
8
  def server= name
7
9
  adapter = "Lux::DelayedJob::#{name.to_s.capitalize}"
8
- @@server = adapter.constantize
10
+ @server = adapter.constantize
9
11
  rescue NameError
10
12
  die 'No adapter %s not found' % adapter
11
13
  end
12
14
 
13
15
  def push object, method_to_call=nil
14
- die "No DelayedJob server defined" unless @@server
15
- @@server.push [object, method_to_call]
16
+ die "No DelayedJob server defined" unless @server
17
+ @server.push [object, method_to_call]
16
18
  end
17
19
 
18
20
  def pop
19
- obj, method_to_call = @@server.pop
21
+ obj, method_to_call = @server.pop
22
+
20
23
  return unless obj
24
+
21
25
  puts "JOB POP> #{obj.to_s}.#{method_to_call}".yellow
26
+
22
27
  if method_to_call
23
28
  begin
24
29
  obj.send(method_to_call)
@@ -28,11 +33,13 @@ module Lux::DelayedJob
28
33
  else
29
34
  eval(obj)
30
35
  end
36
+
31
37
  true
32
38
  end
33
39
 
34
- def run! seconds=2
35
- puts "JOB QUE> is running for #{@@server}".green
40
+ def run! seconds=1
41
+ puts "JOB QUE> is running for #{@server}".green
42
+
36
43
  Thread.new do
37
44
  while true
38
45
  print '.'
@@ -1,14 +1,16 @@
1
1
  module Lux::DelayedJob::Memory
2
2
  extend self
3
3
 
4
- @@JOBS = []
4
+ @jobs = []
5
5
 
6
- def push(data)
7
- @@JOBS.push data
8
- Thread.new { true while Lux::DelayedJob.pop }
6
+ def push data
7
+ @jobs.push data
8
+
9
+ # delayed jobs in memory are resolved asap
10
+ Thread.new { true while pop }
9
11
  end
10
12
 
11
13
  def pop
12
- @@JOBS.shift
14
+ @jobs.shift
13
15
  end
14
16
  end
@@ -3,7 +3,7 @@ module Lux::DelayedJob
3
3
  extend self
4
4
 
5
5
  def que
6
- @@server ||= Lux.config(:redis_server)
6
+ @server ||= Lux.config(:redis_server)
7
7
  end
8
8
 
9
9
  def push(list)