BSON::ObjectId conversion function to pass through ObjectIds

XMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Done
    • Priority: Major - P3
    • bson-4.0.0
    • Affects Version/s: 1.12.1
    • Component/s: BSON
    • None
    • None
    • Minor Change
    • None
    • None
    • None
    • None
    • None
    • None

      The function BSON::ObjectId() is currently a simple wrapper for BSON::ObjectId.from_string().

      However, the signature of BSON::ObjectId() suggests that it is a conversion function. Conversion functions generally take different kinds of input and converts it do the desired type. They typically return the input if the input already is of the correct type.

      BSON::ObjectId breaks this convention by throwing an error if the input is already an ObjectId.

      Here's a general discussion on ruby conversion function idioms: http://devblog.avdi.org/2012/05/07/a-ruby-conversion-idiom/

      I've implemented this here: https://github.com/jesjos/mongo-ruby-driver/commit/22c0cb838bf7ca6f7979ea4f334d3a11c481b8a6

        1. conversion-function.diff
          0.8 kB
          Olle Jonsson

            Assignee:
            Durran Jordan
            Reporter:
            Jesper Josefsson
            Votes:
            2 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: