mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Bring Environment Calculators and Environment Extension from spree_core
This commit is contained in:
12
lib/spree/core/environment/calculators.rb
Normal file
12
lib/spree/core/environment/calculators.rb
Normal file
@@ -0,0 +1,12 @@
|
||||
module Spree
|
||||
module Core
|
||||
class Environment
|
||||
class Calculators
|
||||
include EnvironmentExtension
|
||||
|
||||
attr_accessor :shipping_methods, :tax_rates
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
25
lib/spree/core/environment_extension.rb
Normal file
25
lib/spree/core/environment_extension.rb
Normal file
@@ -0,0 +1,25 @@
|
||||
module Spree
|
||||
module Core
|
||||
module EnvironmentExtension
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
def add_class(name)
|
||||
self.instance_variable_set "@#{name}", Set.new
|
||||
|
||||
create_method( "#{name}=".to_sym ) { |val|
|
||||
instance_variable_set( "@" + name, val)
|
||||
}
|
||||
|
||||
create_method(name.to_sym) do
|
||||
instance_variable_get( "@" + name )
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def create_method(name, &block)
|
||||
self.class.send(:define_method, name, &block)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user