Skip to content

Instantly share code, notes, and snippets.

@kevinnio
Last active October 24, 2018 01:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevinnio/ec0e0b9ea4ad26988f63f27dbaf878a4 to your computer and use it in GitHub Desktop.
Save kevinnio/ec0e0b9ea4ad26988f63f27dbaf878a4 to your computer and use it in GitHub Desktop.
Spree/Solidus Module Decorator pattern
require 'active_support/concern'
module MyNamespace::SpreeDecorator
extend ActiveSupport::Concern
included do
# Call base class methods here!
some_class_method :foo
some_class_method_with_block do
another_class_method :bar
end
end
def overridden_method
# Overrides method
end
def overridden_method_calling_original_one
super # this is available using this decorator approach
# New code
end
def totally_new_method
# Just a plain old method
end
end
Spree::ClassToBeDecorated.include MyNamespace::SpreeDecorator
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment