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 |
# File 'lib/common_helper.rb', line 47 def {referer_service: params[:referer_service]} 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
51 52 53 |
# File 'lib/common_helper.rb', line 51 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
55 56 57 58 59 |
# File 'lib/common_helper.rb', line 55 def return {} unless current_ms_user = {} [:user_id] = current_ms_user.id end |