posthog-rails 3.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,145 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'securerandom'
4
+
5
+ module PostHog
6
+ class InconclusiveMatchError < StandardError
7
+ end
8
+
9
+ module Utils
10
+ module_function
11
+
12
+ # public: Return a new hash with keys converted from strings to symbols
13
+ #
14
+ def symbolize_keys(hash)
15
+ hash.transform_keys(&:to_sym)
16
+ end
17
+
18
+ # public: Convert hash keys from strings to symbols in place
19
+ #
20
+ def symbolize_keys!(hash)
21
+ hash.replace symbolize_keys hash
22
+ end
23
+
24
+ # public: Return a new hash with keys as strings
25
+ #
26
+ def stringify_keys(hash)
27
+ hash.transform_keys(&:to_s)
28
+ end
29
+
30
+ # public: Returns a new hash with all the date values in the into iso8601
31
+ # strings
32
+ #
33
+ def isoify_dates(hash)
34
+ hash.transform_values do |v|
35
+ datetime_in_iso8601(v)
36
+ end
37
+ end
38
+
39
+ # public: Converts all the date values in the into iso8601 strings in place
40
+ #
41
+ def isoify_dates!(hash)
42
+ hash.replace isoify_dates hash
43
+ end
44
+
45
+ # public: Returns a uid string
46
+ #
47
+ def uid
48
+ arr = SecureRandom.random_bytes(16).unpack('NnnnnN')
49
+ arr[2] = (arr[2] & 0x0fff) | 0x4000
50
+ arr[3] = (arr[3] & 0x3fff) | 0x8000
51
+
52
+ '%08x-%04x-%04x-%04x-%04x%08x' % arr # rubocop:disable Style/FormatStringToken, Style/FormatString
53
+ end
54
+
55
+ def datetime_in_iso8601(datetime)
56
+ case datetime
57
+ when Time
58
+ time_in_iso8601 datetime
59
+ when DateTime
60
+ time_in_iso8601 datetime.to_time
61
+ when Date
62
+ date_in_iso8601 datetime
63
+ else
64
+ datetime
65
+ end
66
+ end
67
+
68
+ def time_in_iso8601(time, fraction_digits = 3)
69
+ fraction =
70
+ (('.%06i' % time.usec)[0, fraction_digits + 1] if fraction_digits.positive?) # rubocop:disable Style/FormatString
71
+
72
+ "#{time.strftime('%Y-%m-%dT%H:%M:%S')}#{fraction}#{formatted_offset(time, true, 'Z')}"
73
+ end
74
+
75
+ def date_in_iso8601(date)
76
+ date.strftime('%F')
77
+ end
78
+
79
+ def formatted_offset(time, colon = true, alternate_utc_string = nil)
80
+ (time.utc? && alternate_utc_string) ||
81
+ seconds_to_utc_offset(time.utc_offset, colon)
82
+ end
83
+
84
+ def seconds_to_utc_offset(seconds, colon = true)
85
+ format((colon ? UTC_OFFSET_WITH_COLON : UTC_OFFSET_WITHOUT_COLON), (seconds.negative? ? '-' : '+'),
86
+ seconds.abs / 3600, (seconds.abs % 3600) / 60)
87
+ end
88
+
89
+ def convert_to_datetime(value)
90
+ if value.respond_to?(:strftime)
91
+ value
92
+
93
+ elsif value.respond_to?(:to_str)
94
+ begin
95
+ DateTime.parse(value)
96
+ rescue ArgumentError
97
+ raise InconclusiveMatchError, "#{value} is not in a valid date format"
98
+ end
99
+ else
100
+ raise InconclusiveMatchError, 'The date provided must be a string or date object'
101
+ end
102
+ end
103
+
104
+ UTC_OFFSET_WITH_COLON = '%s%02d:%02d'
105
+ UTC_OFFSET_WITHOUT_COLON = UTC_OFFSET_WITH_COLON.sub(':', '')
106
+
107
+ # TODO: Rename to `valid_regex?` in future version
108
+ def is_valid_regex(regex) # rubocop:disable Naming/PredicateName
109
+ Regexp.new(regex)
110
+ true
111
+ rescue RegexpError
112
+ false
113
+ end
114
+
115
+ # public: Get value from hash by symbol key first, then string key
116
+ # Handles falsy values correctly (unlike ||)
117
+ #
118
+ # hash - Hash to lookup value in
119
+ # key - Symbol or String key to lookup
120
+ #
121
+ # Returns the value if found, nil otherwise
122
+ def get_by_symbol_or_string_key(hash, key)
123
+ symbol_key = key.to_sym
124
+ string_key = key.to_s
125
+
126
+ if hash.key?(symbol_key)
127
+ hash[symbol_key]
128
+ else
129
+ hash[string_key]
130
+ end
131
+ end
132
+
133
+ class SizeLimitedHash < Hash
134
+ def initialize(max_length, ...)
135
+ super(...)
136
+ @max_length = max_length
137
+ end
138
+
139
+ def []=(key, value)
140
+ clear if length >= @max_length
141
+ super
142
+ end
143
+ end
144
+ end
145
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PostHog
4
+ VERSION = '3.5.0'
5
+ end
data/lib/posthog.rb ADDED
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'posthog/version'
4
+ require 'posthog/defaults'
5
+ require 'posthog/utils'
6
+ require 'posthog/field_parser'
7
+ require 'posthog/client'
8
+ require 'posthog/send_worker'
9
+ require 'posthog/transport'
10
+ require 'posthog/response'
11
+ require 'posthog/logging'
12
+ require 'posthog/exception_capture'
13
+ require 'posthog/feature_flag_error'
14
+ require 'posthog/feature_flag_result'
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: posthog-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 3.5.0
5
+ platform: ruby
6
+ authors:
7
+ - PostHog
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2026-02-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: railties
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 5.2.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 5.2.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: posthog-ruby
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.5'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.5'
41
+ description: Automatic exception tracking and instrumentation for Ruby on Rails applications
42
+ using PostHog
43
+ email: hey@posthog.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - lib/posthog.rb
49
+ - lib/posthog/backoff_policy.rb
50
+ - lib/posthog/client.rb
51
+ - lib/posthog/defaults.rb
52
+ - lib/posthog/exception_capture.rb
53
+ - lib/posthog/feature_flag.rb
54
+ - lib/posthog/feature_flag_error.rb
55
+ - lib/posthog/feature_flag_result.rb
56
+ - lib/posthog/feature_flags.rb
57
+ - lib/posthog/field_parser.rb
58
+ - lib/posthog/logging.rb
59
+ - lib/posthog/message_batch.rb
60
+ - lib/posthog/noop_worker.rb
61
+ - lib/posthog/response.rb
62
+ - lib/posthog/send_feature_flags_options.rb
63
+ - lib/posthog/send_worker.rb
64
+ - lib/posthog/transport.rb
65
+ - lib/posthog/utils.rb
66
+ - lib/posthog/version.rb
67
+ homepage: https://github.com/PostHog/posthog-ruby
68
+ licenses:
69
+ - MIT
70
+ metadata:
71
+ rubygems_mfa_required: 'true'
72
+ post_install_message:
73
+ rdoc_options: []
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '3.0'
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ requirements: []
87
+ rubygems_version: 3.5.10
88
+ signing_key:
89
+ specification_version: 4
90
+ summary: PostHog integration for Rails
91
+ test_files: []