nxt_support 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +2 -2
- data/README.md +19 -2
- data/lib/nxt_support/refinements/crystalizer.rb +2 -2
- data/lib/nxt_support/util/crystalizer.rb +1 -1
- data/lib/nxt_support/version.rb +1 -1
- metadata +2 -4
- data/.ruby_version +0 -1
- data/.travis.yml +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4df3922def5f3b704ce0d3f42851714bd63299f5acc4f3972049ce4015af3ad6
|
4
|
+
data.tar.gz: 7003d6c20622f4db12d7f039ff4a4bbaa8d114d11ad77a9b6e189db05bc01f1a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3a8dc4b1e22b351d2ceee9918e299c0f17ed284956125168da3d6e932e00cff1512c7b827411aba7f32a2b3ee3c1face8a1c960f523e6d7b5dd10cc0ba1c5d52
|
7
|
+
data.tar.gz: 29edc7185ac167339ca1ac2a921cad40d620d1a0ee07a1037d92829a147e7d632469c4a9fec733586ca509b5e69a01e7bd83739df823e7a41fc2b5516d0b58be
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
nxt_support (0.
|
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.
|
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(
|
31
|
+
on_ambiguity.arity == 1 ? on_ambiguity.call(resolved_collection) : on_ambiguity.call
|
32
32
|
end
|
33
33
|
end
|
34
34
|
end
|
data/lib/nxt_support/version.rb
CHANGED
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
|
+
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:
|
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
|