site_config.rb
955 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
class SiteConfig
CONFIG_SOURCE_SITE = 'site'.freeze
CONFIG_SOURCE_APP = 'app'.freeze
include Mongoid::Document
include Mongoid::Timestamps
after_save :denormalize
embeds_one :notice_fingerprinter, autobuild: true
validates_associated :notice_fingerprinter
accepts_nested_attributes_for :notice_fingerprinter
# Get the one and only SiteConfig document
def self.document
first || create
end
# Denormalize SiteConfig onto individual apps so that this record doesn't
# need to be accessed when inserting new error notices
def denormalize
App.each do |app|
f = app.notice_fingerprinter
next if f.source && f.source != CONFIG_SOURCE_SITE
app.update_attributes(
notice_fingerprinter: notice_fingerprinter_attributes)
end
end
def notice_fingerprinter_attributes
notice_fingerprinter.attributes.tap do |attrs|
attrs.delete('_id')
attrs[:source] = :site
end
end
end