Module: Stripe::TelemetryId
- Defined in:
- lib/stripe/telemetry_id.rb
Class Method Summary collapse
- .config_dir ⇒ Object
- .get ⇒ Object
-
.reset! ⇒ Object
For testing only.
Class Method Details
.config_dir ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/stripe/telemetry_id.rb', line 8 def self.config_dir if Gem.win_platform? appdata = ENV.fetch("APPDATA", nil) return nil unless appdata && !appdata.empty? ::File.join(appdata, "Stripe") else xdg = ENV.fetch("XDG_CONFIG_HOME", nil) if xdg && !xdg.empty? ::File.join(xdg, "stripe") else ::File.("~/.config/stripe") end end rescue ArgumentError nil end |
.get ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/stripe/telemetry_id.rb', line 26 def self.get return @cached_id if @loaded dir = config_dir return nil unless dir file_path = ::File.join(dir, "telemetry_id") begin content = ::File.read(file_path).strip unless content.empty? @cached_id = content return @cached_id end rescue SystemCallError # File doesn't exist or can't be read end new_id = SecureRandom.hex(16) begin ::FileUtils.mkdir_p(dir) ::File.write(file_path, new_id) rescue SystemCallError return nil end @cached_id = new_id @cached_id ensure @loaded = true end |
.reset! ⇒ Object
For testing only
60 61 62 63 |
# File 'lib/stripe/telemetry_id.rb', line 60 def self.reset! @cached_id = nil @loaded = false end |