system_settings 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/app/models/system_settings/configurator.rb +8 -7
- data/app/models/system_settings/errors/error.rb +6 -0
- data/app/models/system_settings/errors/not_found_error.rb +6 -0
- data/app/models/system_settings/errors/settings_read_error.rb +1 -1
- data/app/models/system_settings/type/integer_list.rb +10 -6
- data/lib/system_settings.rb +4 -9
- data/lib/system_settings/version.rb +1 -1
- metadata +7 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 47a6c44afe9d52cf548c130a71dc763879c5aa47
|
4
|
+
data.tar.gz: fbeb661a76b0efbbaaf477cc739919175efc0241
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2d18357fdecc7756e53716380910ac2fd8731b6999453c7c458f176fc8a94dc4cfdb43404004c688d64b4d544ee6b099191d01e97060727fa27b13218442ca28
|
7
|
+
data.tar.gz: 26f09571be71f63f1526c6e2dd9cd8c31615ecba1222319ab7d9e9eab0bc8b95d3b05560de85974deede6bdd3c07909bf618c02cff30c9279dc5f82e0a70ed5b
|
@@ -1,13 +1,14 @@
|
|
1
1
|
module SystemSettings
|
2
2
|
class Configurator
|
3
3
|
class << self
|
4
|
-
def from_file(
|
5
|
-
|
6
|
-
raise
|
7
|
-
raise
|
8
|
-
|
4
|
+
def from_file(file_name)
|
5
|
+
file_name = file_name.to_path if file_name.respond_to?(:to_path)
|
6
|
+
raise Errors::SettingsReadError, "The file name must either be a String or implement #to_path" unless file_name.is_a?(String)
|
7
|
+
raise Errors::SettingsReadError, "#{file_name} file does not exist" unless File.exist?(file_name)
|
8
|
+
raise Errors::SettingsReadError, "#{file_name} file not readable" unless File.readable?(file_name)
|
9
|
+
file_content = File.read(file_name)
|
9
10
|
new.tap do |obj|
|
10
|
-
obj.instance_eval(file_content,
|
11
|
+
obj.instance_eval(file_content, file_name, 1)
|
11
12
|
end
|
12
13
|
end
|
13
14
|
|
@@ -54,7 +55,7 @@ module SystemSettings
|
|
54
55
|
@items.each do |entry|
|
55
56
|
persisted_record = entry[:class].find_by(name: entry[:name])
|
56
57
|
if persisted_record
|
57
|
-
persisted_record.
|
58
|
+
persisted_record.update!(description: entry[:description])
|
58
59
|
else
|
59
60
|
entry[:class].create!(name: entry[:name], value: entry[:value], description: entry[:description])
|
60
61
|
end
|
@@ -21,15 +21,19 @@ module SystemSettings
|
|
21
21
|
case value
|
22
22
|
when Array
|
23
23
|
value.map do |v|
|
24
|
-
|
25
|
-
|
26
|
-
|
24
|
+
begin
|
25
|
+
v.to_i
|
26
|
+
rescue StandardError
|
27
|
+
nil
|
28
|
+
end
|
27
29
|
end
|
28
30
|
when String
|
29
31
|
value.split(SEPARATOR).map do |v|
|
30
|
-
|
31
|
-
|
32
|
-
|
32
|
+
begin
|
33
|
+
v.to_i
|
34
|
+
rescue StandardError
|
35
|
+
nil
|
36
|
+
end
|
33
37
|
end
|
34
38
|
end
|
35
39
|
end
|
data/lib/system_settings.rb
CHANGED
@@ -1,18 +1,13 @@
|
|
1
1
|
require "system_settings/engine"
|
2
2
|
|
3
3
|
module SystemSettings
|
4
|
-
|
5
|
-
|
6
|
-
def self.settings_file_path
|
7
|
-
@@settings_file_path
|
8
|
-
end
|
9
|
-
|
10
|
-
def self.settings_file_path=(value)
|
11
|
-
@@settings_file_path = value
|
4
|
+
class << self
|
5
|
+
attr_accessor :settings_file_path
|
12
6
|
end
|
13
7
|
|
14
8
|
def self.[](name)
|
15
|
-
Setting.find_by
|
9
|
+
record = Setting.find_by(name: name) || raise(Errors::NotFoundError, "Couldn't find system setting #{name}")
|
10
|
+
record.value
|
16
11
|
end
|
17
12
|
|
18
13
|
def self.load
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: system_settings
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Krists Ozols
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-05-
|
11
|
+
date: 2019-05-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -41,6 +41,8 @@ files:
|
|
41
41
|
- app/models/system_settings/application_record.rb
|
42
42
|
- app/models/system_settings/boolean_setting.rb
|
43
43
|
- app/models/system_settings/configurator.rb
|
44
|
+
- app/models/system_settings/errors/error.rb
|
45
|
+
- app/models/system_settings/errors/not_found_error.rb
|
44
46
|
- app/models/system_settings/errors/settings_read_error.rb
|
45
47
|
- app/models/system_settings/integer_list_setting.rb
|
46
48
|
- app/models/system_settings/integer_setting.rb
|
@@ -79,14 +81,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
79
81
|
requirements:
|
80
82
|
- - ">="
|
81
83
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
84
|
+
version: 2.4.0
|
83
85
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
86
|
requirements:
|
85
87
|
- - ">="
|
86
88
|
- !ruby/object:Gem::Version
|
87
89
|
version: '0'
|
88
90
|
requirements: []
|
89
|
-
|
91
|
+
rubyforge_project:
|
92
|
+
rubygems_version: 2.6.14.4
|
90
93
|
signing_key:
|
91
94
|
specification_version: 4
|
92
95
|
summary: Settings for your Rails application
|