Module: ResqueHelper
- Defined in:
- app/helpers/resque_helper.rb
Instance Method Summary collapse
- #class_filter(id, name, klasses, value) ⇒ Object
- #class_if_current(page = '') ⇒ Object
- #current_page ⇒ Object
- #current_section ⇒ Object
- #exception_filter(id, name, exceptions, value) ⇒ Object
- #find_worker(worker) ⇒ Object
- #flash_helper ⇒ Object
- #format_time(t) ⇒ Object
- #partial? ⇒ Boolean
- #path_prefix ⇒ Object
- #poll ⇒ Object
- #redis_get_size(key) ⇒ Object
- #redis_get_value_as_array(key) ⇒ Object
- #resque ⇒ Object
- #show_args(args) ⇒ Object
- #status_poll(start) ⇒ Object
- #tab(name) ⇒ Object
-
#time_filter(id, name, value) ⇒ Object
resque-cleaner helpers.
- #url(*path_parts) ⇒ Object (also: #u)
Instance Method Details
#class_filter(id, name, klasses, value) ⇒ Object
119 120 121 122 123 124 125 126 127 128 |
# File 'app/helpers/resque_helper.rb', line 119 def class_filter(id, name, klasses, value) html = "<select id=\"#{id}\" name=\"#{name}\">" html += "<option value=\"\">-</option>" klasses.each do |k| selected = k == value ? 'selected="selected"' : '' html += "<option #{selected} value=\"#{k}\">#{k}</option>" end html += "</select>" html.html_safe end |
#class_if_current(page = '') ⇒ Object
31 32 33 |
# File 'app/helpers/resque_helper.rb', line 31 def class_if_current(page = '') 'class="current"' if current_page.include? page.to_s end |
#current_page ⇒ Object
17 18 19 |
# File 'app/helpers/resque_helper.rb', line 17 def current_page url request.path_info.sub('/', '').downcase end |
#current_section ⇒ Object
13 14 15 |
# File 'app/helpers/resque_helper.rb', line 13 def current_section request.path_info.sub('/', '').split('/')[1].downcase end |
#exception_filter(id, name, exceptions, value) ⇒ Object
130 131 132 133 134 135 136 137 138 139 |
# File 'app/helpers/resque_helper.rb', line 130 def exception_filter(id, name, exceptions, value) html = "<select id=\"#{id}\" name=\"#{name}\">" html += "<option value=\"\">-</option>" exceptions.each do |ex| selected = ex == value ? 'selected="selected"' : '' html += "<option #{selected} value=\"#{ex}\">#{ex}</option>" end html += "</select>" html.html_safe end |
#find_worker(worker) ⇒ Object
40 41 42 43 44 |
# File 'app/helpers/resque_helper.rb', line 40 def find_worker(worker) first_part, *rest = worker.split(':') first_part.gsub!(/_/, '.') Resque::Worker.find("#{first_part}:#{rest.join(':')}") end |
#flash_helper ⇒ Object
3 4 5 6 7 |
# File 'app/helpers/resque_helper.rb', line 3 def flash_helper [:notice, :warning, :message, :error].collect do |key| content_tag(:div, flash[key], :class => "flash #{key}") unless flash[key].blank? end.join end |
#format_time(t) ⇒ Object
9 10 11 |
# File 'app/helpers/resque_helper.rb', line 9 def format_time(t) t.strftime("%Y/%m/%d %H:%M:%S %Z") end |
#partial? ⇒ Boolean
76 77 78 |
# File 'app/helpers/resque_helper.rb', line 76 def partial? @partial end |
#path_prefix ⇒ Object
27 28 29 |
# File 'app/helpers/resque_helper.rb', line 27 def path_prefix request.env['SCRIPT_NAME'] end |
#poll ⇒ Object
80 81 82 83 84 85 86 87 |
# File 'app/helpers/resque_helper.rb', line 80 def poll if @polling text = "Last Updated: #{Time.now.strftime("%H:%M:%S")}" else text = link_to('Live Poll', {:action => 'poll', :page => current_section}, :rel => 'poll') end "<p class='poll'>#{text}</p>".html_safe end |
#redis_get_size(key) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'app/helpers/resque_helper.rb', line 46 def redis_get_size(key) case Resque.redis.type(key) when 'none' [] when 'list' Resque.redis.llen(key) when 'set' Resque.redis.scard(key) when 'string' Resque.redis.get(key).length end end |
#redis_get_value_as_array(key) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'app/helpers/resque_helper.rb', line 59 def redis_get_value_as_array(key) case Resque.redis.type(key) when 'none' [] when 'list' Resque.list_range(key, 0, 20) when 'set' Resque.redis.smembers(key) when 'string' [Resque.redis.get(key)] end end |
#resque ⇒ Object
98 99 100 |
# File 'app/helpers/resque_helper.rb', line 98 def resque Resque end |
#show_args(args) ⇒ Object
72 73 74 |
# File 'app/helpers/resque_helper.rb', line 72 def show_args(args) Array(args).map { |a| a.inspect }.join("\n") end |
#status_poll(start) ⇒ Object
89 90 91 92 93 94 95 96 |
# File 'app/helpers/resque_helper.rb', line 89 def status_poll(start) if @polling text = "Last Updated: #{Time.now.strftime("%H:%M:%S")}" else text = link_to('Live Poll', {:action => 'status_poll', :start => start}, :rel => 'poll') end "<p class='poll'>#{text}</p>".html_safe end |
#tab(name) ⇒ Object
35 36 37 38 |
# File 'app/helpers/resque_helper.rb', line 35 def tab(name) dname = "resque/#{name.to_s.downcase}" "<li #{class_if_current(dname)}>#{link_to(name, url(dname))}</li>".html_safe end |
#time_filter(id, name, value) ⇒ Object
resque-cleaner helpers
104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'app/helpers/resque_helper.rb', line 104 def time_filter(id, name, value) html = "<select id=\"#{id}\" name=\"#{name}\">" html += "<option value=\"\">-</option>" [1, 3, 6, 12, 24].each do |h| selected = h.to_s == value ? 'selected="selected"' : '' html += "<option #{selected} value=\"#{h}\">#{h} #{h==1 ? "hour" : "hours"} ago</option>" end [3, 7, 14, 28].each do |d| selected = (d*24).to_s == value ? 'selected="selected"' : '' html += "<option #{selected} value=\"#{d*24}\">#{d} days ago</option>" end html += "</select>" html.html_safe end |
#url(*path_parts) ⇒ Object Also known as: u
21 22 23 |
# File 'app/helpers/resque_helper.rb', line 21 def url(*path_parts) [path_prefix, path_parts].join("/").squeeze('/') end |