Class: UsageStatsUtil

Inherits:
Object
  • Object
show all
Defined in:
lib/wingify/utils/usage_stats_util.rb

Overview

Manages usage statistics for the SDK. Tracks various features and configurations being used by the client. Implements Singleton pattern to ensure a single instance.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeUsageStatsUtil

Returns a new instance of UsageStatsUtil.



56
57
58
# File 'lib/wingify/utils/usage_stats_util.rb', line 56

def initialize
  @usage_stats_data = {}
end

Class Method Details

.clear_usage_statsObject



49
50
51
# File 'lib/wingify/utils/usage_stats_util.rb', line 49

def clear_usage_stats
  instance.clear_usage_stats
end

.get_usage_statsHash

Retrieves the current usage statistics.

Returns:

  • (Hash)

    Record containing boolean flags for various SDK features in use



45
46
47
# File 'lib/wingify/utils/usage_stats_util.rb', line 45

def get_usage_stats
  instance.get_usage_stats
end

.instanceUsageStatsUtil

Provides access to the singleton instance of UsageStatsUtil.

Returns:



30
31
32
# File 'lib/wingify/utils/usage_stats_util.rb', line 30

def instance
  @instance ||= new
end

.set_usage_stats(options) ⇒ Object

Sets usage statistics based on provided options. Maps various SDK features and configurations to boolean flags.

Parameters:

  • options (Hash)

    Configuration options for the SDK



38
39
40
# File 'lib/wingify/utils/usage_stats_util.rb', line 38

def set_usage_stats(options)
  instance.set_usage_stats(options)
end

Instance Method Details

#clear_usage_statsObject



115
116
117
# File 'lib/wingify/utils/usage_stats_util.rb', line 115

def clear_usage_stats
  @usage_stats_data = {}
end

#get_usage_statsObject



111
112
113
# File 'lib/wingify/utils/usage_stats_util.rb', line 111

def get_usage_stats
  @usage_stats_data
end

#set_usage_stats(options) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/wingify/utils/usage_stats_util.rb', line 60

def set_usage_stats(options)
  storage = options[:storage]
  logger = options[:logger]
  event_batching = options[:batch_event_data]
  integrations = options[:integrations]
  poll_interval = options[:poll_interval]
  vwo_meta = options[:_vwo_meta]
  gateway_service = options[:gateway_service]
  threading = options[:threading]

  data = {}

  data[:a] = SettingsService.instance.
  data[:env] = SettingsService.instance.sdk_key
  data[:ig] = 1 if integrations
  data[:eb] = 1 if event_batching
  data[:gs] = 1 if gateway_service

  # if logger has transport or transports, then it is custom logger
  if logger && (logger.key?(:transport) || logger.key?(:transports))
    data[:cl] = 1
  end

  data[:ss] = 1 if storage

  if logger && logger.key?(:level)
    data[:ll] = LogLevelToNumber.to_number(logger[:level]) || -1
  end

  data[:pi] = poll_interval if poll_interval

  if vwo_meta && vwo_meta.key?(:ea)
    data[:_ea] = 1
  end

  # check if threading is not passed or is if passed then enabled should be true
  if !threading || (threading && threading[:enabled] == true)
    data[:th] = 1
    # check if max_pool_size is passed
    if threading && threading[:max_pool_size]
      data[:th_mps] = threading[:max_pool_size]
    end
  end

  if defined?(RUBY_VERSION)
    data[:lv] = RUBY_VERSION
  end

  @usage_stats_data = data
end