nxt_support 0.2.1 → 0.3.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 14151213160e609dc893ae3113a4cfb1eb452ad20f0fe99b7e604e1f20376971
4
- data.tar.gz: 4fea5f3185b01a3730de9cf418c9c10b14c2bbc742eb5dcb0dbe28ee36ce6fdc
3
+ metadata.gz: 4df3922def5f3b704ce0d3f42851714bd63299f5acc4f3972049ce4015af3ad6
4
+ data.tar.gz: 7003d6c20622f4db12d7f039ff4a4bbaa8d114d11ad77a9b6e189db05bc01f1a
5
5
  SHA512:
6
- metadata.gz: c96c5be6ec63d22ae72652f8ece297945a32ea0c4c972b03ec9234da864663f629c45ddd8bf76e1b26b2484744c25de91dbb0a1e4c18d44814b5620f9fac254c
7
- data.tar.gz: 4d7b2944ede23aaf2e568d026bd193019a19b4bcd42ae45612c817c63882bf07d46c81bc6fbb6593833d4236d28a208cea2228e8047a4ae39336943fcf6d0ffe
6
+ metadata.gz: 3a8dc4b1e22b351d2ceee9918e299c0f17ed284956125168da3d6e932e00cff1512c7b827411aba7f32a2b3ee3c1face8a1c960f523e6d7b5dd10cc0ba1c5d52
7
+ data.tar.gz: 29edc7185ac167339ca1ac2a921cad40d620d1a0ee07a1037d92829a147e7d632469c4a9fec733586ca509b5e69a01e7bd83739df823e7a41fc2b5516d0b58be
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # v0.3.0 2022-05-30
2
+ - Support passing `with` to refinement
3
+ - Call ambiguity handler with resolved collection rather than original collection, to avoid logging huge values
4
+
1
5
  # v0.1.15 2021-03-26
2
6
  - Switched Rails dependency to ActiveRecord and ActiveSupport
3
7
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- nxt_support (0.2.1)
4
+ nxt_support (0.3.0)
5
5
  activerecord
6
6
  activesupport
7
7
  nxt_init
@@ -32,7 +32,7 @@ GEM
32
32
  activesupport
33
33
  nxt_registry (0.3.10)
34
34
  activesupport
35
- pry (0.14.0)
35
+ pry (0.14.1)
36
36
  coderay (~> 1.1)
37
37
  method_source (~> 1.0)
38
38
  rake (13.0.3)
data/README.md CHANGED
@@ -304,10 +304,9 @@ is that you can crystallize the department from your collection.
304
304
  NxtSupport::Crystalizer.new(collection: ['andy', 'andy']).call # => 'andy'
305
305
  NxtSupport::Crystalizer.new(collection: []).call # NxtSupport::Crystalizer::Error
306
306
  NxtSupport::Crystalizer.new(collection: ['andy', 'scotty']).call # NxtSupport::Crystalizer::Error
307
- NxtSupport::Crystalizer.new(collection: insurances, attribute: :effective_at).call # => shared effective_at or error in case of different effective_ats
308
307
  ```
309
308
 
310
- or using the refinement
309
+ or using the refinement:
311
310
 
312
311
  ```ruby
313
312
  using NxtSupport::Refinements::Crystalizer
@@ -317,6 +316,24 @@ using NxtSupport::Refinements::Crystalizer
317
316
 
318
317
  Note that for Ruby versions < 3.0 it only refines the class `Array` instead of the module `Enumerable`.
319
318
 
319
+
320
+ You can also specify the method to be checked and returned:
321
+
322
+ ```ruby
323
+ # Return `.effective_at` or error if `.effective_at`s are different
324
+ NxtSupport::Crystalizer.new(collection: insurances, with: :effective_at).call
325
+ NxtSupport::Crystalizer.new(collection: insurances, with: ->(i){ i.effective_at }).call
326
+ insurances.crystalize(with: :effective_at)
327
+ ```
328
+
329
+ The crystallizer raises a `NxtSupport::Crystalizer::Error` if the values are not the same, but you can override this:
330
+
331
+ ```ruby
332
+ insurances.crystalize(with: :effective_at) do |effective_ats|
333
+ raise SomethingsWrong, "Insurances don't start on the same date"
334
+ end
335
+ ```
336
+
320
337
  #### NxtSupport::BirthDate
321
338
 
322
339
  `NxtSupport::BirthDate` takes a date and provides some convenience methods related to age.
@@ -7,8 +7,8 @@ module NxtSupport
7
7
  _refined_module_or_class = Gem::Version.new(RUBY_VERSION) < Gem::Version.new('3.0.0') ? Array : Enumerable
8
8
 
9
9
  refine _refined_module_or_class do
10
- def crystalize(&block)
11
- ::NxtSupport::Crystalizer.new(collection: self, on_ambiguity: block).call
10
+ def crystalize(with: :itself, &block)
11
+ ::NxtSupport::Crystalizer.new(collection: self, with: with, on_ambiguity: block).call
12
12
  end
13
13
  end
14
14
  end
@@ -28,7 +28,7 @@ module NxtSupport
28
28
  def ensure_unanimity
29
29
  return if unique_values.size == 1
30
30
 
31
- on_ambiguity.arity == 1 ? on_ambiguity.call(collection) : on_ambiguity.call
31
+ on_ambiguity.arity == 1 ? on_ambiguity.call(resolved_collection) : on_ambiguity.call
32
32
  end
33
33
  end
34
34
  end
@@ -1,3 +1,3 @@
1
1
  module NxtSupport
2
- VERSION = "0.2.1".freeze
2
+ VERSION = "0.3.0".freeze
3
3
  end
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.2.1
4
+ version: 0.3.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: 2021-09-13 00:00:00.000000000 Z
14
+ date: 2022-06-02 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: activerecord
@@ -154,8 +154,6 @@ files:
154
154
  - ".gitignore"
155
155
  - ".rspec"
156
156
  - ".ruby-version"
157
- - ".ruby_version"
158
- - ".travis.yml"
159
157
  - CHANGELOG.md
160
158
  - Gemfile
161
159
  - Gemfile.lock
data/.ruby_version DELETED
@@ -1 +0,0 @@
1
- 2.6.4
data/.travis.yml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- sudo: false
3
- language: ruby
4
- cache: bundler
5
- rvm:
6
- - 2.6.4
7
- before_install: gem install bundler -v 2.0.2