refinements 12.7.1 → 12.9.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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data/README.adoc +79 -7
- data/lib/refinements/array.rb +1 -1
- data/lib/refinements/hash.rb +8 -2
- data/lib/refinements/pathname.rb +2 -2
- data/lib/refinements/string_io.rb +3 -0
- data/refinements.gemspec +3 -3
- data.tar.gz.sig +0 -0
- metadata +8 -5
- metadata.gz.sig +0 -0
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 229ada32a4378800013462184db88be59d33109cbbd63c8c6378add52fc7b321
         | 
| 4 | 
            +
              data.tar.gz: 4f0291390f858b45e2066dc9eac5e3f06ceef5c9e1051160aa7c625e734c78c4
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: dbe61e5483ff24ffe0d9852e3f1c34e613f53a48f8a96cb15b862bf2528c448df71e9357d2910068b7e41275a916a9169f99e6b5b67c355df73eaf3e6ac2d124
         | 
| 7 | 
            +
              data.tar.gz: 3f77b617a157b3d9be6735a08a9340ddd945642107d5e2728e384f6496197a44e180cfcce8c5738ec5ea509df883fcc5ca3b1261ffaddeaedbcfe0764987d9d0
         | 
    
        checksums.yaml.gz.sig
    CHANGED
    
    | Binary file | 
    
        data/README.adoc
    CHANGED
    
    | @@ -635,7 +635,7 @@ Any object that _is not_ the same type will have a `nil` value as shown in the l | |
| 635 635 |  | 
| 636 636 | 
             
            Fetches value for exiting or missing key. Behavior is identical to `#fetch` except when the value of
         | 
| 637 637 | 
             
            the key is `nil` you'll get the default value instead. This eliminates the need for using an _or_
         | 
| 638 | 
            -
            expression `example.fetch(:desired_key) || "default_value"`.
         | 
| 638 | 
            +
            expression: `example.fetch(:desired_key) || "default_value"`.
         | 
| 639 639 |  | 
| 640 640 | 
             
            [source,ruby]
         | 
| 641 641 | 
             
            ----
         | 
| @@ -650,8 +650,7 @@ expression `example.fetch(:desired_key) || "default_value"`. | |
| 650 650 |  | 
| 651 651 | 
             
            ===== #flatten_keys
         | 
| 652 652 |  | 
| 653 | 
            -
            Flattens nested keys as top-level keys without mutating itself. Does not handle nested arrays | 
| 654 | 
            -
            though.
         | 
| 653 | 
            +
            Flattens nested keys as top-level keys without mutating itself. Keys are converted to symbols. Does not handle nested arrays.
         | 
| 655 654 |  | 
| 656 655 | 
             
            [source,ruby]
         | 
| 657 656 | 
             
            ----
         | 
| @@ -665,8 +664,7 @@ example                                         # {a: {b: 1}} | |
| 665 664 |  | 
| 666 665 | 
             
            ===== #flatten_keys!
         | 
| 667 666 |  | 
| 668 | 
            -
            Flattens nested keys as top-level keys while mutating itself. Does not handle nested arrays | 
| 669 | 
            -
            though.
         | 
| 667 | 
            +
            Flattens nested keys as top-level keys while mutating itself. Keys are converted to symbols. Does not handle nested arrays.
         | 
| 670 668 |  | 
| 671 669 | 
             
            [source,ruby]
         | 
| 672 670 | 
             
            ----
         | 
| @@ -747,6 +745,52 @@ example.symbolize_keys!  # {a: 1, b: 2} | |
| 747 745 | 
             
            example                  # {a: 1, b: 2}
         | 
| 748 746 | 
             
            ----
         | 
| 749 747 |  | 
| 748 | 
            +
            ===== #transform_value
         | 
| 749 | 
            +
             | 
| 750 | 
            +
            Transforms a value for the specified key _only_ if the key exists and a block is given. Otherwise, the original hash is answered. Does not mutate itself.
         | 
| 751 | 
            +
             | 
| 752 | 
            +
            [source,ruby]
         | 
| 753 | 
            +
            ----
         | 
| 754 | 
            +
            example = {a: 1, b: 2}
         | 
| 755 | 
            +
             | 
| 756 | 
            +
            example.transform_value :b                          # {a: 1, b: 2}
         | 
| 757 | 
            +
            example.transform_value(:b) { 20 }                  # {a: 1, b: 20}
         | 
| 758 | 
            +
            example.transform_value(:b) { |value| value * 10 }  # {a: 1, b: 20}
         | 
| 759 | 
            +
            example.transform_value :c                          # {a: 1, b: 2}
         | 
| 760 | 
            +
            example.transform_value(:c) { :bogus }              # {a: 1, b: 2}
         | 
| 761 | 
            +
            ----
         | 
| 762 | 
            +
             | 
| 763 | 
            +
            The original object _is not_ mutated:
         | 
| 764 | 
            +
             | 
| 765 | 
            +
            [source,ruby]
         | 
| 766 | 
            +
            ----
         | 
| 767 | 
            +
            example.transform_value(:b) { 20 }  # {a: 1, b: 20}
         | 
| 768 | 
            +
            example                             # {a: 1, b: 2}
         | 
| 769 | 
            +
            ----
         | 
| 770 | 
            +
             | 
| 771 | 
            +
            ===== #transform_value!
         | 
| 772 | 
            +
             | 
| 773 | 
            +
            Transforms a value for the specified key _only_ if the key exists and a block is given. Otherwise, the original hash is answered. Mutates itself.
         | 
| 774 | 
            +
             | 
| 775 | 
            +
            [source,ruby]
         | 
| 776 | 
            +
            ----
         | 
| 777 | 
            +
            example = {a: 1, b: 2}
         | 
| 778 | 
            +
             | 
| 779 | 
            +
            example.transform_value! :b                          # {a: 1, b: 2}
         | 
| 780 | 
            +
            example.transform_value!(:b) { 20 }                  # {a: 1, b: 20}
         | 
| 781 | 
            +
            example.transform_value!(:b) { |value| value * 10 }  # {a: 1, b: 20}
         | 
| 782 | 
            +
            example.transform_value! :c                          # {a: 1, b: 2}
         | 
| 783 | 
            +
            example.transform_value!(:c) { :bogus }              # {a: 1, b: 2}
         | 
| 784 | 
            +
            ----
         | 
| 785 | 
            +
             | 
| 786 | 
            +
            The original object _is_ mutated:
         | 
| 787 | 
            +
             | 
| 788 | 
            +
            [source,ruby]
         | 
| 789 | 
            +
            ----
         | 
| 790 | 
            +
            example.transform_value!(:b) { 20 }  # {a: 1, b: 20}
         | 
| 791 | 
            +
            example                              # {a: 1, b: 20}
         | 
| 792 | 
            +
            ----
         | 
| 793 | 
            +
             | 
| 750 794 | 
             
            ===== #transform_with
         | 
| 751 795 |  | 
| 752 796 | 
             
            Transforms values of keys using specific operations (i.e. any object that responds to `#call`). Does not mutate itself and you can transform multiple values at once:
         | 
| @@ -768,7 +812,7 @@ example.transform_with bogus: -> value { value.tr "<>", "" } | |
| 768 812 | 
             
            # {email: "<jd@example.com>"}
         | 
| 769 813 | 
             
            ----
         | 
| 770 814 |  | 
| 771 | 
            -
            The original object  | 
| 815 | 
            +
            The original object _is not_ mutated:
         | 
| 772 816 |  | 
| 773 817 | 
             
            [source,ruby]
         | 
| 774 818 | 
             
            ----
         | 
| @@ -796,7 +840,7 @@ example.transform_with! bogus: -> value { value.tr "<>", "" } | |
| 796 840 | 
             
            # {email: "<jd@example.com>"}
         | 
| 797 841 | 
             
            ----
         | 
| 798 842 |  | 
| 799 | 
            -
            The original object  | 
| 843 | 
            +
            The original object _is_ mutated:
         | 
| 800 844 |  | 
| 801 845 | 
             
            [source,ruby]
         | 
| 802 846 | 
             
            ----
         | 
| @@ -1524,6 +1568,32 @@ io.reread(buffer:)  # "This is a test." | |
| 1524 1568 | 
             
            buffer              # "This is a test."
         | 
| 1525 1569 | 
             
            ----
         | 
| 1526 1570 |  | 
| 1571 | 
            +
            ===== #to_s
         | 
| 1572 | 
            +
             | 
| 1573 | 
            +
            Answers underlying string representation for _explicit_ conversion.
         | 
| 1574 | 
            +
             | 
| 1575 | 
            +
            [source,ruby]
         | 
| 1576 | 
            +
            ----
         | 
| 1577 | 
            +
            io = StringIO.new
         | 
| 1578 | 
            +
            io.write "One"
         | 
| 1579 | 
            +
            io.write ", "
         | 
| 1580 | 
            +
            io.write "Two."
         | 
| 1581 | 
            +
            io.to_s # "One, Two."
         | 
| 1582 | 
            +
            ----
         | 
| 1583 | 
            +
             | 
| 1584 | 
            +
            ===== #to_str
         | 
| 1585 | 
            +
             | 
| 1586 | 
            +
            Answers underlying string representation for _implicit_ conversion.
         | 
| 1587 | 
            +
             | 
| 1588 | 
            +
            [source,ruby]
         | 
| 1589 | 
            +
            ----
         | 
| 1590 | 
            +
            io = StringIO.new
         | 
| 1591 | 
            +
            io.write "One"
         | 
| 1592 | 
            +
            io.write ", "
         | 
| 1593 | 
            +
            io.write "Two."
         | 
| 1594 | 
            +
            io.to_str # "One, Two."
         | 
| 1595 | 
            +
            ----
         | 
| 1596 | 
            +
             | 
| 1527 1597 | 
             
            ==== Struct
         | 
| 1528 1598 |  | 
| 1529 1599 | 
             
            ===== .with_positions
         | 
| @@ -1730,6 +1800,8 @@ bin/rake | |
| 1730 1800 |  | 
| 1731 1801 | 
             
            == link:https://alchemists.io/policies/contributions[Contributions]
         | 
| 1732 1802 |  | 
| 1803 | 
            +
            == link:https://alchemists.io/policies/developer_certificate_of_origin[Developer Certificate of Origin]
         | 
| 1804 | 
            +
             | 
| 1733 1805 | 
             
            == link:https://alchemists.io/projects/refinements/versions[Versions]
         | 
| 1734 1806 |  | 
| 1735 1807 | 
             
            == link:https://alchemists.io/community[Community]
         | 
    
        data/lib/refinements/array.rb
    CHANGED
    
    | @@ -19,7 +19,7 @@ module Refinements | |
| 19 19 |  | 
| 20 20 | 
             
                  def excluding(*elements) = self - elements.flatten
         | 
| 21 21 |  | 
| 22 | 
            -
                  def filter_find(& | 
| 22 | 
            +
                  def filter_find(&) = block_given? ? lazy.map(&).find(&:itself) : lazy
         | 
| 23 23 |  | 
| 24 24 | 
             
                  def including(*elements) = self + elements.flatten
         | 
| 25 25 |  | 
    
        data/lib/refinements/hash.rb
    CHANGED
    
    | @@ -80,9 +80,15 @@ module Refinements | |
| 80 80 |  | 
| 81 81 | 
             
                  def symbolize_keys! = transform_keys!(&:to_sym)
         | 
| 82 82 |  | 
| 83 | 
            -
                  def  | 
| 83 | 
            +
                  def transform_value(key, &) = dup.transform_value!(key, &)
         | 
| 84 84 |  | 
| 85 | 
            -
                  def  | 
| 85 | 
            +
                  def transform_value! key
         | 
| 86 | 
            +
                    block_given? && key?(key) ? merge!(key => yield(self[key])) : self
         | 
| 87 | 
            +
                  end
         | 
| 88 | 
            +
             | 
| 89 | 
            +
                  def transform_with(**) = dup.transform_with!(**)
         | 
| 90 | 
            +
             | 
| 91 | 
            +
                  def transform_with!(**operations)
         | 
| 86 92 | 
             
                    operations.each { |key, function| self[key] = function.call self[key] if key? key }
         | 
| 87 93 | 
             
                    self
         | 
| 88 94 | 
             
                  end
         | 
    
        data/lib/refinements/pathname.rb
    CHANGED
    
    | @@ -53,14 +53,14 @@ module Refinements | |
| 53 53 | 
             
                  def delete_suffix(pattern) = parent.join %(#{name.sub(/#{pattern}\z/, "")}#{extname})
         | 
| 54 54 |  | 
| 55 55 | 
             
                  def directories pattern = "*", flag: File::FNM_SYSCASE
         | 
| 56 | 
            -
                    glob(pattern, flag).select(&:directory?) | 
| 56 | 
            +
                    glob(pattern, flag).select(&:directory?)
         | 
| 57 57 | 
             
                  end
         | 
| 58 58 |  | 
| 59 59 | 
             
                  def empty = file? ? (truncate(0) and self) : remove_tree.make_dir
         | 
| 60 60 |  | 
| 61 61 | 
             
                  def extensions = basename.to_s.split(/(?=\.)+/).tap(&:shift)
         | 
| 62 62 |  | 
| 63 | 
            -
                  def files(pattern = "*", flag: File::FNM_SYSCASE) = glob(pattern, flag).select(&:file?) | 
| 63 | 
            +
                  def files(pattern = "*", flag: File::FNM_SYSCASE) = glob(pattern, flag).select(&:file?)
         | 
| 64 64 |  | 
| 65 65 | 
             
                  def gsub(pattern, replacement) = self.class.new(to_s.gsub(pattern, replacement))
         | 
| 66 66 |  | 
    
        data/refinements.gemspec
    CHANGED
    
    | @@ -2,7 +2,7 @@ | |
| 2 2 |  | 
| 3 3 | 
             
            Gem::Specification.new do |spec|
         | 
| 4 4 | 
             
              spec.name = "refinements"
         | 
| 5 | 
            -
              spec.version = "12. | 
| 5 | 
            +
              spec.version = "12.9.0"
         | 
| 6 6 | 
             
              spec.authors = ["Brooke Kuhlmann"]
         | 
| 7 7 | 
             
              spec.email = ["brooke@alchemists.io"]
         | 
| 8 8 | 
             
              spec.homepage = "https://alchemists.io/projects/refinements"
         | 
| @@ -12,7 +12,7 @@ Gem::Specification.new do |spec| | |
| 12 12 | 
             
              spec.metadata = {
         | 
| 13 13 | 
             
                "bug_tracker_uri" => "https://github.com/bkuhlmann/refinements/issues",
         | 
| 14 14 | 
             
                "changelog_uri" => "https://alchemists.io/projects/refinements/versions",
         | 
| 15 | 
            -
                " | 
| 15 | 
            +
                "homepage_uri" => "https://alchemists.io/projects/refinements",
         | 
| 16 16 | 
             
                "funding_uri" => "https://github.com/sponsors/bkuhlmann",
         | 
| 17 17 | 
             
                "label" => "Refinements",
         | 
| 18 18 | 
             
                "rubygems_mfa_required" => "true",
         | 
| @@ -22,7 +22,7 @@ Gem::Specification.new do |spec| | |
| 22 22 | 
             
              spec.signing_key = Gem.default_key_path
         | 
| 23 23 | 
             
              spec.cert_chain = [Gem.default_cert_path]
         | 
| 24 24 |  | 
| 25 | 
            -
              spec.required_ruby_version = " | 
| 25 | 
            +
              spec.required_ruby_version = ">= 3.3", "<= 3.4"
         | 
| 26 26 |  | 
| 27 27 | 
             
              spec.files = Dir["*.gemspec", "lib/**/*"]
         | 
| 28 28 | 
             
              spec.extra_rdoc_files = Dir["README*", "LICENSE*"]
         | 
    
        data.tar.gz.sig
    CHANGED
    
    | Binary file | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: refinements
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 12. | 
| 4 | 
            +
              version: 12.9.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Brooke Kuhlmann
         | 
| @@ -35,7 +35,7 @@ cert_chain: | |
| 35 35 | 
             
              3n5C8/6Zh9DYTkpcwPSuIfAga6wf4nXc9m6JAw8AuMLaiWN/r/2s4zJsUHYERJEu
         | 
| 36 36 | 
             
              gZGm4JqtuSg8pYjPeIJxS960owq+SfuC+jxqmRA54BisFCv/0VOJi7tiJVY=
         | 
| 37 37 | 
             
              -----END CERTIFICATE-----
         | 
| 38 | 
            -
            date: 2024- | 
| 38 | 
            +
            date: 2024-10-01 00:00:00.000000000 Z
         | 
| 39 39 | 
             
            dependencies: []
         | 
| 40 40 | 
             
            description:
         | 
| 41 41 | 
             
            email:
         | 
| @@ -73,7 +73,7 @@ licenses: | |
| 73 73 | 
             
            metadata:
         | 
| 74 74 | 
             
              bug_tracker_uri: https://github.com/bkuhlmann/refinements/issues
         | 
| 75 75 | 
             
              changelog_uri: https://alchemists.io/projects/refinements/versions
         | 
| 76 | 
            -
               | 
| 76 | 
            +
              homepage_uri: https://alchemists.io/projects/refinements
         | 
| 77 77 | 
             
              funding_uri: https://github.com/sponsors/bkuhlmann
         | 
| 78 78 | 
             
              label: Refinements
         | 
| 79 79 | 
             
              rubygems_mfa_required: 'true'
         | 
| @@ -84,16 +84,19 @@ require_paths: | |
| 84 84 | 
             
            - lib
         | 
| 85 85 | 
             
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 86 86 | 
             
              requirements:
         | 
| 87 | 
            -
              - - " | 
| 87 | 
            +
              - - ">="
         | 
| 88 88 | 
             
                - !ruby/object:Gem::Version
         | 
| 89 89 | 
             
                  version: '3.3'
         | 
| 90 | 
            +
              - - "<="
         | 
| 91 | 
            +
                - !ruby/object:Gem::Version
         | 
| 92 | 
            +
                  version: '3.4'
         | 
| 90 93 | 
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 91 94 | 
             
              requirements:
         | 
| 92 95 | 
             
              - - ">="
         | 
| 93 96 | 
             
                - !ruby/object:Gem::Version
         | 
| 94 97 | 
             
                  version: '0'
         | 
| 95 98 | 
             
            requirements: []
         | 
| 96 | 
            -
            rubygems_version: 3.5. | 
| 99 | 
            +
            rubygems_version: 3.5.20
         | 
| 97 100 | 
             
            signing_key:
         | 
| 98 101 | 
             
            specification_version: 4
         | 
| 99 102 | 
             
            summary: A collection of core object refinements.
         | 
    
        metadata.gz.sig
    CHANGED
    
    | Binary file |