Module: MagentWeb::MongoHelper
- Included in:
- App
- Defined in:
- lib/magent_web/mongo_helper.rb
Instance Method Summary collapse
- #channel_name_for(queue_id) ⇒ Object
- #document_list(collection, query = {}) ⇒ Object
- #file_size(database) ⇒ Object
- #humanize(v, quote = false) ⇒ Object
- #humanize_messages(messages) ⇒ Object
- #normalize_stats(stats) ⇒ Object
- #query_options ⇒ Object
- #queue_path(queue) ⇒ Object
- #queues ⇒ Object
- #server_status ⇒ Object
Instance Method Details
#channel_name_for(queue_id) ⇒ Object
84 85 86 |
# File 'lib/magent_web/mongo_helper.rb', line 84 def channel_name_for(queue_id) queue_id.to_s.match("magent\.([^\.]+)")[1] end |
#document_list(collection, query = {}) ⇒ Object
23 24 25 |
# File 'lib/magent_web/mongo_helper.rb', line 23 def document_list(collection, query = {}) collection.find(query, ) end |
#file_size(database) ⇒ Object
27 28 29 |
# File 'lib/magent_web/mongo_helper.rb', line 27 def file_size(database) "%0.2f MB" % (database.stats["fileSize"] / 1024**2) end |
#humanize(v, quote = false) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/magent_web/mongo_helper.rb', line 54 def humanize(v, quote = false) if v.nil? && quote "null" elsif v.kind_of?(Hash) buffer = "" v.each do |k,v| buffer << "#{k.inspect}: #{v.inspect} <br />" end buffer elsif v.kind_of?(Array) v.map{|e| e.nil? ? "null" : e }.join("<br />") elsif v.kind_of?(Time) v.strftime("%d %B %Y %H:%M:%S").inspect elsif quote v.inspect else v end end |
#humanize_messages(messages) ⇒ Object
74 75 76 77 78 79 80 81 82 |
# File 'lib/magent_web/mongo_helper.rb', line 74 def () return "" if !.kind_of?(Array) .map do |e| name = e.first args = e.last.join(", ") "#{name}(#{args})" end.join(" -> ") end |
#normalize_stats(stats) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/magent_web/mongo_helper.rb', line 31 def normalize_stats(stats) r={} stats.each do |k,v| if k =~ /size/i if v.kind_of?(Hash) v.each do |ki,vi| v[ki]="%0.2f MB" % (vi.to_f/1024**2) end r[k] = v else r[k]="%0.2f MB" % (v.to_f/1024**2) end else r[k]=v end end r end |
#query_options ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/magent_web/mongo_helper.rb', line 14 def = {} [:limit] = params[:limit].nil? ? 25 : params[:limit].to_i [:sort] = [["_id", (params[:descending] == "true" ? 'descending' : 'ascending')]] [:skip] = params[:skip].nil? ? 0 : params[:skip].to_i end |
#queue_path(queue) ⇒ Object
88 89 90 91 92 |
# File 'lib/magent_web/mongo_helper.rb', line 88 def queue_path(queue) queue = queue.name if !queue.kind_of?(String) "#{ENV["MAGENT_WEB_PATH"]}/queues/#{queue}" end |