code-ruby 0.14.0 → 0.14.1
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
- data/Gemfile.lock +1 -1
- data/lib/code/object/dictionary.rb +37 -0
- data/lib/code/version.rb +1 -1
- data/spec/code_spec.rb +2 -0
- metadata +1 -1
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 4457f2b10410f6514df4f0eebb52d52931724e2b448bd8e179650942f78aba9f
         | 
| 4 | 
            +
              data.tar.gz: c9a3214b391d5a39aa185dd48ad6bde35bbd537616b93d626ff6686fc341ed9a
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 6ba9119d592685a669c174ead2554725ec5586f25bcf41b3c9c418fb95965327cf0e84f1797e3dd83abc7c4cfe4bb9be4ed2f2fbd7fb9e98de94571b83c53647
         | 
| 7 | 
            +
              data.tar.gz: e1c928ad8bbeab9b0101af715cea94ebefa8540465ae4482e7a8afa8d5e88436a800b8097e51a44b624bb8171c0940397f1eb4b871269d130eb2453e74fa3da3
         | 
    
        data/Gemfile.lock
    CHANGED
    
    
| @@ -107,6 +107,9 @@ class Code | |
| 107 107 | 
             
                    when "merge"
         | 
| 108 108 | 
             
                      sig(args) { [Dictionary.repeat, Function.maybe] }
         | 
| 109 109 | 
             
                      code_merge(*arguments.raw, **globals)
         | 
| 110 | 
            +
                    when "merge!"
         | 
| 111 | 
            +
                      sig(args) { [Dictionary.repeat, Function.maybe] }
         | 
| 112 | 
            +
                      code_merge!(*arguments.raw, **globals)
         | 
| 110 113 | 
             
                    when "nine?"
         | 
| 111 114 | 
             
                      sig(args)
         | 
| 112 115 | 
             
                      code_nine?
         | 
| @@ -470,6 +473,40 @@ class Code | |
| 470 473 | 
             
                    )
         | 
| 471 474 | 
             
                  end
         | 
| 472 475 |  | 
| 476 | 
            +
                  def code_merge!(*arguments, **globals)
         | 
| 477 | 
            +
                    conflict =
         | 
| 478 | 
            +
                      (
         | 
| 479 | 
            +
                        if arguments.last.is_a?(Function) && arguments.size > 1
         | 
| 480 | 
            +
                          arguments.last
         | 
| 481 | 
            +
                        end
         | 
| 482 | 
            +
                      )
         | 
| 483 | 
            +
             | 
| 484 | 
            +
                    arguments = arguments[..-2] if conflict
         | 
| 485 | 
            +
             | 
| 486 | 
            +
                    index = 0
         | 
| 487 | 
            +
             | 
| 488 | 
            +
                    raw.merge!(*arguments.map(&:raw)) do |key, old_value, new_value|
         | 
| 489 | 
            +
                      if conflict
         | 
| 490 | 
            +
                        conflict
         | 
| 491 | 
            +
                          .call(
         | 
| 492 | 
            +
                            arguments:
         | 
| 493 | 
            +
                              List.new(
         | 
| 494 | 
            +
                                [key, old_value, new_value, Integer.new(index), self]
         | 
| 495 | 
            +
                              ),
         | 
| 496 | 
            +
                            **globals
         | 
| 497 | 
            +
                          )
         | 
| 498 | 
            +
                          .tap { index += 1 }
         | 
| 499 | 
            +
                      else
         | 
| 500 | 
            +
                        new_value.tap { index += 1 }
         | 
| 501 | 
            +
                      end
         | 
| 502 | 
            +
                    rescue Error::Next => e
         | 
| 503 | 
            +
                      index += 1
         | 
| 504 | 
            +
                      e.value || Nothing.new
         | 
| 505 | 
            +
                    end
         | 
| 506 | 
            +
             | 
| 507 | 
            +
                    self
         | 
| 508 | 
            +
                  end
         | 
| 509 | 
            +
             | 
| 473 510 | 
             
                  def code_nine?
         | 
| 474 511 | 
             
                    code_size.code_nine?
         | 
| 475 512 | 
             
                  end
         | 
    
        data/lib/code/version.rb
    CHANGED
    
    
    
        data/spec/code_spec.rb
    CHANGED
    
    | @@ -270,6 +270,8 @@ RSpec.describe Code do | |
| 270 270 | 
             
                %w[1.to_json "1"],
         | 
| 271 271 | 
             
                %w[1.0.to_json '"1.0"'],
         | 
| 272 272 | 
             
                %w[1.1.to_json '"1.1"'],
         | 
| 273 | 
            +
                ["a = {} a.merge!(a: 1) a", "{a: 1}"],
         | 
| 274 | 
            +
                ["a = {} a.merge(a: 1) a", "{}"],
         | 
| 273 275 | 
             
                ["", ""]
         | 
| 274 276 | 
             
              ].each do |input, expected|
         | 
| 275 277 | 
             
                it "#{input} == #{expected}" do
         |