DurableDecorator



5,013 downloads



https://github.com/jumph4x/durable_decorator

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"

DurableDecorator::Base.determine_sha('Clazz#method')

# => 'ba3114b2d46caa684b3f7ba38d6f74b2'


Clazz.class_eval do
  durably_decorate :method, mode: 'strict', sha: 'WRONG-SHA-123456' do
    original_string_method + " and new"
  end
end


DurableDecorator::TamperedDefinitionError: Method SHA mismatch, the definition has been tampered with



DurableDecoratorRails




2,373 downloads



https://github.com/jumph4x/durable_decorator_rails

Does all the work for you

rails g decorator Spree::Product#deleted?

      create  app/models/spree/product_decorator.rb
      insert  app/models/spree/product_decorator.rb

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

Problems:

def rescue syntax &

default variable values

Made with Slides.com