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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: be61b7fe3cee8680edfeddde8bbd290aa4463fd68ea2b2582651f740afe4685b
4
- data.tar.gz: 9e6f745b5acc18080066a2ffb482eee0d69f704010ef923b8cab0f960c10ba48
3
+ metadata.gz: 6cd1d77adc1c5b0c6804976f701d7169aa95dde0fbb759223bf5f866d3dcb6ce
4
+ data.tar.gz: a2afa1abc74f9353444ee4a03c8afd256ba56521f5d914376f145367caa9b70b
5
5
  SHA512:
6
- metadata.gz: e2849e6eb9237668d42fa9d7c10fe3075798e2cbc296a4a21d76429dcd921252d012a0c96672b69debc18f919d650dc8a2f1897f3401b664c6b6b688326c6719
7
- data.tar.gz: c76bd8289d7075f53358f9d7035b9d8e3479c4dc081c40c2c826e1cb3f561803bbe2380f66b741b6dea13636b2337c7cef4587dd29d241cb59a04790f236c97e
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 blue_config:migration
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
- @mutex = Mutex.new
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
- @updated_at.present? && @updated_at >= Setting.maximum(:updated_at)
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BlueprintConfig
4
- VERSION = '1.0.0'
4
+ VERSION = '1.2.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blueprint_config
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vladimir Elchinov