betterplace-bi 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +10 -0
  3. data/.semaphore/semaphore.yml +26 -0
  4. data/.tool-versions +2 -0
  5. data/.utilsrc +26 -0
  6. data/Gemfile +5 -0
  7. data/README.md +76 -0
  8. data/Rakefile +37 -0
  9. data/VERSION +1 -0
  10. data/betterplace-bi.gemspec +39 -0
  11. data/lib/betterplace-bi.rb +1 -0
  12. data/lib/bi/ab_test_helper.rb +81 -0
  13. data/lib/bi/api.rb +115 -0
  14. data/lib/bi/commands/base.rb +11 -0
  15. data/lib/bi/commands/collector.rb +32 -0
  16. data/lib/bi/commands/connection.rb +25 -0
  17. data/lib/bi/commands/delete.rb +33 -0
  18. data/lib/bi/commands/serializer.rb +40 -0
  19. data/lib/bi/commands/update.rb +29 -0
  20. data/lib/bi/commands.rb +10 -0
  21. data/lib/bi/commands_job.rb +24 -0
  22. data/lib/bi/event.rb +52 -0
  23. data/lib/bi/planning_value_parser.rb +100 -0
  24. data/lib/bi/planning_value_validations.rb +15 -0
  25. data/lib/bi/railtie.rb +13 -0
  26. data/lib/bi/request_analyzer.rb +64 -0
  27. data/lib/bi/session_id.rb +11 -0
  28. data/lib/bi/shared_value.rb +102 -0
  29. data/lib/bi/tracking.rb +28 -0
  30. data/lib/bi/type_generator.rb +79 -0
  31. data/lib/bi/update_error.rb +4 -0
  32. data/lib/bi/updater.rb +61 -0
  33. data/lib/bi/version.rb +8 -0
  34. data/lib/bi.rb +27 -0
  35. data/lib/tasks/bime.rake +55 -0
  36. data/spec/bi/ab_test_helper_spec.rb +145 -0
  37. data/spec/bi/commands/collector_spec.rb +26 -0
  38. data/spec/bi/commands/connection_spec.rb +15 -0
  39. data/spec/bi/commands_job_spec.rb +24 -0
  40. data/spec/bi/commands_spec.rb +46 -0
  41. data/spec/bi/event_spec.rb +77 -0
  42. data/spec/bi/planning_value_parser_spec.rb +94 -0
  43. data/spec/bi/request_analyzer_spec.rb +75 -0
  44. data/spec/bi/shared_value_spec.rb +47 -0
  45. data/spec/bi/tracking_spec.rb +37 -0
  46. data/spec/bi/type_generator_spec.rb +44 -0
  47. data/spec/bi/updater_spec.rb +61 -0
  48. data/spec/bime_dir/.keep +0 -0
  49. data/spec/config/bi.yml +18 -0
  50. data/spec/spec_helper.rb +31 -0
  51. data/spec/support/models.rb +106 -0
  52. metadata +331 -0
@@ -0,0 +1,61 @@
1
+ require 'spec_helper'
2
+
3
+ describe BI::Updater do
4
+ let :test_object do
5
+ TestModel.new("foo")
6
+ end
7
+
8
+ let :test_value do
9
+ BI::TestModelValue.new(test_object)
10
+ end
11
+
12
+ context 'update disabled' do
13
+ it 'cannot be updated manually' do
14
+ described_class.bi_commands = double
15
+ expect(described_class.bi_commands).not_to receive(:add)
16
+ expect(Log.instance).to receive(:info)
17
+ TestModel.new('foo').bi_update
18
+ end
19
+ end
20
+
21
+ context 'update enabled' do
22
+ before do
23
+ cc.bi.attributes_update update: true
24
+ described_class.bi_commands = double(schedule_job?: false)
25
+ end
26
+
27
+ it 'can be updated manually' do
28
+ expect(described_class.bi_commands).to receive(:add).with(test_object, BI::TestModelValue)
29
+ test_object.bi_update
30
+ end
31
+
32
+ it 'can be deleted manually' do
33
+ expect(described_class.bi_commands).to receive(:add).with(test_object, BI::TestModelValue)
34
+ expect(test_object).to receive(:bi_update).and_call_original
35
+ test_object.destroy
36
+ end
37
+
38
+ it 'updates if changed' do
39
+ expect(test_object).to receive(:bi_update).and_call_original
40
+ expect(described_class.bi_commands).to receive(:add).with(test_object, BI::TestModelValue)
41
+ test_object.changed = true
42
+ test_object.save
43
+ end
44
+
45
+ it 'triggers dependent object bi updates' do
46
+ test_object.dependent = dependent_test_object = TestModel.new("bar")
47
+ expect(described_class.bi_commands).to receive(:add).with(test_object, BI::TestModelValue)
48
+ expect(described_class.bi_commands).to receive(:add).with(dependent_test_object, BI::TestModelValue)
49
+ test_object.bi_update
50
+ end
51
+
52
+ it 'schedules job after all dependent objects where collected' do
53
+ described_class.bi_commands = BI::Commands::Collector.new
54
+ test_object.dependent = dependent_test_object = TestModel.new("bar")
55
+ expect(described_class.bi_commands).to receive(:add).with(test_object, BI::TestModelValue).and_call_original
56
+ expect(described_class.bi_commands).to receive(:add).with(dependent_test_object, BI::TestModelValue).and_call_original
57
+ expect(described_class.bi_commands).to receive(:schedule_job).once
58
+ test_object.bi_update
59
+ end
60
+ end
61
+ end
File without changes
@@ -0,0 +1,18 @@
1
+ ---
2
+ test:
3
+ event_class: ABEvent
4
+ requests:
5
+ user_agents:
6
+ robot: null
7
+ mobile: null
8
+ update: no
9
+ auth:
10
+ username: bi
11
+ password: secret
12
+ clear: /api/v1/all/:id
13
+ endpoints:
14
+ BI::TestModelValue:
15
+ POST: /api/v1/tests
16
+ DELETE: /api/v1/tests/:id
17
+ bime_dir:
18
+ <%= Pathname.pwd.join('spec/bime_dir') %>
@@ -0,0 +1,31 @@
1
+ if ENV['START_SIMPLECOV'].to_i == 1
2
+ require 'simplecov'
3
+ SimpleCov.start do
4
+ add_filter "#{File.basename(File.dirname(__FILE__))}/"
5
+ end
6
+ end
7
+ require 'rspec'
8
+ begin
9
+ require 'byebug'
10
+ rescue LoadError
11
+ end
12
+
13
+ module ActiveJob
14
+ class Base
15
+ def self.queue_as(*a)
16
+ warn "Called #{__method__} with #{a.inspect}"
17
+ end
18
+ def self.retry_on(*a)
19
+ warn "Called #{__method__} with #{a.inspect}"
20
+ end
21
+ end
22
+ end
23
+
24
+ require 'complex_config'
25
+ ComplexConfig::Provider.deep_freeze = false
26
+ ComplexConfig::Provider.env = 'test'
27
+ require 'bi'
28
+
29
+ ComplexConfig::Provider.config_dir = Pathname.new(__FILE__).dirname + "config"
30
+
31
+ require_relative 'support/models'
@@ -0,0 +1,106 @@
1
+ class TestModel
2
+ def self.before_save(*)
3
+ end
4
+
5
+ def self.after_commit(*)
6
+ end
7
+
8
+ def self.before_destroy(*)
9
+ end
10
+
11
+ include BI::Updater
12
+
13
+ def logger
14
+ BI.logger
15
+ end
16
+
17
+ def initialize(id)
18
+ @id = id
19
+ @created_at = Time.now
20
+ @changed = false
21
+ @destroyed = false
22
+ end
23
+
24
+ attr_reader :id
25
+
26
+ attr_reader :created_at
27
+
28
+ attr_writer :changed
29
+
30
+ attr_accessor :dependent
31
+
32
+ def trigger_dependent_updates
33
+ return unless dependent
34
+ dependent.schedule_bi_update_job(true)
35
+ end
36
+
37
+ def changed?
38
+ @changed
39
+ end
40
+
41
+ def destroyed?
42
+ @destroyed
43
+ end
44
+
45
+ def self.find(id)
46
+ new(id)
47
+ end
48
+
49
+ def save
50
+ schedule_bi_update_job_on_change if changed?
51
+ schedule_bi_update_job
52
+ true
53
+ end
54
+
55
+ def destroy
56
+ @destroyed = true
57
+ schedule_bi_update_job_on_change
58
+ schedule_bi_update_job
59
+ true
60
+ end
61
+ end
62
+
63
+ class BI::TestModelValue
64
+ include BI::SharedValue
65
+
66
+ def self.update_class
67
+ ::TestModel
68
+ end
69
+
70
+ field type: 'string', db: 'gorm:"type:uuid;primary_key"'
71
+ def id
72
+ @object.id
73
+ end
74
+
75
+ field type: '*int64', db: 'gorm:"type:bigint"'
76
+ def number
77
+ 10 ** 10
78
+ end
79
+
80
+ field type: '*time.Time', db: bp_timestamp # ISO timestamp string, e. g. "2018-11-05T15:40:14.362219+01:00"
81
+ def created_at
82
+ iso_timestamp(@object.created_at)
83
+ end
84
+
85
+ field type: 'pq.StringArray', db: 'gorm:"type:varchar[]"'
86
+ def tags
87
+ %w[ foo bar ]
88
+ end
89
+
90
+ def ==(other)
91
+ id == other.id
92
+ end
93
+ end
94
+
95
+ class TestPlanning
96
+ def self.validates(*)
97
+ end
98
+
99
+ include BI::PlanningValueValidations
100
+
101
+ def initialize(*) end
102
+
103
+ def valid?
104
+ errors.empty?
105
+ end
106
+ end
metadata ADDED
@@ -0,0 +1,331 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: betterplace-bi
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.7.0
5
+ platform: ruby
6
+ authors:
7
+ - Florian Frank
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2024-04-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: gem_hadar
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.11.0
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.11.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: simplecov
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: byebug
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: json
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: tins
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: complex_config
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: globalid
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: excon
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: rails
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :runtime
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: sinatra
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :runtime
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: betterlog
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ type: :runtime
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
195
+ - !ruby/object:Gem::Dependency
196
+ name: mize
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - ">="
200
+ - !ruby/object:Gem::Version
201
+ version: '0'
202
+ type: :runtime
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - ">="
207
+ - !ruby/object:Gem::Version
208
+ version: '0'
209
+ description: This library contains functionality to send/store BI and AB-testing data
210
+ email: flori@ping.de
211
+ executables: []
212
+ extensions: []
213
+ extra_rdoc_files:
214
+ - README.md
215
+ - lib/betterplace-bi.rb
216
+ - lib/bi.rb
217
+ - lib/bi/ab_test_helper.rb
218
+ - lib/bi/api.rb
219
+ - lib/bi/commands.rb
220
+ - lib/bi/commands/base.rb
221
+ - lib/bi/commands/collector.rb
222
+ - lib/bi/commands/connection.rb
223
+ - lib/bi/commands/delete.rb
224
+ - lib/bi/commands/serializer.rb
225
+ - lib/bi/commands/update.rb
226
+ - lib/bi/commands_job.rb
227
+ - lib/bi/event.rb
228
+ - lib/bi/planning_value_parser.rb
229
+ - lib/bi/planning_value_validations.rb
230
+ - lib/bi/railtie.rb
231
+ - lib/bi/request_analyzer.rb
232
+ - lib/bi/session_id.rb
233
+ - lib/bi/shared_value.rb
234
+ - lib/bi/tracking.rb
235
+ - lib/bi/type_generator.rb
236
+ - lib/bi/update_error.rb
237
+ - lib/bi/updater.rb
238
+ - lib/bi/version.rb
239
+ files:
240
+ - ".gitignore"
241
+ - ".semaphore/semaphore.yml"
242
+ - ".tool-versions"
243
+ - ".utilsrc"
244
+ - Gemfile
245
+ - README.md
246
+ - Rakefile
247
+ - VERSION
248
+ - betterplace-bi.gemspec
249
+ - lib/betterplace-bi.rb
250
+ - lib/bi.rb
251
+ - lib/bi/ab_test_helper.rb
252
+ - lib/bi/api.rb
253
+ - lib/bi/commands.rb
254
+ - lib/bi/commands/base.rb
255
+ - lib/bi/commands/collector.rb
256
+ - lib/bi/commands/connection.rb
257
+ - lib/bi/commands/delete.rb
258
+ - lib/bi/commands/serializer.rb
259
+ - lib/bi/commands/update.rb
260
+ - lib/bi/commands_job.rb
261
+ - lib/bi/event.rb
262
+ - lib/bi/planning_value_parser.rb
263
+ - lib/bi/planning_value_validations.rb
264
+ - lib/bi/railtie.rb
265
+ - lib/bi/request_analyzer.rb
266
+ - lib/bi/session_id.rb
267
+ - lib/bi/shared_value.rb
268
+ - lib/bi/tracking.rb
269
+ - lib/bi/type_generator.rb
270
+ - lib/bi/update_error.rb
271
+ - lib/bi/updater.rb
272
+ - lib/bi/version.rb
273
+ - lib/tasks/bime.rake
274
+ - spec/bi/ab_test_helper_spec.rb
275
+ - spec/bi/commands/collector_spec.rb
276
+ - spec/bi/commands/connection_spec.rb
277
+ - spec/bi/commands_job_spec.rb
278
+ - spec/bi/commands_spec.rb
279
+ - spec/bi/event_spec.rb
280
+ - spec/bi/planning_value_parser_spec.rb
281
+ - spec/bi/request_analyzer_spec.rb
282
+ - spec/bi/shared_value_spec.rb
283
+ - spec/bi/tracking_spec.rb
284
+ - spec/bi/type_generator_spec.rb
285
+ - spec/bi/updater_spec.rb
286
+ - spec/bime_dir/.keep
287
+ - spec/config/bi.yml
288
+ - spec/spec_helper.rb
289
+ - spec/support/models.rb
290
+ homepage: https://github.com/betterplace/betterplace-bi
291
+ licenses:
292
+ - Apache-2.0
293
+ metadata: {}
294
+ post_install_message:
295
+ rdoc_options:
296
+ - "--title"
297
+ - Betterplace-bi -- BI library
298
+ - "--main"
299
+ - README.md
300
+ require_paths:
301
+ - lib
302
+ required_ruby_version: !ruby/object:Gem::Requirement
303
+ requirements:
304
+ - - ">="
305
+ - !ruby/object:Gem::Version
306
+ version: '0'
307
+ required_rubygems_version: !ruby/object:Gem::Requirement
308
+ requirements:
309
+ - - ">="
310
+ - !ruby/object:Gem::Version
311
+ version: '0'
312
+ requirements: []
313
+ rubygems_version: 3.4.21
314
+ signing_key:
315
+ specification_version: 4
316
+ summary: Business Intelligence library
317
+ test_files:
318
+ - spec/bi/ab_test_helper_spec.rb
319
+ - spec/bi/commands/collector_spec.rb
320
+ - spec/bi/commands/connection_spec.rb
321
+ - spec/bi/commands_job_spec.rb
322
+ - spec/bi/commands_spec.rb
323
+ - spec/bi/event_spec.rb
324
+ - spec/bi/planning_value_parser_spec.rb
325
+ - spec/bi/request_analyzer_spec.rb
326
+ - spec/bi/shared_value_spec.rb
327
+ - spec/bi/tracking_spec.rb
328
+ - spec/bi/type_generator_spec.rb
329
+ - spec/bi/updater_spec.rb
330
+ - spec/spec_helper.rb
331
+ - spec/support/models.rb