Module: CommonHelper
- Defined in:
- lib/common_helper.rb
Instance Method Summary collapse
- #add_custom_params_to_logger ⇒ Object
- #common_params_meta_log ⇒ Object
- #current_micro_service_name ⇒ Object
- #custom_meta_data_log ⇒ Object
- #custom_params_meta_log ⇒ Object
- #redis_data(key, value) ⇒ Object
- #redis_get(key) ⇒ Object
- #redis_process ⇒ Object
- #redis_set(batch_set) ⇒ Object
- #render_error(msg, status) ⇒ Object
- #required_organization ⇒ Object
- #user_agent_meta_log ⇒ Object
- #user_meta_log ⇒ Object
Instance Method Details
#add_custom_params_to_logger ⇒ Object
31 32 33 |
# File 'lib/common_helper.rb', line 31 def add_custom_params_to_logger Rails.logger.() if Rails.logger.respond_to?(:add_metadata) end |
#common_params_meta_log ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/common_helper.rb', line 47 def ll = { referer_service: params[:referer_service], jwt_cookie_hash: jwt_header_token, property: current_micro_service_name, referrer_property: params[:referer_service] } if !params[:referer_service] if request.referer && (URI(request.referer).path=="" || URI(request.referer).path=="/") if request.['REARCHID']=="rearch" ll[:referrer_property] = "Search Page" elsif request.['REARCHID']=="nonrearch" ll[:referrer_property] = "Old Home Page" end elsif request.referer && URI(request.referer).path.start_with?('/learn') ll[:referrer_property] = "Learn-Frontend" elsif request.referer && URI(request.referer).path.start_with?('/profile') ll[:referrer_property] = "Profile-Frontend" elsif request.referer && request.referer.match(/practice\/solve\//) ll[:referrer_property] = "Practice-Frontend" elsif request.referer && request.referer.match(/test\//) ll[:referrer_property] = "Test-Frontend" elsif request.referer && URI(request.referer).path.start_with?('/ask') ll[:referrer_property] = "Ask-Frontend" elsif request.referer && URI(request.referer).path.start_with?('/rankup') ll[:referrer_property] = "Rankup-Frontend" elsif request.referer && URI(request.referer).path.start_with?('/jump') ll[:referrer_property] = "Jump-Frontend" elsif request.referer && URI(request.referer).path.start_with?('/exams') ll[:referrer_property] = "Exams-Wordpress" elsif request.referer && URI(request.referer).path.start_with?('/news') ll[:referrer_property] = "News-Wordpress" end end ll end |
#current_micro_service_name ⇒ Object
2 3 4 |
# File 'lib/common_helper.rb', line 2 def current_micro_service_name @_current_micro_service_name ||= Rails.configuration.database_configuration[Rails.env]['mongodb_logger']['application_name'] end |
#custom_meta_data_log ⇒ Object
84 85 86 |
# File 'lib/common_helper.rb', line 84 def .merge!().merge!().merge!() end |
#custom_params_meta_log ⇒ Object
43 44 45 |
# File 'lib/common_helper.rb', line 43 def {c_source: params[:C_source], c_id: params[:C_id]} end |
#redis_data(key, value) ⇒ Object
23 24 25 |
# File 'lib/common_helper.rb', line 23 def redis_data(key, value) {key: key, value: value} end |
#redis_get(key) ⇒ Object
19 20 21 |
# File 'lib/common_helper.rb', line 19 def redis_get(key) (JSON.parse($redis.get(key)) || {}) rescue {} end |
#redis_process ⇒ Object
27 28 29 |
# File 'lib/common_helper.rb', line 27 def redis_process redis_set(_batch_events) end |
#redis_set(batch_set) ⇒ Object
15 16 17 |
# File 'lib/common_helper.rb', line 15 def redis_set(batch_set) batch_set.each {|key, value| d} end |
#render_error(msg, status) ⇒ Object
11 12 13 |
# File 'lib/common_helper.rb', line 11 def render_error(msg, status) render json: {:error => msg, :status => status}, :status => status end |
#required_organization ⇒ Object
6 7 8 9 |
# File 'lib/common_helper.rb', line 6 def required_organization @organization ||= Organization.find_by(namespace: params[:namespace], language: params[:language]) render_error("Organization or Language not found", 404) if @organization.nil? end |
#user_agent_meta_log ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/common_helper.rb', line 35 def ua = DeviceDetector.new(request.user_agent) device_info = [:name, :full_version, :user_agent, :os_name, :os_full_version, :device_name, :device_brand, :device_type, :known?, :bot?, :bot_name] info_data = {url: request.url, referer: request.referer} ua.methods.select {|c| info_data[c] = ua.__send__(c) if device_info.include?(c) } info_data end |
#user_meta_log ⇒ Object
88 89 90 91 92 93 |
# File 'lib/common_helper.rb', line 88 def return {} unless current_ms_user = {} [:user_id] = current_ms_user.id end |