Class: UserPreferences::API
- Inherits:
-
Object
- Object
- UserPreferences::API
- Defined in:
- lib/user_preferences/api.rb
Instance Method Summary collapse
- #all ⇒ Object
- #get(name) ⇒ Object
-
#initialize(category, scope) ⇒ API
constructor
A new instance of API.
- #reload ⇒ Object
- #set(hash) ⇒ Object
Constructor Details
#initialize(category, scope) ⇒ API
Returns a new instance of API.
3 4 5 6 |
# File 'lib/user_preferences/api.rb', line 3 def initialize(category, scope) @category = category @scope = scope.where(category: category) end |
Instance Method Details
#all ⇒ Object
8 9 10 |
# File 'lib/user_preferences/api.rb', line 8 def all serialized_preferences end |
#get(name) ⇒ Object
12 13 14 |
# File 'lib/user_preferences/api.rb', line 12 def get(name) serialized_preferences[name] end |
#reload ⇒ Object
25 26 27 28 |
# File 'lib/user_preferences/api.rb', line 25 def reload @_saved_preferences = nil all end |
#set(hash) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/user_preferences/api.rb', line 16 def set(hash) hash_setter do hash.each do |name, value| find_or_init_preference(name).update_value!(value) end reload end end |