barkibu-kb 0.16.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +7 -0
  2. data/.env.example +3 -0
  3. data/.gitignore +20 -0
  4. data/.rspec +3 -0
  5. data/.rubocop.yml +45 -0
  6. data/.ruby-version +2 -0
  7. data/.travis.yml +7 -0
  8. data/CHANGELOG.md +185 -0
  9. data/CODE_OF_CONDUCT.md +74 -0
  10. data/Gemfile +7 -0
  11. data/Gemfile.lock +182 -0
  12. data/LICENSE.txt +21 -0
  13. data/README.md +243 -0
  14. data/Rakefile +28 -0
  15. data/barkibu-kb-fake.gemspec +41 -0
  16. data/barkibu-kb.gemspec +54 -0
  17. data/bin/console +14 -0
  18. data/bin/setup +8 -0
  19. data/docker-compose.yaml +15 -0
  20. data/lib/barkibu-kb-fake.rb +1 -0
  21. data/lib/barkibu-kb.rb +33 -0
  22. data/lib/kb/cache.rb +23 -0
  23. data/lib/kb/client.rb +85 -0
  24. data/lib/kb/client_resolver.rb +62 -0
  25. data/lib/kb/concerns/as_kb_wrapper.rb +67 -0
  26. data/lib/kb/concerns.rb +1 -0
  27. data/lib/kb/errors/client_error.rb +9 -0
  28. data/lib/kb/errors/conflict_error.rb +3 -0
  29. data/lib/kb/errors/error.rb +26 -0
  30. data/lib/kb/errors/resource_not_found.rb +3 -0
  31. data/lib/kb/errors/unprocessable_entity_error.rb +3 -0
  32. data/lib/kb/errors.rb +6 -0
  33. data/lib/kb/fake/api.rb +72 -0
  34. data/lib/kb/fake/bounded_context/pet_family/breeds.rb +15 -0
  35. data/lib/kb/fake/bounded_context/pet_family/hubspot_relationship.rb +17 -0
  36. data/lib/kb/fake/bounded_context/pet_family/pet_contracts.rb +24 -0
  37. data/lib/kb/fake/bounded_context/pet_family/pet_parents.rb +98 -0
  38. data/lib/kb/fake/bounded_context/pet_family/pets.rb +84 -0
  39. data/lib/kb/fake/bounded_context/pet_family/products.rb +28 -0
  40. data/lib/kb/fake/bounded_context/rest_resource.rb +134 -0
  41. data/lib/kb/fake.rb +6 -0
  42. data/lib/kb/inflections.rb +3 -0
  43. data/lib/kb/models/assessment.rb +58 -0
  44. data/lib/kb/models/base_model.rb +40 -0
  45. data/lib/kb/models/breed.rb +39 -0
  46. data/lib/kb/models/concerns/creatable.rb +18 -0
  47. data/lib/kb/models/concerns/destroyable.rb +17 -0
  48. data/lib/kb/models/concerns/find_or_creatable.rb +19 -0
  49. data/lib/kb/models/concerns/findable.rb +19 -0
  50. data/lib/kb/models/concerns/inspectionable.rb +13 -0
  51. data/lib/kb/models/concerns/listable.rb +21 -0
  52. data/lib/kb/models/concerns/queryable.rb +34 -0
  53. data/lib/kb/models/concerns/updatable.rb +18 -0
  54. data/lib/kb/models/concerns/upsertable.rb +17 -0
  55. data/lib/kb/models/concerns.rb +10 -0
  56. data/lib/kb/models/condition.rb +32 -0
  57. data/lib/kb/models/hubspot_relationship.rb +34 -0
  58. data/lib/kb/models/pet.rb +68 -0
  59. data/lib/kb/models/pet_contract.rb +77 -0
  60. data/lib/kb/models/pet_parent.rb +111 -0
  61. data/lib/kb/models/plan.rb +44 -0
  62. data/lib/kb/models/product.rb +34 -0
  63. data/lib/kb/models/symptom.rb +25 -0
  64. data/lib/kb/models.rb +15 -0
  65. data/lib/kb/type/array_of_conditions_type.rb +13 -0
  66. data/lib/kb/type/array_of_strings_type.rb +9 -0
  67. data/lib/kb/type/array_of_symptoms_type.rb +13 -0
  68. data/lib/kb/types.rb +7 -0
  69. data/lib/kb/validators/uniqueness_validator.rb +26 -0
  70. data/lib/kb/validators.rb +1 -0
  71. data/lib/kb/version.rb +3 -0
  72. metadata +325 -0
data/lib/kb/types.rb ADDED
@@ -0,0 +1,7 @@
1
+ require 'kb/type/array_of_conditions_type'
2
+ require 'kb/type/array_of_symptoms_type'
3
+ require 'kb/type/array_of_strings_type'
4
+
5
+ ActiveModel::Type.register :array_of_symptoms, Type::ArrayOfSymptomsType
6
+ ActiveModel::Type.register :array_of_conditions, Type::ArrayOfConditionsType
7
+ ActiveModel::Type.register :array_of_strings, Type::ArrayOfStringsType
@@ -0,0 +1,26 @@
1
+ module KB
2
+ class UniquenessValidator < ActiveModel::EachValidator
3
+ def validate_each(record, attribute, value)
4
+ record.errors.add(attribute, :taken) if already_registered?(record, attribute, value)
5
+ end
6
+
7
+ private
8
+
9
+ def already_registered?(record, attribute, value)
10
+ filters = scope_filters(record, attribute, value).merge({ "#{attribute}": value })
11
+ all_records(record, filters).any? do |kb_record|
12
+ kb_record.key != record.kb_key
13
+ end
14
+ end
15
+
16
+ def all_records(record, filters)
17
+ record.kb_model.class.all(filters)
18
+ end
19
+
20
+ def scope_filters(record, _attribute, _value)
21
+ Array.wrap(options[:scope]).map do |scope_attribute|
22
+ [scope_attribute, record.send(scope_attribute)]
23
+ end.to_h
24
+ end
25
+ end
26
+ end
@@ -0,0 +1 @@
1
+ require 'kb/validators/uniqueness_validator'
data/lib/kb/version.rb ADDED
@@ -0,0 +1,3 @@
1
+ module KB
2
+ VERSION = '0.16.1'.freeze
3
+ end
metadata ADDED
@@ -0,0 +1,325 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: barkibu-kb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.16.1
5
+ platform: ruby
6
+ authors:
7
+ - Léo Figea
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-06-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: dry-configurable
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.9'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.9'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.17'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.17'
41
+ - !ruby/object:Gem::Dependency
42
+ name: byebug
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: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 12.3.3
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 12.3.3
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
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: rubocop-rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
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: simplecov
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
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: activemodel
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: 4.0.2
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: 4.0.2
139
+ - !ruby/object:Gem::Dependency
140
+ name: activerecord
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: activesupport
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: 3.0.0
160
+ type: :runtime
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: 3.0.0
167
+ - !ruby/object:Gem::Dependency
168
+ name: faraday
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: faraday-http
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: faraday_middleware
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
+ - !ruby/object:Gem::Dependency
210
+ name: i18n
211
+ requirement: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - ">="
214
+ - !ruby/object:Gem::Version
215
+ version: '0'
216
+ type: :runtime
217
+ prerelease: false
218
+ version_requirements: !ruby/object:Gem::Requirement
219
+ requirements:
220
+ - - ">="
221
+ - !ruby/object:Gem::Version
222
+ version: '0'
223
+ description: A wrapper of Barkibu's Knowledge Base Endpoint to make those entities
224
+ and their respective CRUD operations available to a ruby app
225
+ email:
226
+ - leo@barkibu.com
227
+ executables: []
228
+ extensions: []
229
+ extra_rdoc_files: []
230
+ files:
231
+ - ".env.example"
232
+ - ".gitignore"
233
+ - ".rspec"
234
+ - ".rubocop.yml"
235
+ - ".ruby-version"
236
+ - ".travis.yml"
237
+ - CHANGELOG.md
238
+ - CODE_OF_CONDUCT.md
239
+ - Gemfile
240
+ - Gemfile.lock
241
+ - LICENSE.txt
242
+ - README.md
243
+ - Rakefile
244
+ - barkibu-kb-fake.gemspec
245
+ - barkibu-kb.gemspec
246
+ - bin/console
247
+ - bin/setup
248
+ - docker-compose.yaml
249
+ - lib/barkibu-kb-fake.rb
250
+ - lib/barkibu-kb.rb
251
+ - lib/kb/cache.rb
252
+ - lib/kb/client.rb
253
+ - lib/kb/client_resolver.rb
254
+ - lib/kb/concerns.rb
255
+ - lib/kb/concerns/as_kb_wrapper.rb
256
+ - lib/kb/errors.rb
257
+ - lib/kb/errors/client_error.rb
258
+ - lib/kb/errors/conflict_error.rb
259
+ - lib/kb/errors/error.rb
260
+ - lib/kb/errors/resource_not_found.rb
261
+ - lib/kb/errors/unprocessable_entity_error.rb
262
+ - lib/kb/fake.rb
263
+ - lib/kb/fake/api.rb
264
+ - lib/kb/fake/bounded_context/pet_family/breeds.rb
265
+ - lib/kb/fake/bounded_context/pet_family/hubspot_relationship.rb
266
+ - lib/kb/fake/bounded_context/pet_family/pet_contracts.rb
267
+ - lib/kb/fake/bounded_context/pet_family/pet_parents.rb
268
+ - lib/kb/fake/bounded_context/pet_family/pets.rb
269
+ - lib/kb/fake/bounded_context/pet_family/products.rb
270
+ - lib/kb/fake/bounded_context/rest_resource.rb
271
+ - lib/kb/inflections.rb
272
+ - lib/kb/models.rb
273
+ - lib/kb/models/assessment.rb
274
+ - lib/kb/models/base_model.rb
275
+ - lib/kb/models/breed.rb
276
+ - lib/kb/models/concerns.rb
277
+ - lib/kb/models/concerns/creatable.rb
278
+ - lib/kb/models/concerns/destroyable.rb
279
+ - lib/kb/models/concerns/find_or_creatable.rb
280
+ - lib/kb/models/concerns/findable.rb
281
+ - lib/kb/models/concerns/inspectionable.rb
282
+ - lib/kb/models/concerns/listable.rb
283
+ - lib/kb/models/concerns/queryable.rb
284
+ - lib/kb/models/concerns/updatable.rb
285
+ - lib/kb/models/concerns/upsertable.rb
286
+ - lib/kb/models/condition.rb
287
+ - lib/kb/models/hubspot_relationship.rb
288
+ - lib/kb/models/pet.rb
289
+ - lib/kb/models/pet_contract.rb
290
+ - lib/kb/models/pet_parent.rb
291
+ - lib/kb/models/plan.rb
292
+ - lib/kb/models/product.rb
293
+ - lib/kb/models/symptom.rb
294
+ - lib/kb/type/array_of_conditions_type.rb
295
+ - lib/kb/type/array_of_strings_type.rb
296
+ - lib/kb/type/array_of_symptoms_type.rb
297
+ - lib/kb/types.rb
298
+ - lib/kb/validators.rb
299
+ - lib/kb/validators/uniqueness_validator.rb
300
+ - lib/kb/version.rb
301
+ homepage: https://app.barkibu.com
302
+ licenses:
303
+ - MIT
304
+ metadata:
305
+ homepage_uri: https://app.barkibu.com
306
+ post_install_message:
307
+ rdoc_options: []
308
+ require_paths:
309
+ - lib
310
+ required_ruby_version: !ruby/object:Gem::Requirement
311
+ requirements:
312
+ - - ">="
313
+ - !ruby/object:Gem::Version
314
+ version: '2.6'
315
+ required_rubygems_version: !ruby/object:Gem::Requirement
316
+ requirements:
317
+ - - ">="
318
+ - !ruby/object:Gem::Version
319
+ version: '0'
320
+ requirements: []
321
+ rubygems_version: 3.1.2
322
+ signing_key:
323
+ specification_version: 4
324
+ summary: Barkibu's Knowledge Base API sdk
325
+ test_files: []