Borrows concepts, inspiration and motivation from Brian's Deface
Goal: pay the price for Spree's (Ruby's) flexibility by helping us avoid prolific monkey-patching
Why?
No, but really, why?
Xzibit, tell 'em
Whatever specs your extension had, if someone class_evals codeat runtime, they're damn near worthless to you
Their code Your code
How?
With the power of Hash!
Let something else do the class_evaling
History of overrides,
validation, exception handling
class ExampleClass def string_method "original" end end
ExampleClass.class_eval do durably_decorate :string_method do original_string_method + " and new" end end instance = ExampleClass.new instance.string_method # => "original and new"
Spree::Product.class_eval do durably_decorate :deleted?, mode: 'strict', sha: '9dc99742ed3ebbdd5b2cbd7c3c93d730e5244e72' do # call the old method with: # _9dc9_deleted?
# Alternatively, uncomment and override the method body below: # !!deleted_at end end