mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-26 01:33:22 +00:00
Add simple variant proxy
This commit is contained in:
19
lib/open_food_network/variant_proxy.rb
Normal file
19
lib/open_food_network/variant_proxy.rb
Normal file
@@ -0,0 +1,19 @@
|
||||
module OpenFoodNetwork
|
||||
class VariantProxy
|
||||
instance_methods.each { |m| undef_method m unless m =~ /(^__|^send$|^object_id$)/ }
|
||||
|
||||
def initialize(variant, hub)
|
||||
@variant = variant
|
||||
@hub = hub
|
||||
end
|
||||
|
||||
def price
|
||||
VariantOverride.price_for(@variant, @hub) || @variant.price
|
||||
end
|
||||
|
||||
|
||||
def method_missing(name, *args, &block)
|
||||
@variant.send(name, *args, &block)
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user