[RCBC-100] Provide proper attribute inheritance when subclassing Couchbase::Model subclasses. Created: 07/Dec/12 Updated: 08/Feb/13 Resolved: 08/Feb/13 |
|
| Status: | Closed |
| Project: | Couchbase Ruby client library |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Security Level: | Public |
| Type: | Improvement | Priority: | Major |
| Reporter: | Mike Evans | Assignee: | Sergey Avseyev |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| 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 |
| Comments |
| Comment by Mike Evans [ 10/Dec/12 ] |
| Pull request was updated with an improved patch and passing tests. |
| Comment by Sergey Avseyev [ 08/Feb/13 ] |
| http://review.couchbase.org/23392 |