Module: MongodbLogger::MustacheHelpers
- Includes:
- Rack::Utils
- Included in:
- MustacheHelpersObj
- Defined in:
- lib/mongodb_logger/server/helpers/mustache_helpers.rb
Instance Method Summary collapse
- #class_if_current(path = '') ⇒ Object
- #current_page ⇒ Object
- #log_data(log) ⇒ Object
- #log_data_json(log) ⇒ Object
- #path_prefix ⇒ Object
- #pretty_hash(hash) ⇒ Object
- #string_from_log_message(message) ⇒ Object
- #url_path(*path_parts) ⇒ Object
Instance Method Details
#class_if_current(path = '') ⇒ Object
18 19 20 |
# File 'lib/mongodb_logger/server/helpers/mustache_helpers.rb', line 18 def class_if_current(path = '') 'class="active"' if current_page[0, path.size] == path end |
#current_page ⇒ Object
14 15 16 |
# File 'lib/mongodb_logger/server/helpers/mustache_helpers.rb', line 14 def current_page url_path request.path_info.sub('/','') end |
#log_data(log) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/mongodb_logger/server/helpers/mustache_helpers.rb', line 36 def log_data(log) main_msg = "No message" if log['messages'] && log['messages']['info'] main_msg = (log['messages']['info']).truncate(300, :separator => ' ') end if log['is_exception'] && log['messages'] && log['messages']['error'] main_msg = (log['messages']['error']).truncate(300, :separator => ' ') end # return value { '_id' => log['_id'].to_s, 'web_url' => url_path("log/#{log['_id']}"), 'main_msg' => main_msg, 'is_exception_class' => (log['is_exception'] ? 'failure' : 'success'), 'method' => log['method'], 'url' => log['url'], 'request_time' => log['request_time'], 'ip' => log['ip'], 'params' => pretty_hash(log['params']) } end |
#log_data_json(log) ⇒ Object
58 59 60 |
# File 'lib/mongodb_logger/server/helpers/mustache_helpers.rb', line 58 def log_data_json(log) MultiJson.dump(log_data(log)) end |
#path_prefix ⇒ Object
10 11 12 |
# File 'lib/mongodb_logger/server/helpers/mustache_helpers.rb', line 10 def path_prefix request.env['SCRIPT_NAME'] end |
#pretty_hash(hash) ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/mongodb_logger/server/helpers/mustache_helpers.rb', line 26 def pretty_hash(hash) begin Marshal::dump(hash) h(hash.to_yaml).gsub(" ", " ") rescue Exception => e # errors from Marshal or YAML # Object couldn't be dumped, perhaps because of singleton methods -- this is the fallback h(hash.inspect) end end |
#string_from_log_message(message) ⇒ Object
22 23 24 |
# File 'lib/mongodb_logger/server/helpers/mustache_helpers.rb', line 22 def () .is_a?(Array) ? .join("\n") : .to_s end |
#url_path(*path_parts) ⇒ Object
6 7 8 |
# File 'lib/mongodb_logger/server/helpers/mustache_helpers.rb', line 6 def url_path(*path_parts) [ path_prefix, path_parts ].join("/").squeeze('/') end |