db_fuel 2.2.0 → 2.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 96e96867b0df819c4a00e446f47fe586d48a12da5798e0743b8895940ff126af
4
- data.tar.gz: fed359df2f9d2512740e39ad65fd5e6fabed287fb1403bed525fe4b0af5bdf0d
3
+ metadata.gz: 6153de5e6e01820bf9c5b0bb67260ab4aa71198a82b775e1f34c771d4a520140
4
+ data.tar.gz: a95690fcf11543f4fdeb247190e993efe53c05f946ec866eb8e482378fd75e68
5
5
  SHA512:
6
- metadata.gz: 72382d90f1368e9ac9d4cb35a64b60235ec5822568be79ce5a92fd956e41eed9a139d6cf9681585af24932c4e5ff7759e8cb4b36eb2e1cefa0f20e120baa478c
7
- data.tar.gz: d127c76c1d94e35e2c8b46aff67c6e80735b9381348ae3fb984e983b67701889b0448d5ae00e53218ec52453d7a7e1d7f3df39feaefaaa139652fe35e36fbaff
6
+ metadata.gz: e446d0a87845c79afbcfb1d20859b6fc363e39cf6069c10e833f8524a161f66f4ef254282294e0188193f4e41054877b18b781077287f2c19bb10d1a03cba545
7
+ data.tar.gz: 172f25cbc3503861f0f82ffa20885697b7a1b46fd04f44d80a8a565f6781e7d72f1e714a57aab98ca2245e2fcbf44667bfb692a88e69f2021aedc8eba92e6a73
@@ -0,0 +1,73 @@
1
+ version: 2.1
2
+
3
+ orbs:
4
+ status_to_ms_teams: bluemarblepayroll/status_to_ms_teams_pure_bash@1.0.0
5
+
6
+ jobs:
7
+ build:
8
+ parameters:
9
+ use-bundler-cache:
10
+ type: boolean
11
+ default: true
12
+
13
+ docker:
14
+ - image: circleci/ruby:2.6.6-buster
15
+ environment:
16
+ FORBID_FOCUSED_SPECS: 1
17
+ AR_VERSION: 5
18
+ working_directory: ~/db_fuel
19
+ steps:
20
+ - checkout
21
+ - run: cp spec/config/database.yaml.ci spec/config/database.yaml
22
+
23
+ # TODO: wrap bundler caching logic into an Orb:
24
+ - when:
25
+ condition: << parameters.use-bundler-cache >>
26
+ steps:
27
+ - restore_cache:
28
+ key: v1.0.0-build-ruby-dependency-cache-{{ checksum "db_fuel.gemspec" }}-{{ checksum "Gemfile" }}-{{ checksum ".ruby-version" }}
29
+
30
+ - run: bundle install --path vendor/bundle
31
+
32
+ - when:
33
+ condition: << parameters.use-bundler-cache >>
34
+ steps:
35
+ - save_cache:
36
+ key: v1.0.0-build-ruby-dependency-cache-{{ checksum "db_fuel.gemspec" }}-{{ checksum "Gemfile" }}-{{ checksum ".ruby-version" }}
37
+ paths:
38
+ - vendor/bundle
39
+
40
+ - store_artifacts:
41
+ path: Gemfile.lock
42
+
43
+ - run: bundle exec rubocop
44
+
45
+ - run: COVERAGE=true bundle exec rspec -r rspec_junit_formatter --format progress --format RspecJunitFormatter -o test-results/rspec/results.xml
46
+
47
+ - store_test_results:
48
+ path: test-results
49
+
50
+ - store_artifacts:
51
+ path: coverage
52
+
53
+ - status_to_ms_teams/report:
54
+ webhook_url: $MS_TEAMS_WEBHOOK_URL
55
+
56
+ workflows:
57
+ version: 2.1
58
+ build:
59
+ jobs:
60
+ - build:
61
+ context: org-global
62
+ monthly-gem-dependency-refresh-check:
63
+ triggers:
64
+ - schedule:
65
+ cron: '0 0 1 * *'
66
+ filters:
67
+ branches:
68
+ only:
69
+ - master
70
+ jobs:
71
+ - build:
72
+ context: org-global
73
+ use-bundler-cache: false
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # DB Fuel
2
2
 
3
- [![Gem Version](https://badge.fury.io/rb/db_fuel.svg)](https://badge.fury.io/rb/db_fuel) [![Build Status](https://travis-ci.org/bluemarblepayroll/db_fuel.svg?branch=master)](https://travis-ci.org/bluemarblepayroll/db_fuel) [![Maintainability](https://api.codeclimate.com/v1/badges/21945483950d9c35fabb/maintainability)](https://codeclimate.com/github/bluemarblepayroll/db_fuel/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/21945483950d9c35fabb/test_coverage)](https://codeclimate.com/github/bluemarblepayroll/db_fuel/test_coverage) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
3
+ [![CircleCI](https://circleci.com/bb/bluemarble-ondemand/db_fuel/tree/master.svg?style=svg&circle-token=f1b2aed3fa173235db39da671c5b5db22e061609)](https://circleci.com/bb/bluemarble-ondemand/db_fuel/tree/master)
4
4
 
5
5
  This library is a plugin for [Burner](https://github.com/bluemarblepayroll/burner). Burner, by itself, cannot use a database. So, if you wish to use a database as a data source or as a target for mutation then you need to add a library similar to this.
6
6
 
@@ -421,7 +421,7 @@ Note: ensure you have proper authorization before trying to publish new versions
421
421
  After code changes have successfully gone through the Pull Request review process then the following steps should be followed for publishing new versions:
422
422
 
423
423
  1. Merge Pull Request into master
424
- 2. Update `lib/db_fuel/version.rb` using [semantic versioning](https://semver.org/)
424
+ 2. Update `version.rb` using [semantic versioning](https://semver.org/)
425
425
  3. Install dependencies: `bundle`
426
426
  4. Update `CHANGELOG.md` with release notes
427
427
  5. Commit & push master to remote and ensure CI builds master successfully
data/db_fuel.gemspec CHANGED
@@ -16,15 +16,7 @@ Gem::Specification.new do |s|
16
16
  s.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
17
  s.bindir = 'exe'
18
18
  s.executables = %w[]
19
- s.homepage = 'https://github.com/bluemarblepayroll/db_fuel'
20
19
  s.license = 'MIT'
21
- s.metadata = {
22
- 'bug_tracker_uri' => 'https://github.com/bluemarblepayroll/db_fuel/issues',
23
- 'changelog_uri' => 'https://github.com/bluemarblepayroll/db_fuel/blob/master/CHANGELOG.md',
24
- 'documentation_uri' => 'https://www.rubydoc.info/gems/db_fuel',
25
- 'homepage_uri' => s.homepage,
26
- 'source_code_uri' => s.homepage
27
- }
28
20
 
29
21
  s.required_ruby_version = '>= 2.5'
30
22
 
@@ -51,6 +43,7 @@ Gem::Specification.new do |s|
51
43
  s.add_development_dependency('pry', '~>0')
52
44
  s.add_development_dependency('rake', '~> 13')
53
45
  s.add_development_dependency('rspec', '~> 3.8')
46
+ s.add_development_dependency('rspec_junit_formatter')
54
47
  s.add_development_dependency('rubocop', '~>1.7.0')
55
48
  s.add_development_dependency('simplecov', '~>0.18.5')
56
49
  s.add_development_dependency('simplecov-console', '~>0.7.0')
@@ -19,12 +19,11 @@ module DbFuel
19
19
  NOW_TYPE = 'r/value/now'
20
20
  UPDATED_AT = :updated_at
21
21
 
22
- attr_reader :attribute_renderers,
23
- :db_provider,
22
+ attr_reader :db_provider,
24
23
  :debug,
25
24
  :keys_register,
26
25
  :resolver,
27
- :attribute_renderers_set
26
+ :record_transformer
28
27
 
29
28
  def initialize(
30
29
  table_name:,
@@ -37,10 +36,14 @@ module DbFuel
37
36
  )
38
37
  super(name: name, register: register)
39
38
 
40
- @keys_register = keys_register.to_s
41
- @resolver = Objectable.resolver(separator: separator)
42
- @attribute_renderers_set = Modeling::AttributeRendererSet.new(resolver: resolver,
43
- attributes: attributes)
39
+ @keys_register = keys_register.to_s
40
+ @resolver = Objectable.resolver(separator: separator)
41
+
42
+ @record_transformer = Modeling::RecordTransformer.new(
43
+ resolver: resolver,
44
+ attributes: attributes
45
+ )
46
+
44
47
  @db_provider = DbProvider.new(table_name)
45
48
  @debug = debug || false
46
49
  end
@@ -79,12 +79,7 @@ module DbFuel
79
79
  keys = resolve_key_set(output, payload)
80
80
 
81
81
  total_rows_affected = payload[register].inject(0) do |memo, row|
82
- where_object = attribute_renderers_set.transform(
83
- unique_attribute_renderers,
84
- row,
85
- payload.time
86
- )
87
-
82
+ where_object = unique_record_transformer.transform(row, payload.time)
88
83
  rows_affected = update(output, row, payload.time, where_object, keys)
89
84
 
90
85
  debug_detail(output, "Individual Rows Affected: #{rows_affected}")
@@ -21,7 +21,7 @@ module DbFuel
21
21
  # Expected Payload[register] input: array of objects
22
22
  # Payload[register] output: array of objects.
23
23
  class Upsert < Base
24
- attr_reader :primary_keyed_column, :timestamps, :unique_attribute_renderers
24
+ attr_reader :primary_keyed_column, :timestamps, :unique_record_transformer
25
25
 
26
26
  # Arguments:
27
27
  # name: name of the job within the Burner::Pipeline.
@@ -80,8 +80,10 @@ module DbFuel
80
80
 
81
81
  @primary_keyed_column = Modeling::KeyedColumn.make(primary_keyed_column, nullable: true)
82
82
 
83
- @unique_attribute_renderers = attribute_renderers_set
84
- .make_renderers(unique_attributes)
83
+ @unique_record_transformer = Modeling::RecordTransformer.new(
84
+ resolver: resolver,
85
+ attributes: unique_attributes
86
+ )
85
87
 
86
88
  @timestamps = timestamps
87
89
 
@@ -114,7 +116,7 @@ module DbFuel
114
116
  protected
115
117
 
116
118
  def find_record(output, row, time)
117
- unique_row = attribute_renderers_set.transform(unique_attribute_renderers, row, time)
119
+ unique_row = unique_record_transformer.transform(row, time)
118
120
 
119
121
  first_sql = db_provider.first_sql(unique_row)
120
122
 
@@ -132,15 +134,13 @@ module DbFuel
132
134
  end
133
135
 
134
136
  def insert_record(output, row, time, keys = Set.new)
135
- dynamic_attrs = if timestamps
136
- # doing an INSERT and timestamps should be set
137
- # set the created_at and updated_at fields
138
- attribute_renderers_set.timestamp_created_attribute_renderers
139
- else
140
- attribute_renderers_set.attribute_renderers
141
- end
142
-
143
- set_object = attribute_renderers_set.transform(dynamic_attrs, row, time, keys)
137
+ set_object = record_transformer.transform(
138
+ row,
139
+ time,
140
+ keys: keys,
141
+ created_at: timestamps,
142
+ updated_at: timestamps
143
+ )
144
144
 
145
145
  insert_sql = db_provider.insert_sql(set_object)
146
146
 
@@ -176,15 +176,12 @@ module DbFuel
176
176
 
177
177
  # Updates one or many records depending on where_object passed
178
178
  def update(output, row, time, where_object, keys)
179
- dynamic_attrs = if timestamps
180
- # doing an UPDATE and timestamps should be set,
181
- # modify the updated_at field, don't modify the created_at field
182
- attribute_renderers_set.timestamp_updated_attribute_renderers
183
- else
184
- attribute_renderers_set.attribute_renderers
185
- end
186
-
187
- set_object = attribute_renderers_set.transform(dynamic_attrs, row, time, keys)
179
+ set_object = record_transformer.transform(
180
+ row,
181
+ time,
182
+ keys: keys,
183
+ updated_at: timestamps
184
+ )
188
185
 
189
186
  update_sql = db_provider.update_sql(set_object, where_object)
190
187
 
@@ -12,10 +12,10 @@ module DbFuel
12
12
  # Creates attribute renderers based on attributes passed.
13
13
  # Also constains methods to transform attribute renderers
14
14
  # and include timestamp attributes if needed.
15
- class AttributeRendererSet # :nodoc:
15
+ class RecordTransformer # :nodoc:
16
16
  NOW_TYPE = 'r/value/now'
17
- CREATED_AT = :created_at
18
- UPDATED_AT = :updated_at
17
+ CREATED_AT = 'created_at'
18
+ UPDATED_AT = 'updated_at'
19
19
 
20
20
  attr_reader :attribute_renderers, :resolver
21
21
 
@@ -28,22 +28,48 @@ module DbFuel
28
28
  freeze
29
29
  end
30
30
 
31
- # Adds the attributes for created_at and updated_at to the currrent attribute renderers.
32
- def timestamp_created_attribute_renderers
33
- timestamp_attributes = [created_at_timestamp_attribute, updated_at_timestamp_attribute]
31
+ def transform(row, time, keys: Set.new, created_at: false, updated_at: false)
32
+ dynamic_attributes, all_keys = make_dynamic_attributes(
33
+ keys: keys,
34
+ created_at: created_at,
35
+ updated_at: updated_at
36
+ )
37
+
38
+ dynamic_attributes.each_with_object({}) do |attribute_renderer, memo|
39
+ next if all_keys.any? && all_keys.exclude?(attribute_renderer.key)
40
+
41
+ value = attribute_renderer.transform(row, time)
34
42
 
35
- timestamp_attributes.map do |a|
36
- Burner::Modeling::AttributeRenderer.new(a, resolver)
37
- end + attribute_renderers
43
+ resolver.set(memo, attribute_renderer.key, value)
44
+ end
38
45
  end
39
46
 
40
- # Adds the attribute for updated_at to the currrent attribute renderers.
41
- def timestamp_updated_attribute_renderers
42
- timestamp_attributes = [updated_at_timestamp_attribute]
47
+ private
48
+
49
+ def make_dynamic_attributes(keys:, created_at:, updated_at:)
50
+ dynamic_attributes = attribute_renderers
51
+ all_keys = keys
52
+
53
+ if created_at
54
+ dynamic_attributes += [
55
+ Burner::Modeling::AttributeRenderer.new(created_at_timestamp_attribute, resolver)
56
+ ]
57
+
58
+ all_keys += [CREATED_AT] if keys.any?
59
+ end
60
+
61
+ if updated_at
62
+ dynamic_attributes += [
63
+ Burner::Modeling::AttributeRenderer.new(updated_at_timestamp_attribute, resolver)
64
+ ]
65
+
66
+ all_keys += [UPDATED_AT] if keys.any?
67
+ end
43
68
 
44
- timestamp_attributes.map do |a|
45
- Burner::Modeling::AttributeRenderer.new(a, resolver)
46
- end + attribute_renderers
69
+ [
70
+ dynamic_attributes,
71
+ all_keys
72
+ ]
47
73
  end
48
74
 
49
75
  def make_renderers(attributes)
@@ -52,16 +78,6 @@ module DbFuel
52
78
  .map { |a| Burner::Modeling::AttributeRenderer.new(a, resolver) }
53
79
  end
54
80
 
55
- def transform(attribute_renderers, row, time, keys = Set.new)
56
- attribute_renderers.each_with_object({}) do |attribute_renderer, memo|
57
- next if keys.any? && keys.exclude?(attribute_renderer.key)
58
-
59
- value = attribute_renderer.transform(row, time)
60
-
61
- resolver.set(memo, attribute_renderer.key, value)
62
- end
63
- end
64
-
65
81
  def created_at_timestamp_attribute
66
82
  timestamp_attribute(CREATED_AT)
67
83
  end
@@ -8,4 +8,4 @@
8
8
  #
9
9
 
10
10
  require_relative 'modeling/keyed_column'
11
- require_relative 'modeling/attribute_renderer_set'
11
+ require_relative 'modeling/record_transformer'
@@ -8,5 +8,5 @@
8
8
  #
9
9
 
10
10
  module DbFuel
11
- VERSION = '2.2.0'
11
+ VERSION = '2.2.1'
12
12
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: db_fuel
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Ruggio
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2021-05-23 00:00:00.000000000 Z
12
+ date: 2021-12-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -157,6 +157,20 @@ dependencies:
157
157
  - - "~>"
158
158
  - !ruby/object:Gem::Version
159
159
  version: '3.8'
160
+ - !ruby/object:Gem::Dependency
161
+ name: rspec_junit_formatter
162
+ requirement: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ type: :development
168
+ prerelease: false
169
+ version_requirements: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
160
174
  - !ruby/object:Gem::Dependency
161
175
  name: rubocop
162
176
  requirement: !ruby/object:Gem::Requirement
@@ -222,12 +236,12 @@ executables: []
222
236
  extensions: []
223
237
  extra_rdoc_files: []
224
238
  files:
239
+ - ".circleci/config.yml"
225
240
  - ".editorconfig"
226
241
  - ".gitignore"
227
242
  - ".rubocop.yml"
228
243
  - ".ruby-version"
229
244
  - ".tool-versions"
230
- - ".travis.yml"
231
245
  - CHANGELOG.md
232
246
  - CODE_OF_CONDUCT.md
233
247
  - Gemfile
@@ -251,18 +265,13 @@ files:
251
265
  - lib/db_fuel/library/dbee/query.rb
252
266
  - lib/db_fuel/library/dbee/range.rb
253
267
  - lib/db_fuel/modeling.rb
254
- - lib/db_fuel/modeling/attribute_renderer_set.rb
255
268
  - lib/db_fuel/modeling/keyed_column.rb
269
+ - lib/db_fuel/modeling/record_transformer.rb
256
270
  - lib/db_fuel/version.rb
257
- homepage: https://github.com/bluemarblepayroll/db_fuel
271
+ homepage:
258
272
  licenses:
259
273
  - MIT
260
- metadata:
261
- bug_tracker_uri: https://github.com/bluemarblepayroll/db_fuel/issues
262
- changelog_uri: https://github.com/bluemarblepayroll/db_fuel/blob/master/CHANGELOG.md
263
- documentation_uri: https://www.rubydoc.info/gems/db_fuel
264
- homepage_uri: https://github.com/bluemarblepayroll/db_fuel
265
- source_code_uri: https://github.com/bluemarblepayroll/db_fuel
274
+ metadata: {}
266
275
  post_install_message:
267
276
  rdoc_options: []
268
277
  require_paths:
data/.travis.yml DELETED
@@ -1,28 +0,0 @@
1
- env:
2
- global:
3
- - CC_TEST_REPORTER_ID=2d57d597269e2cb04a63d0a7262927cf811abb7ab528da7de681943b212b4134
4
- jobs:
5
- - AR_VERSION=5
6
- - AR_VERSION=6
7
- language: ruby
8
- rvm:
9
- # Build on the latest stable of all supported Rubies (https://www.ruby-lang.org/en/downloads/):
10
- - 2.5.8
11
- - 2.6.6
12
- - 2.7.1
13
- cache: bundler
14
- before_script:
15
- - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
16
- - chmod +x ./cc-test-reporter
17
- - ./cc-test-reporter before-build
18
- - cp spec/config/database.yaml.ci spec/config/database.yaml
19
- script:
20
- - bundle exec rubocop
21
- - bundle exec rspec spec --format documentation
22
- after_script:
23
- - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
24
- addons:
25
- # https://docs.travis-ci.com/user/uploading-artifacts/
26
- artifacts:
27
- paths:
28
- - Gemfile.lock