Add respond_to_missing? to ChargeBee::Model#79
Conversation
|
|
I'm using this in a Rails project and have some places where I want to decorate the underlying |
|
Thanks for reaching out, @reagent! We'll analyze, test this, and explore merging possibilities. We'll keep you posted. |
|
Hi @sobrinho & @reagent, |
|
@cb-alish even if this would break something, this would be incorrect because that would be the correct usage: def something
result.resources.object if result.resources.respond_to?(:object)
endIf Every time a Ruby does not require you to but it is the expected implementation. Ref:
That's exactly why calling flatten doesn't work without respond_to_missing: resources.map(&:class).tally
#=> {ChargeBee::Transaction=>890,
ChargeBee::Invoice=>712,
ChargeBee::Customer=>17088,
ChargeBee::Subscription=>14774,
ChargeBee::PaymentSource=>534,
ChargeBee::Card=>6942,
ChargeBee::CreditNote=>178}
resources.flatten
#=> There's no method called to_ary [] here -- please try again. |
|
I dug through the Ruby docs across versions for As far back as Ruby
Because of that, I'm wondering if instead of raising a def method_missing(m, *args, &block)
if(@values.has_key?(m))
return @values[m]
elsif(m[0,3] == "cf_") # All the custom fields start with prefix cf_.
return nil
end
super
endIf backwards compatibility is a concern, semver would require a bump to 3.0 -- I think that's a conservative move, but maybe there are more breaking changes that the Chargebee team would want to consider before a 3.0 release? Another option would be to give it a |
|
Ideally yes, the super would be called, but I'm being conservative here and only adding the respond_to_missing. I can update the PR if we agree it's a better move. |
|
By the way, I have been running a monkey patch for this in production for about a year now and it didn't break anything in our codebase. |
|
Any updates here? |



That will fix an issue when calling
flattento an array ofChargeBee::Model: