Uploaded image for project: 'Couchbase Ruby client library'
  1. Couchbase Ruby client library
  2. RCBC-100

Provide proper attribute inheritance when subclassing Couchbase::Model subclasses.

    XMLWordPrintable

Details

    • Improvement
    • Resolution: Fixed
    • Major
    • None
    • None
    • None
    • Security Level: Public
    • None

    Description

      (Pull request to fix this can be found here: https://github.com/couchbase/couchbase-ruby-model/pull/2 )

      Currently, Couchbase::Model stores attributes (and views) in a class variable set to a mutable hash. This breaks the expected subclass attribute inheritance behavior that ActiveModel provides.

      Example:

      class A < Couchbase::Model
      attribute :one
      end

      class B < A
      attribute :two
      end

      B.attributes #=> {:one => nil, :two => nil}
      A.attributes #=> {:one => nil, :two => nil}
      B.attributes.object_id == A.attributes.object_id #=> true

      This patch enables proper inheritance when ::Rails is present by using Class#class_attribute and detecting subclass additions to attribute:

      class A < Couchbase::Model
      attribute :one
      end

      class B < A
      attribute :two
      end

      A.attributes #=> {:one => nil}
      B.attributes #=> {:one => nil, :two => nil}
      B.attributes.object_id != A.attributes.object_id #=> true

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            avsej Sergey Avseyev
            mje113 Mike Evans
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes

                PagerDuty