Equality and better metaprogramming for RecordRef.#167
Equality and better metaprogramming for RecordRef.#167jdfrens wants to merge 5 commits intoNetSweet:masterfrom
Conversation
* Only the internal id is considered. * Like ActiveRecord, a nil internal id is never equal to anything else. * Override #hash appropriately. * Compare and hash on string representations of internal ids.
|
My instinct here is to leave the equality operators working as is. This seams to break the principal of least surprise: ActiveRecord, and other DB abstractions I've worked with, don't operate like this; I'm hesitant to break convention with the gems and systems I've worked with in the past. Any thoughts here @greggroth? |
Could you explain why you needed to implement this? My meta programming knowledge might be a bit lacking here. Thanks for the PRs! Keep them coming! |
|
Actually, the definition of I just now found a blog post which suggests a few changes to my definition (like calling |
|
If you don't define # WITHOUT respond_to_missing?
[1] (pry) main: 0> rr = NetSuite::Records::RecordRef.new(foo: 5)
#<NetSuite::Records::RecordRef:0x007fca15b280b8 @internal_id=nil, @external_id=nil, @type=nil, @attributes={:foo=>5}>
[2] (pry) main: 0> rr.foo
5
[3] (pry) main: 0> rr.respond_to?(:foo)
false
[4] (pry) main: 0> rr.method(:foo)
NameError: undefined method `foo' for class `NetSuite::Records::RecordRef'
from (pry):4:in `method'Honestly, I have no need for this right now, but I wanted equality for my specs. Since I was in this file anyway, I thought I'd add |
There was a problem hiding this comment.
This seems reasonable to me
# Conflicts: # lib/netsuite/records/customer.rb # spec/netsuite/records/customer_spec.rb
|
Looks like there's a year old PR to add |
Improvements to
NetSuite::Records::RecordRef.Improved metaprogramming:
#respond_to_missing?(to complement#method_missing).Added equality:
#hashis overridden to hash on the string version of the internal id.