Module: CommonHelper

Defined in:
lib/common_helper.rb

Instance Method Summary collapse

Instance Method Details

#add_custom_params_to_loggerObject



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_logObject



47
48
49
# File 'lib/common_helper.rb', line 47

def common_params_meta_log
  {referer_service: params[:referer_service]}
end

#current_micro_service_nameObject



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_logObject



51
52
53
# File 'lib/common_helper.rb', line 51

def 
  user_meta_log.merge!(user_agent_meta_log).merge!(custom_params_meta_log).merge!(common_params_meta_log)
end

#custom_params_meta_logObject



43
44
45
# File 'lib/common_helper.rb', line 43

def custom_params_meta_log
  {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_processObject



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_organizationObject



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_logObject



35
36
37
38
39
40
41
# File 'lib/common_helper.rb', line 35

def user_agent_meta_log
  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_logObject



55
56
57
58
59
# File 'lib/common_helper.rb', line 55

def user_meta_log
  return {} unless current_user
   = {}
  [:user_id] = current_user.id
end