class Oxidized::API::WebApp
Private Instance Methods
diff_view(diff)
click to toggle source
method the give diffs in separate view (the old and the new) as in github
# File lib/oxidized/web/webapp.rb, line 288 def diff_view diff old_diff = [] new_diff = [] detection = ::CharlockHolmes::EncodingDetector.detect(diff) utf8_encoded_content = ::CharlockHolmes::Converter.convert diff, detection[:encoding], 'UTF-8' HTMLEntities.new.encode(utf8_encoded_content).each_line do |line| if /^\+/.match(line) new_diff.push(line) elsif /^\-/.match(line) old_diff.push(line) else new_diff.push(line) old_diff.push(line) end end length_o = old_diff.count length_n = new_diff.count for i in 0..[length_o, length_n].max if i > [length_o, length_n].min break end if (/^\-.*/.match(old_diff[i])) && !(/^\+.*/.match(new_diff[i])) # tag removed latter to add color syntax insert = 'empty_line' # ugly way to avoid asymmetry if at display the line takes 2 line on the screen insert = " \n" new_diff.insert(i, insert) length_n += 1 elsif !(/^\-.*/.match(old_diff[i])) && (/^\+.*/.match(new_diff[i])) insert = 'empty_line' insert = " \n" old_diff.insert(i, insert) length_o += 1 end end { old_diff: old_diff, new_diff: new_diff } end
nodes()
click to toggle source
# File lib/oxidized/web/webapp.rb, line 245 def nodes settings.nodes end
out(template = :text)
click to toggle source
# File lib/oxidized/web/webapp.rb, line 230 def out template = :text if @json or params[:format] == 'json' if @data.is_a?(String) json @data.lines else json @data end elsif template == :text or params[:format] == 'text' content_type :text @data else haml template, layout: true end end
route_parse(param)
click to toggle source
# File lib/oxidized/web/webapp.rb, line 249 def route_parse param json = false if param.respond_to?(:to_str) e = param.split '.' else e = params[param].split '.' end if e.last == 'json' e.pop json = true end [e.join('.'), json] end
time_from_now(date)
click to toggle source
give the time enlapsed between now and a date
# File lib/oxidized/web/webapp.rb, line 264 def time_from_now date if date # if the + is missing unless date.include? '+' date.insert(21, '+') end date = DateTime.parse date now = DateTime.now.new_offset(0) t = ((now - date) * 24 * 60 * 60).to_i mm, ss = t.divmod(60) hh, mm = mm.divmod(60) dd, hh = hh.divmod(24) if dd.positive? date = "#{dd} days #{hh} hours ago" elsif hh.positive? date = "#{hh} hours #{mm} min ago" else date = "#{mm} min #{ss} sec ago" end end date end