Class: UserPreferences::API

Inherits:
Object
  • Object
show all
Defined in:
lib/user_preferences/api.rb

Instance Method Summary collapse

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

#allObject



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

#reloadObject



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