everythingrb 0.8.1 → 0.8.3

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: 690fd1806244edcbfb5eb400b41c03f469395dd60b4aae710525f0deaee74987
4
- data.tar.gz: eb30c2bf26c9a760d44a5615c7469ee3217b077129e4d703d12072ed5518772c
3
+ metadata.gz: 6523ad82c57c693afadd2a17649c6628b49c0f775d0c3af09b5b207d8bace8a7
4
+ data.tar.gz: 8c0c363214cf537d6ada6ad78d0da899ddbfdc17066325774b9e8f6f97b9f6f1
5
5
  SHA512:
6
- metadata.gz: a3b3fd079bceec53d996894600edf5cedd3160eb2ae3e6936b1ee7d0912f44b1f49fd17365bc718f994c9a741a5c343cddafdb6a0d26eec48ab72025ceb4e8d6
7
- data.tar.gz: 57cf9aa688a17360d4f77be95a225c94df7cfbb5acb39efa060abaf8b4d02a96f3315d9e0a4f5273cbc92e0eb7931cf4a28f453e0491ac4f7db146882ae13e17
6
+ metadata.gz: 8a9f2620930ed9635287815679639cbd5403dc31b382717e107d8fbebf5fad0b6ba4be5398478f9b240141bbbbd2889cccbfc86d9330aeb1547386ab114bf034
7
+ data.tar.gz: 8b6f1facb28da84ad99d7e52d14196ae023521c8ea26c075e1649f02364a29595f424b8aa9719438742ae2f5cc8ce047336534e94357693c7a678f225fdbc353
data/CHANGELOG.md CHANGED
@@ -15,6 +15,31 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
15
15
  ### Removed
16
16
  -->
17
17
 
18
+ ## [0.8.3] - 12025-05-31
19
+
20
+ ### Added
21
+
22
+ ### Changed
23
+
24
+ - **Deprecated Hash value filtering methods** - `Hash#select_values`, `Hash#reject_values`, `Hash#select_values!` and `Hash#reject_values!` are now deprecated and will be removed in v0.9.0. These methods largely duplicate existing Ruby/ActiveSupport functionality:
25
+ - `hash.reject_values(&:blank?)` → use `hash.compact_blank` instead
26
+ - `hash.select_values { |v| condition }` → use `hash.select { |k, v| condition }`
27
+ - `hash.reject_values { |v| condition }` → use `hash.reject { |k, v| condition }`
28
+
29
+ See [Issue #61](https://github.com/itsthedevman/everythingrb/issues/61) for full details.
30
+
31
+ ### Removed
32
+
33
+ ## [0.8.2] - 12025-05-25
34
+
35
+ ### Added
36
+
37
+ ### Changed
38
+
39
+ - Fixed `Hash#rename_key_unordered` and `Hash#rename_key_unordered!` to not create new key-value pairs when the original key doesn't exist. Previously, these methods would incorrectly add the `new_key` to the hash even when `old_key` was missing.
40
+
41
+ ### Removed
42
+
18
43
  ## [0.8.1] - 12025-05-21
19
44
 
20
45
  ### Added
@@ -291,7 +316,9 @@ This change aligns our method signatures with Ruby's conventions and matches our
291
316
 
292
317
  - Added alias `each` to `each_pair` in OpenStruct for better enumerable compatibility
293
318
 
294
- [unreleased]: https://github.com/itsthedevman/everythingrb/compare/v0.8.1...HEAD
319
+ [unreleased]: https://github.com/itsthedevman/everythingrb/compare/v0.8.3...HEAD
320
+ [0.8.3]: https://github.com/itsthedevman/everythingrb/compare/v0.8.2...v0.8.3
321
+ [0.8.2]: https://github.com/itsthedevman/everythingrb/compare/v0.8.1...v0.8.2
295
322
  [0.8.1]: https://github.com/itsthedevman/everythingrb/compare/v0.8.0...v0.8.1
296
323
  [0.8.0]: https://github.com/itsthedevman/everythingrb/compare/v0.7.0...v0.8.0
297
324
  [0.7.0]: https://github.com/itsthedevman/everythingrb/compare/v0.6.1...v0.7.0
data/README.md CHANGED
@@ -12,11 +12,15 @@ We've all been there - writing the same tedious patterns over and over:
12
12
 
13
13
  ```ruby
14
14
  # BEFORE
15
- users = [{ name: "Alice", role: "admin" }, { name: "Bob", role: "user" }]
15
+ users = [
16
+ { name: "Alice", role: "admin" },
17
+ { name: "Bob", role: "user" },
18
+ { name: "Charlie", role: "admin" }
19
+ ]
16
20
  admin_users = users.select { |u| u[:role] == "admin" }
17
21
  admin_names = admin_users.map { |u| u[:name] }
18
22
  result = admin_names.join(", ")
19
- # => "Alice"
23
+ # => "Alice, Charlie"
20
24
  ```
21
25
 
22
26
  With EverythingRB, you can write code that actually says what you mean:
@@ -24,7 +28,7 @@ With EverythingRB, you can write code that actually says what you mean:
24
28
  ```ruby
25
29
  # AFTER
26
30
  users.join_map(", ") { |u| u[:name] if u[:role] == "admin" }
27
- # => "Alice"
31
+ # => "Alice, Charlie"
28
32
  ```
29
33
 
30
34
  *Methods used: [`join_map`](https://itsthedevman.com/docs/everythingrb/Array.html#join_map-instance_method)*
@@ -629,6 +629,10 @@ class Hash
629
629
  # But as the hash becomes larger, the performance improvements become diminished until they're roughly the same.
630
630
  # Neat!
631
631
  hash = except(old_key)
632
+
633
+ # Only modify the hash if the old key exists
634
+ return hash unless key?(old_key)
635
+
632
636
  hash[new_key] = self[old_key]
633
637
  hash
634
638
  end
@@ -650,6 +654,9 @@ class Hash
650
654
  # # => {a: 1, c: 3, middle: 2} # Order may differ
651
655
  #
652
656
  def rename_key_unordered!(old_key, new_key)
657
+ # Only modify the hash if the old key exists
658
+ return self unless key?(old_key)
659
+
653
660
  self[new_key] = delete(old_key)
654
661
  self
655
662
  end
@@ -657,22 +664,13 @@ class Hash
657
664
  #
658
665
  # Selects hash entries based only on their values
659
666
  #
660
- # @yield [value] Block that determines whether to include the entry
661
- # @yieldparam value [Object] The current value
662
- # @yieldreturn [Boolean] Whether to include this entry
663
- #
664
- # @return [Hash] A new hash including only entries where the block returned truthy
665
- # @return [Enumerator] If no block is given
666
- #
667
- # @example Filter to include only present values (with ActiveSupport)
668
- # {name: "Alice", bio: nil, role: ""}.select_values(&:present?)
669
- # # => {name: "Alice"}
670
- #
671
- # @example Filter using more complex logic
672
- # {id: 1, count: 0, items: [1, 2, 3]}.select_values { |v| v.is_a?(Array) || v > 0 }
673
- # # => {id: 1, items: [1, 2, 3]}
667
+ # @deprecated Hash#select_values will be removed in 0.9.0. Please use `select { |k, v| condition }` instead.
674
668
  #
675
669
  def select_values(&block)
670
+ Everythingrb.deprecator.warn(
671
+ "Hash#select_values will be removed in 0.9.0. Please use `select { |k, v| condition }` instead."
672
+ )
673
+
676
674
  return to_enum(:select_values) if block.nil?
677
675
 
678
676
  select { |_k, v| block.call(v) }
@@ -683,20 +681,13 @@ class Hash
683
681
  #
684
682
  # Selects hash entries based only on their values, modifying the hash in place
685
683
  #
686
- # @yield [value] Block that determines whether to keep the entry
687
- # @yieldparam value [Object] The current value
688
- # @yieldreturn [Boolean] Whether to keep this entry
689
- #
690
- # @return [self, nil] The modified hash, or nil if no changes were made
691
- # @return [Enumerator] If no block is given
692
- #
693
- # @example Remove entries with empty values (with ActiveSupport)
694
- # hash = {name: "Alice", bio: nil, role: ""}
695
- # hash.select_values!(&:present?)
696
- # # => {name: "Alice"}
697
- # # hash is now {name: "Alice"}
684
+ # @deprecated Hash#select_values! will be removed in 0.9.0. Please use `select! { |k, v| condition }` instead.
698
685
  #
699
686
  def select_values!(&block)
687
+ Everythingrb.deprecator.warn(
688
+ "Hash#select_values! will be removed in 0.9.0. Please use `select! { |k, v| condition }` instead."
689
+ )
690
+
700
691
  return to_enum(:select_values!) if block.nil?
701
692
 
702
693
  select! { |_k, v| block.call(v) }
@@ -707,22 +698,13 @@ class Hash
707
698
  #
708
699
  # Rejects hash entries based only on their values
709
700
  #
710
- # @yield [value] Block that determines whether to exclude the entry
711
- # @yieldparam value [Object] The current value
712
- # @yieldreturn [Boolean] Whether to exclude this entry
713
- #
714
- # @return [Hash] A new hash excluding entries where the block returned truthy
715
- # @return [Enumerator] If no block is given
716
- #
717
- # @example Remove blank values (with ActiveSupport)
718
- # {name: "Alice", bio: nil, role: ""}.reject_values(&:blank?)
719
- # # => {name: "Alice"}
720
- #
721
- # @example Remove specific types of values
722
- # {id: 1, count: 0, items: [1, 2, 3]}.reject_values { |v| v.is_a?(Integer) && v == 0 }
723
- # # => {id: 1, items: [1, 2, 3]}
701
+ # @deprecated Hash#reject_values will be removed in 0.9.0. Please use `reject { |k, v| condition }` instead.
724
702
  #
725
703
  def reject_values(&block)
704
+ Everythingrb.deprecator.warn(
705
+ "Hash#reject_values will be removed in 0.9.0. Please use `reject { |k, v| condition }` instead."
706
+ )
707
+
726
708
  return to_enum(:reject_values) if block.nil?
727
709
 
728
710
  reject { |_k, v| block.call(v) }
@@ -731,20 +713,13 @@ class Hash
731
713
  #
732
714
  # Rejects hash entries based only on their values, modifying the hash in place
733
715
  #
734
- # @yield [value] Block that determines whether to remove the entry
735
- # @yieldparam value [Object] The current value
736
- # @yieldreturn [Boolean] Whether to remove this entry
737
- #
738
- # @return [self, nil] The modified hash, or nil if no changes were made
739
- # @return [Enumerator] If no block is given
740
- #
741
- # @example Remove blank values in place (with ActiveSupport)
742
- # hash = {name: "Alice", bio: nil, role: ""}
743
- # hash.reject_values!(&:blank?)
744
- # # => {name: "Alice"}
745
- # # hash is now {name: "Alice"}
716
+ # @deprecated Hash#reject_values! will be removed in 0.9.0. Please use `reject! { |k, v| condition }` instead.
746
717
  #
747
718
  def reject_values!(&block)
719
+ Everythingrb.deprecator.warn(
720
+ "Hash#reject_values! will be removed in 0.9.0. Please use `reject! { |k, v| condition }` instead."
721
+ )
722
+
748
723
  return to_enum(:reject_values!) if block.nil?
749
724
 
750
725
  reject! { |_k, v| block.call(v) }
@@ -25,6 +25,15 @@ require "json"
25
25
  # users.key_map(:name).join(", ") # => "Alice, Bob"
26
26
  #
27
27
  module Everythingrb
28
+ def self.deprecator
29
+ @deprecator ||= if defined?(ActiveSupport)
30
+ ActiveSupport::Deprecation.new(VERSION, "everythingrb")
31
+ else
32
+ proxy = Data.define
33
+ proxy.define_method(:warn) { |message| puts "DEPRECATION WARNING: #{message}" }
34
+ proxy.new
35
+ end
36
+ end
28
37
  end
29
38
 
30
39
  require_relative "extensions"
@@ -7,5 +7,5 @@
7
7
  #
8
8
  module Everythingrb
9
9
  # Current version of the everythingrb gem
10
- VERSION = "0.8.1"
10
+ VERSION = "0.8.3"
11
11
  end
data/lib/everythingrb.rb CHANGED
@@ -1,9 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "everythingrb/prelude"
4
-
5
3
  if defined?(Rails::Railtie)
6
4
  require_relative "railtie"
7
5
  else
6
+ require_relative "everythingrb/prelude"
8
7
  require_relative "everythingrb/all"
9
8
  end
data/lib/railtie.rb CHANGED
@@ -24,6 +24,8 @@ module Everythingrb
24
24
  # I learned that, whereas ActiveSupport is defined at this point, the core_ext files are
25
25
  # required later down the line.
26
26
  ActiveSupport.on_load(:active_record) do
27
+ require_relative "everythingrb/prelude"
28
+
27
29
  extensions = Rails.configuration.everythingrb.extensions
28
30
 
29
31
  if extensions.is_a?(Array)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: everythingrb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.8.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bryan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-05-21 00:00:00.000000000 Z
11
+ date: 2025-06-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ostruct