refinements 7.3.0 → 7.4.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 +1 -2
- data.tar.gz.sig +0 -0
- data/README.adoc +41 -0
- data/lib/refinements/hashes.rb +33 -2
- data/lib/refinements/identity.rb +1 -1
- data/lib/refinements/pathnames.rb +8 -0
- data/lib/refinements/strings.rb +4 -0
- metadata +2 -2
- 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: aa83a3ce542b62b6d89204aea8ac2411565a401f26150bfcdc64a2d4334d0313
         | 
| 4 | 
            +
              data.tar.gz: c34503ce9aa7b522eac87ff66384fc8c1815c5907e4048a6023208f948a33cd1
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 8bc6f8633db7a9caed51998e190aeccb77b74a755d83a8a982e93d7c4c9576044598e626b9457fb40da667aff76c9d87314ad42f4e2815d8287435eee5d71e2a
         | 
| 7 | 
            +
              data.tar.gz: c23828f5179b57747cd0a173baa7deeee2fc1513791ecf1042612a23addf8443c7c012c6f316596b197a8765904e66d93f31141037271673e50bf2a6b9b56da8
         | 
    
        checksums.yaml.gz.sig
    CHANGED
    
    | @@ -1,2 +1 @@ | |
| 1 | 
            -
             | 
| 2 | 
            -
            ^��8y��P���~p��C�մ�8WWla�A�bϓ�Q
         | 
| 1 | 
            +
            ��%�z���z,
         | 
    
        data.tar.gz.sig
    CHANGED
    
    | Binary file | 
    
        data/README.adoc
    CHANGED
    
    | @@ -33,13 +33,21 @@ file for manipulation and immediate writing back to the same file. | |
| 33 33 | 
             
            ** `#symbolize_keys!` - Converts keys to symbols while modifying itself.
         | 
| 34 34 | 
             
            ** `#deep_merge` - Merges deeply nested hashes together without modifying itself.
         | 
| 35 35 | 
             
            ** `#deep_merge!` - Merges deeply nested hashes together while modifying itself.
         | 
| 36 | 
            +
            ** `#deep_symbolize_keys` - Symbolizes keys of nested hash without modifying itself. Does not handle
         | 
| 37 | 
            +
               nested arrays, though.
         | 
| 38 | 
            +
            ** `#deep_symbolize_keys!` - Symbolizes keys of nested hash while modifying itself. Does not handle
         | 
| 39 | 
            +
               nested arrays, though.
         | 
| 40 | 
            +
            ** `#recurse` - Applies block to nested hash. Does not handle nested arrays, though.
         | 
| 41 | 
            +
            ** `#rekey` - Transforms keys per mapping (size of mapping can vary).
         | 
| 36 42 | 
             
            ** `#reverse_merge` - Merges calling hash into passed in hash without modifying calling hash.
         | 
| 37 43 | 
             
            ** `#reverse_merge!` - Merges calling hash into passed in hash while modifying calling hash.
         | 
| 38 44 | 
             
            ** `#use` - Passes each hash value as a block argument for further processing.
         | 
| 39 45 | 
             
            * *Pathnames*:
         | 
| 40 46 | 
             
            ** `#name` - Answers file name without extension.
         | 
| 41 47 | 
             
            ** `#copy` - Copies file from current location to new location.
         | 
| 48 | 
            +
            ** `#directories` - Answers all or filtered directories for current path.
         | 
| 42 49 | 
             
            ** `#extensions` - Answers file extensions as an array.
         | 
| 50 | 
            +
            ** `#files` - Answers all or filtered files for current path.
         | 
| 43 51 | 
             
            ** `#relative_parent_from` - Answers relative path from parent directory. This is a complement to
         | 
| 44 52 | 
             
               `#relative_path_from`.
         | 
| 45 53 | 
             
            ** `#make_ancestors` - Ensures all ancestor directories are created for a path.
         | 
| @@ -56,6 +64,7 @@ manipulation and immediate writing back to the same file. | |
| 56 64 | 
             
            ** `#camelcase` - Answers a camelcased string.
         | 
| 57 65 | 
             
            ** `#snakecase` - Answers a snakecased string.
         | 
| 58 66 | 
             
            ** `#titleize` - Answers titleized string.
         | 
| 67 | 
            +
            ** `#to_bool` - Answers string as a boolean.
         | 
| 59 68 |  | 
| 60 69 | 
             
            == Requirements
         | 
| 61 70 |  | 
| @@ -221,6 +230,21 @@ example = {a: "A", b: {one: "One", two: "Two"}} | |
| 221 230 | 
             
            example.deep_merge! b: {one: 1} # => {a: "A", b: {one: 1, two: "Two"}}
         | 
| 222 231 | 
             
            example # => {a: "A", b: {one: 1, two: "Two"}}
         | 
| 223 232 |  | 
| 233 | 
            +
            example = {"a" => {"b" => 2}}
         | 
| 234 | 
            +
            example.deep_symbolize_keys # => {a: {b: 1}}
         | 
| 235 | 
            +
            example # => {"a" => {"b" => 2}}
         | 
| 236 | 
            +
             | 
| 237 | 
            +
            example = {"a" => {"b" => 2}}
         | 
| 238 | 
            +
            example.deep_symbolize_keys! # => {a: {b: 1}}
         | 
| 239 | 
            +
            example # => {a: {b: 1}}
         | 
| 240 | 
            +
             | 
| 241 | 
            +
            example = {"a" => {"b" => 1}}
         | 
| 242 | 
            +
            example.recurse(&:symbolize_keys) # => {a: {b: 1}}
         | 
| 243 | 
            +
            example.recurse(&:invert) # => {{"b" => 1} => "a"}
         | 
| 244 | 
            +
             | 
| 245 | 
            +
            example = {a: 1, b: 2, c: 3}
         | 
| 246 | 
            +
            example.rekey a: :amber, b: :blue # => {amber: 1, blue: 2, c: 3}
         | 
| 247 | 
            +
             | 
| 224 248 | 
             
            example = {a: 1, b: 2}
         | 
| 225 249 | 
             
            example.reverse_merge a: 0, c: 3 # => {a: 1, b: 2, c: 3}
         | 
| 226 250 | 
             
            example # => {a: 1, b: 2}
         | 
| @@ -241,8 +265,14 @@ Pathname("example.txt").name # => Pathname("example") | |
| 241 265 |  | 
| 242 266 | 
             
            Pathname("input.txt").copy Pathname("output.txt")
         | 
| 243 267 |  | 
| 268 | 
            +
            Pathname("/example").directories # => [Pathname("a"), Pathname("b")]
         | 
| 269 | 
            +
            Pathname("/example").directories "a*" # => [Pathname("a")]
         | 
| 270 | 
            +
             | 
| 244 271 | 
             
            Pathname("example.txt.erb").extensions # => [".txt", ".erb"]
         | 
| 245 272 |  | 
| 273 | 
            +
            Pathname("/example").files # => [Pathname("a.txt"), Pathname("a.png")]
         | 
| 274 | 
            +
            Pathname("/example").files "*.png" # => [Pathname("a.png")]
         | 
| 275 | 
            +
             | 
| 246 276 | 
             
            Pathname("/one/two/three").relative_parent_from("/one") # => Pathname "two"
         | 
| 247 277 |  | 
| 248 278 | 
             
            Pathname("/one/two").make_ancestors
         | 
| @@ -266,11 +296,22 @@ Pathname("example.txt").touch accessed_at: Time.now - 1, modified_at: Time.now - | |
| 266 296 | 
             
            "instant".last 3 # => "ant"
         | 
| 267 297 |  | 
| 268 298 | 
             
            " \n\t\r".blank? # => true
         | 
| 299 | 
            +
             | 
| 269 300 | 
             
            "example".up # => "Example"
         | 
| 301 | 
            +
             | 
| 270 302 | 
             
            "EXAMPLE".down # => "eXAMPLE"
         | 
| 303 | 
            +
             | 
| 271 304 | 
             
            "this_is_an_example".camelcase # => "ThisIsAnExample"
         | 
| 305 | 
            +
             | 
| 272 306 | 
             
            "ThisIsAnExample".snakecase # => "this_is_an_example"
         | 
| 307 | 
            +
             | 
| 273 308 | 
             
            "ThisIsAnExample".titleize # => "This Is An Example"
         | 
| 309 | 
            +
             | 
| 310 | 
            +
            "true".to_bool # => true
         | 
| 311 | 
            +
            "yes".to_bool # => true
         | 
| 312 | 
            +
            "1".to_bool # => true
         | 
| 313 | 
            +
            "".to_bool # => false
         | 
| 314 | 
            +
            "example".to_bool # => false
         | 
| 274 315 | 
             
            ----
         | 
| 275 316 |  | 
| 276 317 | 
             
            == Tests
         | 
    
        data/lib/refinements/hashes.rb
    CHANGED
    
    | @@ -23,10 +23,11 @@ module Refinements | |
| 23 23 | 
             
                    dup.deep_merge! other
         | 
| 24 24 | 
             
                  end
         | 
| 25 25 |  | 
| 26 | 
            -
                  # :reek:FeatureEnvy
         | 
| 27 26 | 
             
                  def deep_merge! other
         | 
| 27 | 
            +
                    clazz = self.class
         | 
| 28 | 
            +
             | 
| 28 29 | 
             
                    merge! other do |_key, this_value, other_value|
         | 
| 29 | 
            -
                      if this_value.is_a?( | 
| 30 | 
            +
                      if this_value.is_a?(clazz) && other_value.is_a?(clazz)
         | 
| 30 31 | 
             
                        this_value.deep_merge other_value
         | 
| 31 32 | 
             
                      else
         | 
| 32 33 | 
             
                        other_value
         | 
| @@ -34,11 +35,41 @@ module Refinements | |
| 34 35 | 
             
                    end
         | 
| 35 36 | 
             
                  end
         | 
| 36 37 |  | 
| 38 | 
            +
                  def deep_symbolize_keys
         | 
| 39 | 
            +
                    recurse(&:symbolize_keys)
         | 
| 40 | 
            +
                  end
         | 
| 41 | 
            +
             | 
| 42 | 
            +
                  def deep_symbolize_keys!
         | 
| 43 | 
            +
                    recurse(&:symbolize_keys!)
         | 
| 44 | 
            +
                  end
         | 
| 45 | 
            +
             | 
| 46 | 
            +
                  def recurse &block
         | 
| 47 | 
            +
                    return self unless block_given?
         | 
| 48 | 
            +
             | 
| 49 | 
            +
                    transform = yield self
         | 
| 50 | 
            +
             | 
| 51 | 
            +
                    transform.each do |key, value|
         | 
| 52 | 
            +
                      transform[key] = value.recurse(&block) if value.is_a? self.class
         | 
| 53 | 
            +
                    end
         | 
| 54 | 
            +
                  end
         | 
| 55 | 
            +
             | 
| 56 | 
            +
                  def rekey mapping = {}
         | 
| 57 | 
            +
                    return self if mapping.empty?
         | 
| 58 | 
            +
             | 
| 59 | 
            +
                    transform_keys { |key| mapping[key] || key }
         | 
| 60 | 
            +
                  end
         | 
| 61 | 
            +
             | 
| 62 | 
            +
                  def rekey! mapping = {}
         | 
| 63 | 
            +
                    replace rekey(mapping)
         | 
| 64 | 
            +
                  end
         | 
| 65 | 
            +
             | 
| 37 66 | 
             
                  def reverse_merge other
         | 
| 67 | 
            +
                    warn "[DEPRECATION]: #reverse_merge is deprecated, use #merge instead."
         | 
| 38 68 | 
             
                    other.merge self
         | 
| 39 69 | 
             
                  end
         | 
| 40 70 |  | 
| 41 71 | 
             
                  def reverse_merge! other
         | 
| 72 | 
            +
                    warn "[DEPRECATION]: #reverse_merge! is deprecated, use #merge! instead."
         | 
| 42 73 | 
             
                    merge!(other) { |_key, old_value, _new_value| old_value }
         | 
| 43 74 | 
             
                  end
         | 
| 44 75 |  | 
    
        data/lib/refinements/identity.rb
    CHANGED
    
    
| @@ -15,10 +15,18 @@ module Refinements | |
| 15 15 | 
             
                    self
         | 
| 16 16 | 
             
                  end
         | 
| 17 17 |  | 
| 18 | 
            +
                  def directories pattern = "*"
         | 
| 19 | 
            +
                    glob(pattern).select(&:directory?).sort
         | 
| 20 | 
            +
                  end
         | 
| 21 | 
            +
             | 
| 18 22 | 
             
                  def extensions
         | 
| 19 23 | 
             
                    basename.to_s.split(/(?=\.)+/).tap(&:shift)
         | 
| 20 24 | 
             
                  end
         | 
| 21 25 |  | 
| 26 | 
            +
                  def files pattern = "*"
         | 
| 27 | 
            +
                    glob(pattern).select(&:file?).sort
         | 
| 28 | 
            +
                  end
         | 
| 29 | 
            +
             | 
| 22 30 | 
             
                  def relative_parent_from root
         | 
| 23 31 | 
             
                    relative_path_from(root).parent
         | 
| 24 32 | 
             
                  end
         | 
    
        data/lib/refinements/strings.rb
    CHANGED
    
    
    
        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: 7. | 
| 4 | 
            +
              version: 7.4.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Brooke Kuhlmann
         | 
| @@ -28,7 +28,7 @@ cert_chain: | |
| 28 28 | 
             
              2XV8FRa7/JimI07sPLC13eLY3xd/aYTi85Z782KIA4j0G8XEEWAX0ouBhlXPocZv
         | 
| 29 29 | 
             
              QWc=
         | 
| 30 30 | 
             
              -----END CERTIFICATE-----
         | 
| 31 | 
            -
            date: 2020-05- | 
| 31 | 
            +
            date: 2020-05-21 00:00:00.000000000 Z
         | 
| 32 32 | 
             
            dependencies:
         | 
| 33 33 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 34 34 | 
             
              name: bundler-audit
         | 
    
        metadata.gz.sig
    CHANGED
    
    | Binary file |