nxt_support 0.4.3 → 0.5.0

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: f312406bd8279693e902e38435d9ecec8e0e3d15c1e522d91c4a5cd75e4f4ced
4
- data.tar.gz: 0bb1c82b792322ecab97f89093295b17c4f9c5e2223a71584aca23b4b672a95a
3
+ metadata.gz: 5be999049e08c616e9259357e3babdc21c8a56202e29463ffb35877d7b59156b
4
+ data.tar.gz: a24d5abbc81b8a05104096251e7a1c5ef95fd4ef22378be9ad225e310848a417
5
5
  SHA512:
6
- metadata.gz: 92bf3e5ec6c83fe1f713973d4528b1a85b7c83573f86121b3fbe03e8586820c63e56369911d84031a62af5ca2db72bc50baaac2a45a29e270936d9154671f58b
7
- data.tar.gz: 0b883a1c2bbb8e0b7a6040569204676f4d5beec2b41514d791a1545863cd7c41d4394f8a1619b61956058cb6fa5d2038db6403857fb5cbe71f6a040dac6d77a4
6
+ metadata.gz: 62f3c629491c73b7b9fe0ac85639d01671cd3845fa6250a5c5b980ca5ea2a3353bc17337f2a7dbf72904113761cf70d6b43864635a526eed6bb0f7eb859e997d
7
+ data.tar.gz: 27ea42c5fa932be54cbc2b2e0cc1d5e1edd34176fe50e8fb8581507ce9429fba032dbba2aeda8806044f7471918eb8cc33744939a881ab4a6d409e7b2130ecb8
data/.circleci/config.yml CHANGED
@@ -10,9 +10,9 @@ workflows:
10
10
  - build:
11
11
  matrix:
12
12
  parameters:
13
- ruby-version: ["3.0.2", "3.1.3", "3.2.1"]
13
+ ruby-version: ["3.0.2", "3.1.3", "3.2.1", "3.2.2"]
14
14
  orbs:
15
- ruby: circleci/ruby@2.0.0
15
+ ruby: circleci/ruby@2.0.1
16
16
 
17
17
  jobs:
18
18
  build:
@@ -28,7 +28,9 @@ jobs:
28
28
 
29
29
  steps:
30
30
  - checkout
31
- - ruby/install-deps
31
+ - ruby/install-deps:
32
+ key: gems-v2
33
+ include-branch-in-cache-key: false
32
34
  - run:
33
35
  name: run tests
34
36
  command: |
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 3.2.1
1
+ 3.2.2
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ # v0.5.0 2023-03-22
2
+ - Add `rake_cli_options`
3
+
1
4
  # v0.4.3 2023-03-22
2
5
  - `Sentry-Error-Id`: Don't assume status code is an Integer
3
6
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- nxt_support (0.4.3)
4
+ nxt_support (0.5.0)
5
5
  activerecord
6
6
  activesupport
7
7
  nxt_init
@@ -10,47 +10,49 @@ PATH
10
10
  GEM
11
11
  remote: https://rubygems.org/
12
12
  specs:
13
- activemodel (7.0.4.3)
14
- activesupport (= 7.0.4.3)
15
- activerecord (7.0.4.3)
16
- activemodel (= 7.0.4.3)
17
- activesupport (= 7.0.4.3)
18
- activesupport (7.0.4.3)
13
+ activemodel (7.0.7.2)
14
+ activesupport (= 7.0.7.2)
15
+ activerecord (7.0.7.2)
16
+ activemodel (= 7.0.7.2)
17
+ activesupport (= 7.0.7.2)
18
+ activesupport (7.0.7.2)
19
19
  concurrent-ruby (~> 1.0, >= 1.0.2)
20
20
  i18n (>= 1.6, < 2)
21
21
  minitest (>= 5.1)
22
22
  tzinfo (~> 2.0)
23
23
  coderay (1.1.3)
24
24
  concurrent-ruby (1.2.2)
25
- diff-lcs (1.4.4)
26
- i18n (1.12.0)
25
+ diff-lcs (1.5.0)
26
+ i18n (1.14.1)
27
27
  concurrent-ruby (~> 1.0)
28
28
  method_source (1.0.0)
29
- minitest (5.18.0)
29
+ mini_portile2 (2.8.4)
30
+ minitest (5.19.0)
30
31
  nxt_init (0.1.5)
31
32
  activesupport
32
33
  nxt_registry (0.3.10)
33
34
  activesupport
34
- pry (0.14.1)
35
+ pry (0.14.2)
35
36
  coderay (~> 1.1)
36
37
  method_source (~> 1.0)
37
- rake (13.0.3)
38
- rspec (3.10.0)
39
- rspec-core (~> 3.10.0)
40
- rspec-expectations (~> 3.10.0)
41
- rspec-mocks (~> 3.10.0)
42
- rspec-core (3.10.1)
43
- rspec-support (~> 3.10.0)
44
- rspec-expectations (3.10.1)
38
+ rake (13.0.6)
39
+ rspec (3.12.0)
40
+ rspec-core (~> 3.12.0)
41
+ rspec-expectations (~> 3.12.0)
42
+ rspec-mocks (~> 3.12.0)
43
+ rspec-core (3.12.2)
44
+ rspec-support (~> 3.12.0)
45
+ rspec-expectations (3.12.3)
45
46
  diff-lcs (>= 1.2.0, < 2.0)
46
- rspec-support (~> 3.10.0)
47
- rspec-mocks (3.10.2)
47
+ rspec-support (~> 3.12.0)
48
+ rspec-mocks (3.12.6)
48
49
  diff-lcs (>= 1.2.0, < 2.0)
49
- rspec-support (~> 3.10.0)
50
- rspec-support (3.10.2)
51
- rspec_junit_formatter (0.4.1)
50
+ rspec-support (~> 3.12.0)
51
+ rspec-support (3.12.1)
52
+ rspec_junit_formatter (0.6.0)
52
53
  rspec-core (>= 2, < 4, != 2.12.0)
53
- sqlite3 (1.4.2)
54
+ sqlite3 (1.6.3)
55
+ mini_portile2 (~> 2.8.0)
54
56
  tzinfo (2.0.6)
55
57
  concurrent-ruby (~> 1.0)
56
58
 
data/README.md CHANGED
@@ -2,7 +2,10 @@
2
2
 
3
3
  # NxtSupport
4
4
 
5
- This is a collection of mixins, helpers and classes that cover several aspects of a ruby on rails application, such as models, controllers and job processing. At [Getsafe](https://hellogetsafe.com), we run multiple Ruby on Rails apps as part of our insurance infrastructure and we found that we wrote quite some shared helpers that are duplicated among applications and serve a generic purpose that we could share in this gem. Look at it as our version of ActiveSupport (which is amazing! ❤️), droping in the pieces we sometimes miss in the beautiful puzzle of Rails.
5
+ This is a collection of mixins, helpers and classes that cover several aspects of a ruby on rails application, such as models, controllers and job processing.
6
+ At [Getsafe](https://hellogetsafe.com), we run multiple Ruby on Rails apps as part of our insurance infrastructure and we found that we wrote quite some
7
+ shared helpers that are duplicated among applications and serve a generic purpose that we could share in this gem.
8
+ Look at it as our version of ActiveSupport (which is amazing! ❤️), dropping in the pieces we sometimes miss in the beautiful puzzle of Rails.
6
9
 
7
10
  ## Installation
8
11
 
@@ -28,7 +31,7 @@ Here's an overview all the supporting features.
28
31
  A Rack middleware that adds a `Sentry-Error-ID` header to 5xx responses.
29
32
  The header is only added if an error was reported during the request.
30
33
  The error ID is gotten from [`sentry.error_event_id` in the Rack env](https://github.com/getsentry/sentry-ruby/pull/1849)).
31
- You can then visit `https://sentry.io/organizations/<org-slug>>?query=<error-event-id>`
34
+ You can then visit `https://<org-slug>.sentry.io/issues/?query=<error-event-id>`
32
35
  to go directly to the error (it may not show up immediately).
33
36
 
34
37
  Note that this middleware must be inserted before Sentry's own middleware.
@@ -250,7 +253,7 @@ TestClass.translate_hash(firstname: 'John', firstname: :first_name)
250
253
  => { 'first_name' => 'John' }
251
254
  ```
252
255
  The `value` also could be a `Hash` where key represents the new key in result hash and value must be a lambda or Proc
253
- that would be used to process value from origin hash. If the tuple hash contains more than 1 key-value paris or value in key value pair
256
+ that would be used to process value from origin hash. If the tuple hash contains more than 1 key-value pairs or value in key value pair
254
257
  is not a callable block `InvalidTranslationArgument` error would be raised.
255
258
 
256
259
  ```ruby
@@ -357,6 +360,64 @@ NxtSupport::BirthDate.new(date: '1990-08-08').to_age # => 30
357
360
  NxtSupport::BirthDate.new(date: '1990-08-08').to_age_in_months # => 361
358
361
  ```
359
362
 
363
+ ### NxtSupport::Console.rake_cli_options
364
+ A simple utility that uses Ruby's [OptionParser](https://docs.ruby-lang.org/en/2.1.0/OptionParser.html)
365
+ to make it easier to pass CLI options to Rake tasks.
366
+
367
+ #### Task definition
368
+ Call `NxtSupport::Console.rake_cli_options` with a block. Use the `option` method to define options.
369
+ It takes one required argument (the flag syntax), and optionally the data type and a default value.
370
+
371
+ Options which are not booleans **must** end with an `=`.
372
+
373
+ ```rb
374
+ task my_task: :environment do
375
+ opts = NxtSupport::Console.rake_cli_options do
376
+ option '--simulate', default: false
377
+ option '--contract_numbers=', Array, default: []
378
+ option '--limit=', Integer
379
+ option '--effective_at='
380
+ end
381
+
382
+ do_stuff_with opts
383
+ end
384
+ ```
385
+
386
+ #### Command line
387
+
388
+ A `--` must be passed after the Rake task name and any Rake-specific options,
389
+ before our custom task options. (With `heroku run`, you'll also need a second `--`).
390
+
391
+ ```sh
392
+ rake my_task -- --simulate --contract_numbers=123,456 --effective_at=2022-01-02 --limit=20
393
+ # {:contract_numbers=>["123", "456"], :simulate=>true, :effective_at=>"2022-01-02", :limit=>20}
394
+ ```
395
+
396
+ On Heroku (note the second `--`):
397
+
398
+ ```sh
399
+ heroku run rake my_task -- -- --simulate --contract_numbers=123,456 --effective_at=2022-01-02 --limit=20
400
+ ```
401
+
402
+ If any options are not passed, they'll be replaced with their defaults.
403
+ If no default was specified, they will _not_ be present in the returned hash.
404
+
405
+ ```sh
406
+ rake my_task -- --effective_at=2022-10-13
407
+ # {:simulate=>false, :effective_at=>"2022-10-13", :contract_numbers=>[]}
408
+ ```
409
+
410
+ If you specify an option which was not defined, the command will exit with an error:
411
+
412
+ ```sh
413
+ rake my_task -- --effective_at=2022-10-13 --testing
414
+ # invalid option: --testing
415
+ ```
416
+
417
+ #### Limitations
418
+ - Short arguments aren't supported (`-l` as a shortcut for `--limit`).
419
+ - On the command line, options with values must be passed with an `=` at the end. `--effective_at 2022-10-13` will not work.
420
+
360
421
  ### NxtSupport/Services
361
422
  Enjoy your service objects.
362
423
 
@@ -436,7 +497,7 @@ To release a new version, update the version number in `version.rb`, and then ru
436
497
 
437
498
  ## Contributing
438
499
 
439
- Bug reports and pull requests are welcome on GitHub at https://github.com/nxt_insurance/nxt_support.
500
+ Bug reports and pull requests are welcome on GitHub at https://github.com/nxt-insurance/nxt_support.
440
501
 
441
502
  ## Publishing
442
503
  ### GitHub Tags and Releases
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NxtSupport
4
+ module Console
5
+ # Better CLI arguments for Rake tasks, using Ruby's OptionParser
6
+ # See https://docs.ruby-lang.org/en/2.1.0/OptionParser.html
7
+ #
8
+ # Example usage in a task:
9
+ #
10
+ # task :my_task do
11
+ # opts = NxtSupport::Console.rake_cli_options do
12
+ # option '--simulate'
13
+ # option '--contract_numbers=', Array, default: []
14
+ # option '--limit=', Integer, default: 10
15
+ # option '--effective_at='
16
+ # end
17
+ #
18
+ # p opts
19
+ # end
20
+ #
21
+ # On the CLI:
22
+ # rake my_task -- --simulate --contract_numbers=123,456 --effective_at=2022-01-02 --limit=20
23
+ #
24
+ # Results:
25
+ # {:contract_numbers=>["123", "456"], :simulate=>true, :effective_at=>"2022-01-02", :limit=>20}
26
+ #
27
+ # Note that the extra "--" must be passed after the task name and all Rake-specific flags.
28
+ #
29
+ # Also, only arguments which are supplied on the CLI or had defaults defined will be present in the returned hash
30
+ # rake my_task -- --effective_at=2022-10-13
31
+ # => {:limit=>10, :effective_at=>"2022-10-13", :contract_numbers=>[]}
32
+ def rake_cli_options(argv = ARGV.dup, &option_definition_block)
33
+ require 'optparse'
34
+
35
+ argv.shift while argv.include?('--') # Remove task name and --
36
+ options = {}
37
+
38
+ OptionParser.new do |parser|
39
+ parser.define_singleton_method(:option) do |switch, type = nil, default: nil|
40
+ if default
41
+ switch_name = switch.sub('--', '').sub('=', '')
42
+ options[:"#{switch_name}"] = default
43
+ end
44
+ type ? def_option(switch, type) : def_option(switch)
45
+ end
46
+ parser.instance_eval(&option_definition_block)
47
+ end.parse!(argv, into: options)
48
+
49
+ options
50
+ end
51
+
52
+ module_function :rake_cli_options
53
+ end
54
+ end
@@ -1,3 +1,3 @@
1
1
  module NxtSupport
2
- VERSION = "0.4.3".freeze
2
+ VERSION = "0.5.0".freeze
3
3
  end
data/lib/nxt_support.rb CHANGED
@@ -8,6 +8,7 @@ require "nxt_support/serializers"
8
8
  require "nxt_support/util"
9
9
  require "nxt_support/services"
10
10
  require "nxt_support/refinements"
11
+ require "nxt_support/console"
11
12
 
12
13
  require 'nxt_support/middleware/sentry_error_id'
13
14
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nxt_support
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nils Sommer
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: exe
13
13
  cert_chain: []
14
- date: 2023-03-22 00:00:00.000000000 Z
14
+ date: 2023-08-23 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: activerecord
@@ -165,6 +165,7 @@ files:
165
165
  - bin/rspec
166
166
  - bin/setup
167
167
  - lib/nxt_support.rb
168
+ - lib/nxt_support/console.rb
168
169
  - lib/nxt_support/middleware/sentry_error_id.rb
169
170
  - lib/nxt_support/models.rb
170
171
  - lib/nxt_support/models/assignable_values.rb
@@ -214,7 +215,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
214
215
  - !ruby/object:Gem::Version
215
216
  version: '0'
216
217
  requirements: []
217
- rubygems_version: 3.4.6
218
+ rubygems_version: 3.4.10
218
219
  signing_key:
219
220
  specification_version: 4
220
221
  summary: Support through reusable Mixins and Helpers for Ruby on Rails Applications