Module: Prefered::PreferenceEngine

Included in:
Preference, PreferenceGroup
Defined in:
lib/prefered/preference.rb

Instance Method Summary collapse

Instance Method Details

#deserialize_preferences(settings, raw_data) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/prefered/preference.rb', line 45

def deserialize_preferences(settings, raw_data)
  settings.preferences.keys.each do |preference|
    if raw_data.include?(preference)
      send(:"#{preference}=", raw_data[preference])
    end
  end
  settings.groups.keys.each do |group|
    if raw_data.include?(group)
      send(:"#{group}").deserialize_preferences(settings.groups[group], raw_data[group])
    end
  end
end

#serialize_preferences(settings) ⇒ Object



35
36
37
38
39
40
41
42
43
# File 'lib/prefered/preference.rb', line 35

def serialize_preferences(settings)
  preferences_data = settings.preferences.keys.to_h do |preference|
    send(:"#{preference}")
  end
  groups_data = settings.groups.keys.to_h do |group|
    send(:"#{group}").serialize_preferences(settings.groups[group])
  end
  preferences_data.merge(groups_data)
end