Class: Spree::Preferences::PreferenceDifferentiator
- Inherits:
-
Object
- Object
- Spree::Preferences::PreferenceDifferentiator
- Defined in:
- lib/spree/preferences/preference_differentiator.rb
Instance Attribute Summary collapse
-
#config_class ⇒ Object
readonly
Returns the value of attribute config_class.
Instance Method Summary collapse
- #call(from:, to:) ⇒ Object
-
#initialize(config_class) ⇒ PreferenceDifferentiator
constructor
A new instance of PreferenceDifferentiator.
Constructor Details
#initialize(config_class) ⇒ PreferenceDifferentiator
Returns a new instance of PreferenceDifferentiator.
8 9 10 |
# File 'lib/spree/preferences/preference_differentiator.rb', line 8 def initialize(config_class) @config_class = config_class end |
Instance Attribute Details
#config_class ⇒ Object (readonly)
Returns the value of attribute config_class.
6 7 8 |
# File 'lib/spree/preferences/preference_differentiator.rb', line 6 def config_class @config_class end |
Instance Method Details
#call(from:, to:) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/spree/preferences/preference_differentiator.rb', line 12 def call(from:, to:) preferences_from = config_class.new.load_defaults(from) preferences_to = config_class.new.load_defaults(to) config_class.versioned_preferences.reduce({}) do |changes, pref_key| value_from = preferences_from[pref_key] value_to = preferences_to[pref_key] if value_from == value_to changes else changes.merge( pref_key => { from: value_from, to: value_to } ) end end end |