Refactor preference access to use define_method instead of method_missing

Replaces dynamic method handling with explicit getters and setters to
avoid recursion issues and improve clarity.
This commit is contained in:
Carlos Chitty
2025-06-10 12:37:23 -04:00
parent f909bb2c30
commit 37bf3f495f

View File

@@ -27,6 +27,20 @@ module Spree
class Configuration
include Spree::Preferences::Preferable
class << self
def preference(name, type, *args)
super
define_method(name) do
get_preference(name)
end
define_method("#{name}=") do |value|
set_preference(name, value)
end
end
end
def configure
yield(self) if block_given?
end
@@ -56,24 +70,6 @@ module Spree
set_preference args[0], args[1]
end
def respond_to_missing?(method_name, include_private = false)
name = method_name.to_s.chomp('=')
has_preference?(name) || super
end
def method_missing(method, *args)
name = method.to_s.gsub('=', '')
if has_preference? name
if method.to_s =~ /=$/
set_preference(name, args.first)
else
get_preference name
end
else
super
end
end
end
end
end