Module: User::Preferences

Included in:
User
Defined in:
app/models/user/preferences.rb

Constant Summary collapse

BASE_PREFERENCES =
YAML.load_file(Rails.root + 'config/preferences/user.yml')

Instance Method Summary collapse

Instance Method Details

#fill_preferencesObject



23
24
25
26
27
28
29
30
31
32
# File 'app/models/user/preferences.rb', line 23

def fill_preferences
  if preferences.empty?
    reset_preferences
  else
    BASE_PREFERENCES.keys.each do |k|
      preferences[k] = BASE_PREFERENCES[k] if send(k).nil?
    end
  end
  true
end

#layout=(values) ⇒ Object



48
49
50
51
# File 'app/models/user/preferences.rb', line 48

def layout=(values)
  l = layout.nil? ? {} : layout
  super(l.merge(values))
end

#reset_hub_favorites(project_id = nil) ⇒ Object



38
39
40
41
42
43
44
45
46
# File 'app/models/user/preferences.rb', line 38

def reset_hub_favorites(project_id = nil)
  if project_id.nil?
    write_attribute(:hub_favorites, {})
  else
    h = read_attribute(:hub_favorites)
    h[project_id] = User::HUB_FAVORITES
    write_attribute(:hub_favorites, h)
  end
end

#reset_preferencesObject



34
35
36
# File 'app/models/user/preferences.rb', line 34

def reset_preferences
  write_attribute(:preferences, BASE_PREFERENCES)
end