Last active
July 5, 2016 18:55
-
-
Save etagwerker/8760a38692461caca67f9cd27c89ce75 to your computer and use it in GitHub Desktop.
null_object.rb
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 Seller | |
belongs_to :user | |
def can_add_products? | |
products.count < seller.products_limit | |
end | |
def seller | |
if is_sysadmin? | |
NullSeller.new | |
else | |
super | |
end | |
end | |
end | |
class User | |
has_one :seller | |
end | |
# Usage | |
if user.seller.can_add_products? | |
puts "Can add products" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment