Module: Que::Web::Helpers

Defined in:
lib/que/web.rb

Instance Method Summary collapse

Instance Method Details

#active_class(pattern) ⇒ Object



171
172
173
174
175
# File 'lib/que/web.rb', line 171

def active_class(pattern)
  if request.path.match pattern
    "active"
  end
end

#flashObject



199
200
201
202
# File 'lib/que/web.rb', line 199

def flash
  @sweep_flash = true
  session[FLASH_KEY] ||= {}
end

#format_args(job) ⇒ Object



177
178
179
# File 'lib/que/web.rb', line 177

def format_args(job)
  truncate job.args.map(&:inspect).join(', ')
end

#format_error(job) ⇒ Object



181
182
183
184
185
# File 'lib/que/web.rb', line 181

def format_error(job)
  return unless job.last_error_message
  line = job.last_error_message.lines.first || ''
  truncate line, 30
end

#html_escape(text) ⇒ Object Also known as: h



209
210
211
212
213
# File 'lib/que/web.rb', line 209

def html_escape(text)
  return if text.nil?

  CGI.escape_html(text)
end


146
147
148
# File 'lib/que/web.rb', line 146

def link_to(path)
  to path_with_search(path)
end

#path_with_search(path) ⇒ Object



150
151
152
153
# File 'lib/que/web.rb', line 150

def path_with_search(path)
  path += "?search=#{search_param}" if search_param
  path
end

#relative_time(time) ⇒ Object



187
188
189
# File 'lib/que/web.rb', line 187

def relative_time(time)
  %{<time class="timeago" datetime="#{time.utc.iso8601}">#{time.utc}</time>}
end

#root_pathObject



142
143
144
# File 'lib/que/web.rb', line 142

def root_path
  "#{env['SCRIPT_NAME']}/"
end

#searchObject



155
156
157
158
# File 'lib/que/web.rb', line 155

def search
  return '%' unless search_param
  "%#{search_param}%"
end

#search_paramObject



165
166
167
168
169
# File 'lib/que/web.rb', line 165

def search_param
  sanitised = (params['search'] || '').gsub(/[^0-9a-z:]/i, '')
  return if sanitised.empty?
  sanitised
end

#search_running(jobs) ⇒ Object



160
161
162
163
# File 'lib/que/web.rb', line 160

def search_running(jobs)
  return jobs unless search_param
  jobs.select { |job| job.fetch(:job_class).include? search_param }
end

#set_flash(level, val) ⇒ Object



204
205
206
207
# File 'lib/que/web.rb', line 204

def set_flash(level, val)
  hash = session[FLASH_KEY] ||= {}
  hash[level] = val
end

#truncate(str, len = 200) ⇒ Object



191
192
193
194
195
196
197
# File 'lib/que/web.rb', line 191

def truncate(str, len=200)
  if str.length > len
    str[0..len] + '...'
  else
    str
  end
end