rb-konfig 0.1.1 → 0.1.6

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: 1d4f1c0da5f57c267a60744219db12cf6367dbbab95f3565b80fae2b0b4b44bb
4
- data.tar.gz: 7edcd4ef1a08f53bce1fa4df0472ad1f52edb01734af8f0ccbc7d1bac5befbfb
3
+ metadata.gz: d856585bd2b6c9b421964eb757e4dbc60b8a1e4a033e817c91353da2b9c0cc7a
4
+ data.tar.gz: c924badaff2dc5a2140c9559b4ea97c573590404593c050be3ca32ed7d66a15c
5
5
  SHA512:
6
- metadata.gz: 7684f9dc14ff341145b701277d8e0a06fc9d11a027b1ab7d9fb707f09654510e6065bd04b25c3da12f6de51ad707b7bbae1357a659779d30d693e64d8943e53d
7
- data.tar.gz: 24e20e5a45290d8351cf4da66b1a51fc8082b630826155db9f594907f08b457b4602e081277a4bed42937425f6074ab18ef382be9e9c23d357636ca5511200d2
6
+ metadata.gz: d180c690f4d3747ce7da2aa8e459c0d8df4a3241ec3853c439bc70c0a69b8a6ddb15f65f137fc4724e1b993df25d36eb2ddc4dd653f957f8a465a2bbf0dc82d0
7
+ data.tar.gz: e3702b812b5eaa692db87f3eb737c4b77981410c448bc304828fc085249c8134db2aa0b1df6f90f19e73e00565efea3a7eec231fe2c2299cf5cb36f44ecbd869
data/.gitignore CHANGED
@@ -50,3 +50,4 @@ build-iPhoneSimulator/
50
50
  .rvmrc
51
51
  /.byebug_history
52
52
  /.idea
53
+ /.DS_Store
data/.ruby-version CHANGED
@@ -1,2 +1,2 @@
1
- ruby-2.5.5
1
+ 3.0.0
2
2
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rb-konfig (0.1.1)
4
+ rb-konfig (0.1.5)
5
5
  activesupport (>= 4)
6
6
  dry-schema (~> 1.3)
7
7
  thor (~> 0.20)
data/README.md CHANGED
@@ -84,6 +84,7 @@ You can change or reach the following from `Konfig.configuration`
84
84
  * `mode`: No default value
85
85
  * `workdir`: No default value
86
86
  * `schema`: Configuration validation schema. If available, the loaded, merged and parsed configuration is validated against this schema. See [Dry-Schema](https://dry-rb.org/gems/dry-schema/) for more information.
87
+ * `fail_on_validation`: Fail if schema validation fails
87
88
 
88
89
  ### Data types
89
90
 
@@ -92,7 +93,6 @@ The directory mode, supports the following data types in files and tries to retu
92
93
  - Integer
93
94
  - Float
94
95
  - String
95
- - Date time
96
96
  - Boolean
97
97
  - JSON
98
98
  - Null (see above)
data/konfig.gemspec CHANGED
@@ -26,7 +26,7 @@ Gem::Specification.new do |spec|
26
26
 
27
27
  spec.add_dependency "activesupport", ">= 4"
28
28
  spec.add_dependency "dry-schema", "~> 1.3"
29
- spec.add_dependency "thor", "~> 0.20"
29
+ spec.add_dependency "thor", "~> 1.0"
30
30
 
31
31
  spec.add_development_dependency "bundler", "~> 2.0"
32
32
  spec.add_development_dependency "rake", "~> 10.0"
data/lib/konfig.rb CHANGED
@@ -22,6 +22,7 @@ module Konfig
22
22
  attr_writer :workdir
23
23
  attr_writer :env_prefix
24
24
  attr_writer :logger
25
+ attr_writer :fail_on_validation
25
26
 
26
27
  def namespace
27
28
  @namespace || "Settings"
@@ -44,12 +45,13 @@ module Konfig
44
45
  end
45
46
 
46
47
  def logger
47
- @logger if @logger
48
+ return @logger if @logger
48
49
  if defined?(Rails) && Rails.logger
49
- Rails.logger
50
+ @logger = Rails.logger
50
51
  else
51
- Logger.new(STDOUT)
52
+ @logger = Logger.new(STDOUT)
52
53
  end
54
+ @logger
53
55
  end
54
56
 
55
57
  def schema=(value)
@@ -82,6 +84,10 @@ module Konfig
82
84
 
83
85
  def nil_word
84
86
  @nil_word || "null"
85
- end
87
+ end
88
+
89
+ def fail_on_validation
90
+ @fail_on_validation.nil? ? true : @fail_on_validation
91
+ end
86
92
  end
87
93
  end
@@ -1,5 +1,4 @@
1
1
  require_relative "config_provider"
2
- require "date"
3
2
  require "json"
4
3
 
5
4
  module Konfig
data/lib/konfig/option.rb CHANGED
@@ -32,7 +32,11 @@ module Konfig
32
32
 
33
33
  unless v_res.success?
34
34
  error = Konfig::ValidationError.format(v_res)
35
- raise Konfig::ValidationError.new("Config validation failed:\n\n#{error}")
35
+ if Konfig.configuration.fail_on_validation
36
+ raise Konfig::ValidationError.new("Config validation failed:\n\n#{error}")
37
+ else
38
+ Konfig.configuration.logger.error "Config validation failed:\n\n#{error}"
39
+ end
36
40
  end
37
41
  end
38
42
  end
@@ -90,8 +94,7 @@ module Konfig
90
94
  s = self.class.new
91
95
 
92
96
  h.each do |k, v|
93
- k = k.to_s if !k.respond_to?(:to_sym) && k.respond_to?(:to_s)
94
- s.new_ostruct_member(k)
97
+ k = k.to_s if !k.respond_to?(:to_sym) && k.respond_to?(:to_s)
95
98
 
96
99
  if v.is_a?(Hash)
97
100
  v = v["type"] == "hash" ? v["contents"] : __convert(v)
@@ -99,7 +102,7 @@ module Konfig
99
102
  v = v.collect { |e| e.instance_of?(Hash) ? __convert(e) : e }
100
103
  end
101
104
 
102
- s.send("#{k}=".to_sym, v)
105
+ s[k] = v
103
106
  end
104
107
  s
105
108
  end
data/lib/konfig/utils.rb CHANGED
@@ -10,9 +10,12 @@ module Konfig
10
10
  lambda { |value| Integer(value) rescue NIL_VALUE }, # integer
11
11
  lambda { |value| Float(value) rescue NIL_VALUE }, # float
12
12
  lambda { |value| (["true", "false"].include?(value)) ? (value == "true") : NIL_VALUE }, # boolean
13
- lambda { |value| DateTime.parse(value) rescue NIL_VALUE }, # date time
14
13
  lambda { |value| (value == Konfig.configuration.nil_word && Konfig.configuration.allow_nil) ? nil : NIL_VALUE }, # nil value
15
14
  lambda do |value|
15
+ value = value.strip
16
+ # on some platforms, JSON.parse returns value for integer and floats. This is incorrect https://www.json.org/
17
+ return NIL_VALUE if !value.start_with?("[") && !value.start_with?("{")
18
+
16
19
  result = JSON.parse(value, { symbolize_names: true })
17
20
  if result == nil && !Konfig.configuration.allow_nil
18
21
  return NIL_VALUE
@@ -22,7 +25,10 @@ module Konfig
22
25
  rescue
23
26
  NIL_VALUE
24
27
  end, # json
25
- lambda { |value| value }, # string. should always be the last one
28
+ lambda do |value| # string. should always be the last one
29
+ # in case we have a string, clean it up. For example, quotes in strings should be escaped or will be removed
30
+ Konfig::Utils.remove_quotations(value)
31
+ end,
26
32
  ]
27
33
 
28
34
  class Utils
@@ -36,5 +42,11 @@ module Konfig
36
42
 
37
43
  raise UnsupportedValueType, "'#{value}' is unsupported type"
38
44
  end
45
+
46
+ def self.remove_quotations(str)
47
+ str = str.slice(1..-1) if str.start_with?('"') || str.start_with?('\'')
48
+ str = str.slice(0..-2) if str.end_with?('"') || str.end_with?('\'')
49
+ return str
50
+ end
39
51
  end
40
52
  end
@@ -1,3 +1,3 @@
1
1
  module Konfig
2
- VERSION ||= "0.1.1"
2
+ VERSION ||= "0.1.6"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rb-konfig
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Khash Sajadi
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-08-21 00:00:00.000000000 Z
11
+ date: 2021-03-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0.20'
47
+ version: '1.0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '0.20'
54
+ version: '1.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: bundler
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -164,7 +164,7 @@ dependencies:
164
164
  - - "~>"
165
165
  - !ruby/object:Gem::Version
166
166
  version: '11.0'
167
- description:
167
+ description:
168
168
  email:
169
169
  - hello@cloud66.com
170
170
  executables:
@@ -204,7 +204,7 @@ licenses: []
204
204
  metadata:
205
205
  homepage_uri: https://github.com/cloud66-oss/konfig/
206
206
  source_code_uri: https://github.com/cloud66-oss/konfig/
207
- post_install_message:
207
+ post_install_message:
208
208
  rdoc_options: []
209
209
  require_paths:
210
210
  - lib
@@ -219,9 +219,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
219
219
  - !ruby/object:Gem::Version
220
220
  version: '0'
221
221
  requirements: []
222
- rubyforge_project:
223
- rubygems_version: 2.7.6.2
224
- signing_key:
222
+ rubygems_version: 3.2.3
223
+ signing_key:
225
224
  specification_version: 4
226
225
  summary: Konfig is a Kubernetes friendly Rails configuration gem
227
226
  test_files: []