Created
November 6, 2013 20:04
-
-
Save laspluviosillas/7343184 to your computer and use it in GitHub Desktop.
Example subscription decorator structure.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ChargifySubscription < SimpleDelegator | |
def addons_count | |
# Implementacion aqui | |
end | |
def price | |
# Implementacion aqui | |
end | |
end | |
class BraintreeSubscription < SimpleDelegator | |
def addons_count | |
# Implementacion aqui | |
end | |
def price | |
# Implementacion aqui | |
end | |
end | |
class Subscription | |
attr_accessible :api | |
def addons_count | |
decorate.addons_count | |
end | |
def price | |
decorate.price | |
end | |
def decorate | |
if api == "braintree" | |
BraintreeSubscription.new(self) | |
elsif api == "chargify" | |
ChargifySubscription.new(self) | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment