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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: 5f17765421feae9372577a362a6529227d3286f667c59733dd326dacc3fc65f6
4
- data.tar.gz: bfcd048964c1b8fdf99b91e6c88abae1cf89e3c7bc9e888c55c7827b4556b008
2
+ SHA1:
3
+ metadata.gz: 47a6c44afe9d52cf548c130a71dc763879c5aa47
4
+ data.tar.gz: fbeb661a76b0efbbaaf477cc739919175efc0241
5
5
  SHA512:
6
- metadata.gz: 8c6f652967fa2c4b7db860c7b4b0a596ce85822f8ecef8ca3b2a77fd20856b33757a54dfb13f98fcab5f5546f013722b1b871426c38fecca3ffeb6d6da0be355
7
- data.tar.gz: 3206825f36333adbbfcde4c1af5424423f0c2824b9c4c25a8fe506ef68018b5aa299c67392b2e97914808713a133211ef6ed04c22e9d65fbd6eabe7e4bb16931
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(path)
5
- path_str = path.to_s
6
- raise SystemSettings::Errors::SettingsReadError, "#{path_str} file does not exist" unless File.exist?(path_str)
7
- raise SystemSettings::Errors::SettingsReadError, "#{path_str} file not readable" unless File.readable?(path_str)
8
- file_content = File.read(path_str)
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, path_str, 1)
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.update_attributes!(description: entry[:description])
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
@@ -0,0 +1,6 @@
1
+ module SystemSettings
2
+ module Errors
3
+ class Error < StandardError
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ module SystemSettings
2
+ module Errors
3
+ class NotFoundError < Error
4
+ end
5
+ end
6
+ end
@@ -1,6 +1,6 @@
1
1
  module SystemSettings
2
2
  module Errors
3
- class SettingsReadError < StandardError
3
+ class SettingsReadError < Error
4
4
  end
5
5
  end
6
6
  end
@@ -21,15 +21,19 @@ module SystemSettings
21
21
  case value
22
22
  when Array
23
23
  value.map do |v|
24
- v.to_i
25
- rescue StandardError
26
- nil
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
- v.to_i
31
- rescue StandardError
32
- nil
32
+ begin
33
+ v.to_i
34
+ rescue StandardError
35
+ nil
36
+ end
33
37
  end
34
38
  end
35
39
  end
@@ -1,18 +1,13 @@
1
1
  require "system_settings/engine"
2
2
 
3
3
  module SystemSettings
4
- @@settings_file_path = nil
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!(name: name).value
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
@@ -1,3 +1,3 @@
1
1
  module SystemSettings
2
- VERSION = "0.3.0".freeze
2
+ VERSION = "0.4.0".freeze
3
3
  end
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.3.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-25 00:00:00.000000000 Z
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: '0'
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
- rubygems_version: 3.0.3
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