blueprint_config 1.0.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/blueprint_config/backend/active_record.rb +21 -3
- data/lib/blueprint_config/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6cd1d77adc1c5b0c6804976f701d7169aa95dde0fbb759223bf5f866d3dcb6ce
|
4
|
+
data.tar.gz: a2afa1abc74f9353444ee4a03c8afd256ba56521f5d914376f145367caa9b70b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dcc11edd92aed918514ec06d6da8b8fe98033ceed743d8bb710d8263bcb93460ee089d6299c31a969d93cfe7997aab707b5d5749a6af99e4383a0870a2d64201
|
7
|
+
data.tar.gz: 3363d88bfbc0da672f308f4d528b256399a4ac0c5364e2a4c25f298e84bf951f41feab992c071d5f74f978df7695cd9fcb3c49998c83ceae705c9f7ed3e2f9f3
|
@@ -11,7 +11,7 @@ module BlueprintConfig
|
|
11
11
|
=======================================================================
|
12
12
|
Settings table not found. Please add the configuration table by running:
|
13
13
|
|
14
|
-
rails generate
|
14
|
+
rails generate blueprint_config:install
|
15
15
|
rake db:migrate
|
16
16
|
=======================================================================
|
17
17
|
WARNING
|
@@ -20,16 +20,27 @@ module BlueprintConfig
|
|
20
20
|
@options = options
|
21
21
|
@updated_at = nil
|
22
22
|
@last_checked_at = nil
|
23
|
-
@
|
23
|
+
@configured = true
|
24
|
+
@mutex = Thread::Mutex.new
|
24
25
|
end
|
25
26
|
|
26
27
|
def load_keys
|
28
|
+
@configured = true
|
27
29
|
update_timestamp
|
28
30
|
|
29
31
|
data = Setting.all.map { |s| { s.key => s.parsed_value } }.reduce(:merge) || {}
|
30
32
|
return data.transform_keys(&:to_sym) unless @options[:nest]
|
31
33
|
|
32
34
|
nest_hash(data, @options[:nest_separator] || '.')
|
35
|
+
rescue ::ActiveRecord::NoDatabaseError => e
|
36
|
+
# database is not created yet
|
37
|
+
@configured = false
|
38
|
+
{}
|
39
|
+
rescue ::ActiveRecord::StatementInvalid => e
|
40
|
+
@configured = false
|
41
|
+
Rails.logger.warn(e.message)
|
42
|
+
Rails.logger.warn(MISSING_TABLE_WARNING)
|
43
|
+
{}
|
33
44
|
end
|
34
45
|
|
35
46
|
def update_timestamp
|
@@ -39,12 +50,19 @@ module BlueprintConfig
|
|
39
50
|
end
|
40
51
|
|
41
52
|
def fresh?
|
53
|
+
# if database is not create/configured yet - don't try to refresh settings from it
|
54
|
+
return true unless @configured
|
42
55
|
return true if @last_checked_at.present? && @last_checked_at > 1.second.ago
|
43
56
|
|
44
57
|
@mutex.synchronize do
|
45
58
|
@last_checked_at = Time.now
|
46
59
|
end
|
47
|
-
|
60
|
+
max_updated_at = Setting.maximum(:updated_at)
|
61
|
+
|
62
|
+
# if there is no settings in the database - don't try to refresh settings from it'
|
63
|
+
return true if max_updated_at.blank?
|
64
|
+
|
65
|
+
@updated_at.present? && @updated_at >= max_updated_at
|
48
66
|
end
|
49
67
|
end
|
50
68
|
end
|