bson 2.0.0.rc1-java → 2.0.0.rc2-java
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.
Potentially problematic release.
This version of bson might be problematic. Click here for more details.
- data.tar.gz.sig +0 -0
- data/Rakefile +7 -2
- data/lib/bson-ruby.jar +0 -0
- data/lib/bson/code_with_scope.rb +6 -4
- data/lib/bson/hash.rb +2 -2
- data/lib/bson/object_id.rb +38 -0
- data/lib/bson/string.rb +2 -2
- data/lib/bson/symbol.rb +1 -1
- data/lib/bson/version.rb +1 -1
- data/spec/bson/code_with_scope_spec.rb +10 -6
- data/spec/bson/object_id_spec.rb +26 -0
- data/spec/bson/string_spec.rb +1 -1
- data/spec/bson/symbol_spec.rb +10 -0
- metadata +4 -4
- metadata.gz.sig +0 -0
    
        data.tar.gz.sig
    CHANGED
    
    | Binary file | 
    
        data/Rakefile
    CHANGED
    
    | @@ -81,8 +81,13 @@ end | |
| 81 81 | 
             
            task :release => :build do
         | 
| 82 82 | 
             
              system "git tag -a v#{BSON::VERSION} -m 'Tagging release: #{BSON::VERSION}'"
         | 
| 83 83 | 
             
              system "git push --tags"
         | 
| 84 | 
            -
               | 
| 85 | 
            -
             | 
| 84 | 
            +
              if jruby?
         | 
| 85 | 
            +
                system "gem push bson-#{BSON::VERSION}-java.gem"
         | 
| 86 | 
            +
                system "rm bson-#{BSON::VERSION}-java.gem"
         | 
| 87 | 
            +
              else
         | 
| 88 | 
            +
                system "gem push bson-#{BSON::VERSION}.gem"
         | 
| 89 | 
            +
                system "rm bson-#{BSON::VERSION}.gem"
         | 
| 90 | 
            +
              end
         | 
| 86 91 | 
             
            end
         | 
| 87 92 |  | 
| 88 93 | 
             
            namespace :benchmark do
         | 
    
        data/lib/bson-ruby.jar
    CHANGED
    
    | Binary file | 
    
        data/lib/bson/code_with_scope.rb
    CHANGED
    
    | @@ -89,10 +89,13 @@ module BSON | |
| 89 89 | 
             
                #
         | 
| 90 90 | 
             
                # @since 2.0.0
         | 
| 91 91 | 
             
                def to_bson(encoded = ''.force_encoding(BINARY))
         | 
| 92 | 
            -
                   | 
| 92 | 
            +
                  # -1 because we are removing an extra byte
         | 
| 93 | 
            +
                  out = encode_with_placeholder_and_null(BSON_ADJUST - 1, encoded) do |encoded|
         | 
| 93 94 | 
             
                    javascript.to_bson(encoded)
         | 
| 94 95 | 
             
                    scope.to_bson(encoded)
         | 
| 95 96 | 
             
                  end
         | 
| 97 | 
            +
                  # an extra null byte has been added; we must remove it
         | 
| 98 | 
            +
                  out.chop!
         | 
| 96 99 | 
             
                end
         | 
| 97 100 |  | 
| 98 101 | 
             
                # Deserialize a code with scope from BSON.
         | 
| @@ -105,9 +108,8 @@ module BSON | |
| 105 108 | 
             
                #
         | 
| 106 109 | 
             
                # @since 2.0.0
         | 
| 107 110 | 
             
                def self.from_bson(bson)
         | 
| 108 | 
            -
                   | 
| 109 | 
            -
                   | 
| 110 | 
            -
                  new(code_with_scope.read(length).from_bson_string.chop!)
         | 
| 111 | 
            +
                  bson.read(4) # Throw away the total length.
         | 
| 112 | 
            +
                  new(bson.read(Int32.from_bson(bson)).from_bson_string.chop!, ::Hash.from_bson(bson))
         | 
| 111 113 | 
             
                end
         | 
| 112 114 |  | 
| 113 115 | 
             
                # Register this type when the module is loaded.
         | 
    
        data/lib/bson/hash.rb
    CHANGED
    
    | @@ -31,7 +31,7 @@ module BSON | |
| 31 31 | 
             
                # Get the hash as encoded BSON.
         | 
| 32 32 | 
             
                #
         | 
| 33 33 | 
             
                # @example Get the hash as encoded BSON.
         | 
| 34 | 
            -
                #   { field | 
| 34 | 
            +
                #   { "field" => "value" }.to_bson
         | 
| 35 35 | 
             
                #
         | 
| 36 36 | 
             
                # @return [ String ] The encoded string.
         | 
| 37 37 | 
             
                #
         | 
| @@ -52,7 +52,7 @@ module BSON | |
| 52 52 |  | 
| 53 53 | 
             
                  # Deserialize the hash from BSON.
         | 
| 54 54 | 
             
                  #
         | 
| 55 | 
            -
                  # @param [  | 
| 55 | 
            +
                  # @param [ IO ] bson The bson representing a hash.
         | 
| 56 56 | 
             
                  #
         | 
| 57 57 | 
             
                  # @return [ Array ] The decoded hash.
         | 
| 58 58 | 
             
                  #
         | 
    
        data/lib/bson/object_id.rb
    CHANGED
    
    | @@ -115,6 +115,44 @@ module BSON | |
| 115 115 | 
             
                  to_bson.hash
         | 
| 116 116 | 
             
                end
         | 
| 117 117 |  | 
| 118 | 
            +
                # Get a nice string for use with object inspection.
         | 
| 119 | 
            +
                #
         | 
| 120 | 
            +
                # @example Inspect the object id.
         | 
| 121 | 
            +
                #   obhect_id.inspect
         | 
| 122 | 
            +
                #
         | 
| 123 | 
            +
                # @return [ String ] The object id in form BSON::ObjectId('id')
         | 
| 124 | 
            +
                #
         | 
| 125 | 
            +
                # @since 2.0.0
         | 
| 126 | 
            +
                def inspect
         | 
| 127 | 
            +
                  "BSON::ObjectId('#{to_s}')"
         | 
| 128 | 
            +
                end
         | 
| 129 | 
            +
             | 
| 130 | 
            +
                # Dump the raw bson when calling Marshal.dump.
         | 
| 131 | 
            +
                #
         | 
| 132 | 
            +
                # @example Dump the raw bson.
         | 
| 133 | 
            +
                #   Marshal.dump(object_id)
         | 
| 134 | 
            +
                #
         | 
| 135 | 
            +
                # @return [ String ] The raw bson bytes.
         | 
| 136 | 
            +
                #
         | 
| 137 | 
            +
                # @since 2.0.0
         | 
| 138 | 
            +
                def marshal_dump
         | 
| 139 | 
            +
                  to_bson
         | 
| 140 | 
            +
                end
         | 
| 141 | 
            +
             | 
| 142 | 
            +
                # Unmarshal the data into an object id.
         | 
| 143 | 
            +
                #
         | 
| 144 | 
            +
                # @example Unmarshal the data.
         | 
| 145 | 
            +
                #   Marshal.load(data)
         | 
| 146 | 
            +
                #
         | 
| 147 | 
            +
                # @param [ String ] data The raw bson bytes.
         | 
| 148 | 
            +
                #
         | 
| 149 | 
            +
                # @return [ String ] The raw bson bytes.
         | 
| 150 | 
            +
                #
         | 
| 151 | 
            +
                # @since 2.0.0
         | 
| 152 | 
            +
                def marshal_load(data)
         | 
| 153 | 
            +
                  @raw_data = data
         | 
| 154 | 
            +
                end
         | 
| 155 | 
            +
             | 
| 118 156 | 
             
                # Get the object id as it's raw BSON data.
         | 
| 119 157 | 
             
                #
         | 
| 120 158 | 
             
                # @example Get the raw bson bytes.
         | 
    
        data/lib/bson/string.rb
    CHANGED
    
    | @@ -1,3 +1,4 @@ | |
| 1 | 
            +
            # -*- coding: utf-8 -*-
         | 
| 1 2 | 
             
            # Copyright (C) 2013 10gen Inc.
         | 
| 2 3 | 
             
            #
         | 
| 3 4 | 
             
            # Licensed under the Apache License, Version 2.0 (the "License");
         | 
| @@ -59,7 +60,6 @@ module BSON | |
| 59 60 | 
             
                #
         | 
| 60 61 | 
             
                # @since 2.0.0
         | 
| 61 62 | 
             
                def to_bson_key(encoded = ''.force_encoding(BINARY))
         | 
| 62 | 
            -
                  check_for_illegal_characters!
         | 
| 63 63 | 
             
                  to_bson_cstring(encoded)
         | 
| 64 64 | 
             
                end
         | 
| 65 65 |  | 
| @@ -168,7 +168,7 @@ module BSON | |
| 168 168 |  | 
| 169 169 | 
             
                def check_for_illegal_characters!
         | 
| 170 170 | 
             
                  if include?(NULL_BYTE)
         | 
| 171 | 
            -
                    raise  | 
| 171 | 
            +
                    raise(ArgumentError, "Illegal C-String '#{self}' contains a null byte.")
         | 
| 172 172 | 
             
                  end
         | 
| 173 173 | 
             
                end
         | 
| 174 174 |  | 
    
        data/lib/bson/symbol.rb
    CHANGED
    
    
    
        data/lib/bson/version.rb
    CHANGED
    
    
| @@ -40,8 +40,8 @@ describe BSON::CodeWithScope do | |
| 40 40 | 
             
                end
         | 
| 41 41 | 
             
                let(:obj) { described_class.new(code, scope) }
         | 
| 42 42 | 
             
                let(:bson) do
         | 
| 43 | 
            -
                  "#{ | 
| 44 | 
            -
                  "#{scope.to_bson} | 
| 43 | 
            +
                  "#{47.to_bson}#{(code.length + 1).to_bson}#{code}#{BSON::NULL_BYTE}" +
         | 
| 44 | 
            +
                  "#{scope.to_bson}"
         | 
| 45 45 | 
             
                end
         | 
| 46 46 |  | 
| 47 47 | 
             
                it_behaves_like "a bson element"
         | 
| @@ -53,18 +53,22 @@ describe BSON::CodeWithScope do | |
| 53 53 | 
             
                let(:type) { 15.chr }
         | 
| 54 54 | 
             
                let(:code) { "this.value == name" }
         | 
| 55 55 | 
             
                let(:scope) do
         | 
| 56 | 
            -
                  {  | 
| 56 | 
            +
                  { "name" => "test" }
         | 
| 57 57 | 
             
                end
         | 
| 58 58 | 
             
                let(:obj) { described_class.new(code, scope) }
         | 
| 59 59 | 
             
                let(:bson) { StringIO.new(obj.to_bson) }
         | 
| 60 | 
            -
                let(:deserialized) { described_class.from_bson(bson) }
         | 
| 60 | 
            +
                let!(:deserialized) { described_class.from_bson(bson) }
         | 
| 61 61 |  | 
| 62 62 | 
             
                it "deserializes the javascript" do
         | 
| 63 63 | 
             
                  expect(deserialized.javascript).to eq(code)
         | 
| 64 64 | 
             
                end
         | 
| 65 65 |  | 
| 66 | 
            -
                it " | 
| 67 | 
            -
                  expect(deserialized.scope).to  | 
| 66 | 
            +
                it "deserializes the scope" do
         | 
| 67 | 
            +
                  expect(deserialized.scope).to eq(scope)
         | 
| 68 | 
            +
                end
         | 
| 69 | 
            +
             | 
| 70 | 
            +
                it "does not leave any extra bytes" do
         | 
| 71 | 
            +
                  expect(bson.read(1)).to be_nil
         | 
| 68 72 | 
             
                end
         | 
| 69 73 | 
             
              end
         | 
| 70 74 | 
             
            end
         | 
    
        data/spec/bson/object_id_spec.rb
    CHANGED
    
    | @@ -383,6 +383,17 @@ describe BSON::ObjectId do | |
| 383 383 | 
             
                end
         | 
| 384 384 | 
             
              end
         | 
| 385 385 |  | 
| 386 | 
            +
              describe "#inspect" do
         | 
| 387 | 
            +
             | 
| 388 | 
            +
                let(:object_id) do
         | 
| 389 | 
            +
                  described_class.new
         | 
| 390 | 
            +
                end
         | 
| 391 | 
            +
             | 
| 392 | 
            +
                it "returns the inspection with the object id to_s" do
         | 
| 393 | 
            +
                  expect(object_id.inspect).to eq("BSON::ObjectId('#{object_id.to_s}')")
         | 
| 394 | 
            +
                end
         | 
| 395 | 
            +
              end
         | 
| 396 | 
            +
             | 
| 386 397 | 
             
              describe ".legal?" do
         | 
| 387 398 |  | 
| 388 399 | 
             
                context "when the string is too short to be an object id" do
         | 
| @@ -418,6 +429,21 @@ describe BSON::ObjectId do | |
| 418 429 | 
             
                end
         | 
| 419 430 | 
             
              end
         | 
| 420 431 |  | 
| 432 | 
            +
              describe "#marshal_dump" do
         | 
| 433 | 
            +
             | 
| 434 | 
            +
                let(:object_id) do
         | 
| 435 | 
            +
                  described_class.new
         | 
| 436 | 
            +
                end
         | 
| 437 | 
            +
             | 
| 438 | 
            +
                let(:dumped) do
         | 
| 439 | 
            +
                  Marshal.dump(object_id)
         | 
| 440 | 
            +
                end
         | 
| 441 | 
            +
             | 
| 442 | 
            +
                it "dumps the raw bytes data" do
         | 
| 443 | 
            +
                  expect(Marshal.load(dumped)).to eq(object_id)
         | 
| 444 | 
            +
                end
         | 
| 445 | 
            +
              end
         | 
| 446 | 
            +
             | 
| 421 447 | 
             
              describe "#to_bson/#from_bson" do
         | 
| 422 448 |  | 
| 423 449 | 
             
                let(:time) { Time.utc(2013, 1, 1) }
         | 
    
        data/spec/bson/string_spec.rb
    CHANGED
    
    
    
        data/spec/bson/symbol_spec.rb
    CHANGED
    
    | @@ -41,5 +41,15 @@ describe Symbol do | |
| 41 41 | 
             
                it "appends to optional previous content" do
         | 
| 42 42 | 
             
                  expect(symbol.to_bson_key(previous_content)).to eq(previous_content << encoded)
         | 
| 43 43 | 
             
                end
         | 
| 44 | 
            +
             | 
| 45 | 
            +
                context 'when the symbol contains a null byte' do
         | 
| 46 | 
            +
                  let(:symbol) { :"test#{BSON::NULL_BYTE}ing" }
         | 
| 47 | 
            +
             | 
| 48 | 
            +
                  it 'raises an error' do
         | 
| 49 | 
            +
                    expect {
         | 
| 50 | 
            +
                      symbol.to_bson_key
         | 
| 51 | 
            +
                    }.to raise_error(ArgumentError)
         | 
| 52 | 
            +
                  end
         | 
| 53 | 
            +
                end
         | 
| 44 54 | 
             
              end
         | 
| 45 55 | 
             
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -2,7 +2,7 @@ | |
| 2 2 | 
             
            name: bson
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 4 | 
             
              prerelease: 6
         | 
| 5 | 
            -
              version: 2.0.0. | 
| 5 | 
            +
              version: 2.0.0.rc2
         | 
| 6 6 | 
             
            platform: java
         | 
| 7 7 | 
             
            authors:
         | 
| 8 8 | 
             
            - Tyler Brock
         | 
| @@ -34,7 +34,7 @@ cert_chain: | |
| 34 34 | 
             
              8v7zLF2XliYbfurYIwkcXs8yPn8ggApBIy9bX6VJxRs/l2+UvqzaHIFaFy/F8/GP
         | 
| 35 35 | 
             
              RNTuXsVG5NDACo7Q
         | 
| 36 36 | 
             
              -----END CERTIFICATE-----
         | 
| 37 | 
            -
            date: 2013- | 
| 37 | 
            +
            date: 2013-09-23 00:00:00.000000000 Z
         | 
| 38 38 | 
             
            dependencies: []
         | 
| 39 39 | 
             
            description: A full featured BSON specification implementation, in Ruby
         | 
| 40 40 | 
             
            email:
         | 
| @@ -117,13 +117,13 @@ require_paths: | |
| 117 117 | 
             
            - lib
         | 
| 118 118 | 
             
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 119 119 | 
             
              requirements:
         | 
| 120 | 
            -
              - -  | 
| 120 | 
            +
              - - '>='
         | 
| 121 121 | 
             
                - !ruby/object:Gem::Version
         | 
| 122 122 | 
             
                  version: 1.8.7
         | 
| 123 123 | 
             
              none: false
         | 
| 124 124 | 
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 125 125 | 
             
              requirements:
         | 
| 126 | 
            -
              - -  | 
| 126 | 
            +
              - - '>='
         | 
| 127 127 | 
             
                - !ruby/object:Gem::Version
         | 
| 128 128 | 
             
                  version: 1.3.6
         | 
| 129 129 | 
             
              none: false
         | 
    
        metadata.gz.sig
    CHANGED
    
    | Binary file |