king_konf 0.1.10 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.circleci/config.yml +47 -0
- data/README.md +3 -0
- data/king_konf.gemspec +1 -0
- data/lib/king_konf/config.rb +9 -4
- data/lib/king_konf/variable.rb +7 -2
- data/lib/king_konf/version.rb +1 -1
- metadata +18 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b05b410d3b35c4b341e2f10ec7ca684936c692f21a67452197b5e231c25c87f3
|
4
|
+
data.tar.gz: fc5368013c4f4b73d461c3dfabf43be74f37153208f5e0caa1d152765fb37e61
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '00248cac6619fde14c3a1cd29f2905aec16bf893cd99cf6b588ecfff14bef42b300296e8cb3d70914ae8df2c3729cfc0294d91e79682b188ea53f7f8c26e7ee2'
|
7
|
+
data.tar.gz: 38875fec1190771e9e120ad504a9f475bb11a08f437c94e3188a097870cb5e1706bd0df5bbc77c55e7050a3a8fd6e3db1fee0ad9c626f2a236370a94edf7a621
|
@@ -0,0 +1,47 @@
|
|
1
|
+
version: 2
|
2
|
+
jobs:
|
3
|
+
build:
|
4
|
+
docker:
|
5
|
+
- image: circleci/ruby:2.4.1-node-browsers
|
6
|
+
|
7
|
+
working_directory: ~/repo
|
8
|
+
|
9
|
+
steps:
|
10
|
+
- checkout
|
11
|
+
|
12
|
+
# Download and cache dependencies
|
13
|
+
- restore_cache:
|
14
|
+
keys:
|
15
|
+
- v1-dependencies-{{ checksum "king_konf.gemspec" }}
|
16
|
+
# fallback to using the latest cache if no exact match is found
|
17
|
+
- v1-dependencies-
|
18
|
+
|
19
|
+
- run:
|
20
|
+
name: install dependencies
|
21
|
+
command: |
|
22
|
+
bundle install --jobs=4 --retry=3 --path vendor/bundle
|
23
|
+
|
24
|
+
- save_cache:
|
25
|
+
paths:
|
26
|
+
- ./vendor/bundle
|
27
|
+
key: v1-dependencies-{{ checksum "king_konf.gemspec" }}
|
28
|
+
|
29
|
+
# run tests!
|
30
|
+
- run:
|
31
|
+
name: run tests
|
32
|
+
command: |
|
33
|
+
mkdir /tmp/test-results
|
34
|
+
TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)"
|
35
|
+
|
36
|
+
bundle exec rspec --format progress \
|
37
|
+
--format RspecJunitFormatter \
|
38
|
+
--out /tmp/test-results/rspec.xml \
|
39
|
+
--format progress \
|
40
|
+
$TEST_FILES
|
41
|
+
|
42
|
+
# collect reports
|
43
|
+
- store_test_results:
|
44
|
+
path: /tmp/test-results
|
45
|
+
- store_artifacts:
|
46
|
+
path: /tmp/test-results
|
47
|
+
destination: test-results
|
data/README.md
CHANGED
@@ -52,6 +52,9 @@ class MyApplication::Config < KingKonf::Config
|
|
52
52
|
|
53
53
|
# You can also provide a default value to any variable:
|
54
54
|
string :body, default: "N/A"
|
55
|
+
|
56
|
+
# You can restrict the set of allowed values:
|
57
|
+
string :category, allowed_values: ["news", "stuff", "accouncements"]
|
55
58
|
end
|
56
59
|
```
|
57
60
|
|
data/king_konf.gemspec
CHANGED
data/lib/king_konf/config.rb
CHANGED
@@ -33,7 +33,7 @@ module KingKonf
|
|
33
33
|
end
|
34
34
|
|
35
35
|
%i(boolean integer float string list).each do |type|
|
36
|
-
define_method(type) do |name, default: nil, required: false, **options|
|
36
|
+
define_method(type) do |name, default: nil, required: false, allowed_values: nil, **options|
|
37
37
|
description, @desc = @desc, nil
|
38
38
|
variable = Variable.new(
|
39
39
|
name: name,
|
@@ -41,6 +41,7 @@ module KingKonf
|
|
41
41
|
default: default,
|
42
42
|
required: required,
|
43
43
|
description: description,
|
44
|
+
allowed_values: allowed_values,
|
44
45
|
options: options,
|
45
46
|
)
|
46
47
|
|
@@ -99,11 +100,15 @@ module KingKonf
|
|
99
100
|
|
100
101
|
variable = self.class.variable(name)
|
101
102
|
|
102
|
-
if variable.valid?(value)
|
103
|
-
instance_variable_set("@#{name}", variable.cast(value))
|
104
|
-
else
|
103
|
+
if !variable.valid?(value)
|
105
104
|
raise ConfigError, "invalid value #{value.inspect} for variable `#{name}`, expected #{variable.type}"
|
106
105
|
end
|
106
|
+
|
107
|
+
if !variable.allowed?(value)
|
108
|
+
raise ConfigError, "invalid value #{value.inspect} for variable `#{name}`, allowed values are #{variable.allowed_values}"
|
109
|
+
end
|
110
|
+
|
111
|
+
instance_variable_set("@#{name}", variable.cast(value))
|
107
112
|
end
|
108
113
|
|
109
114
|
def validate!
|
data/lib/king_konf/variable.rb
CHANGED
@@ -2,12 +2,13 @@ require "king_konf/decoder"
|
|
2
2
|
|
3
3
|
module KingKonf
|
4
4
|
class Variable
|
5
|
-
attr_reader :name, :type, :default, :description, :options
|
5
|
+
attr_reader :name, :type, :default, :description, :allowed_values, :options
|
6
6
|
|
7
|
-
def initialize(name:, type:, default: nil, description: "", required: false, options: {})
|
7
|
+
def initialize(name:, type:, default: nil, description: "", required: false, allowed_values: nil, options: {})
|
8
8
|
@name, @type, @default = name, type, default
|
9
9
|
@description = description
|
10
10
|
@required = required
|
11
|
+
@allowed_values = allowed_values
|
11
12
|
@options = options
|
12
13
|
end
|
13
14
|
|
@@ -33,6 +34,10 @@ module KingKonf
|
|
33
34
|
end
|
34
35
|
end
|
35
36
|
|
37
|
+
def allowed?(value)
|
38
|
+
allowed_values.nil? || allowed_values.include?(value)
|
39
|
+
end
|
40
|
+
|
36
41
|
def decode(value)
|
37
42
|
Decoder.public_send(@type, value, **options)
|
38
43
|
end
|
data/lib/king_konf/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: king_konf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Schierbeck
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-02
|
11
|
+
date: 2018-03-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec_junit_formatter
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
description: A simple configuration library
|
56
70
|
email:
|
57
71
|
- daniel.schierbeck@gmail.com
|
@@ -59,6 +73,7 @@ executables: []
|
|
59
73
|
extensions: []
|
60
74
|
extra_rdoc_files: []
|
61
75
|
files:
|
76
|
+
- ".circleci/config.yml"
|
62
77
|
- ".gitignore"
|
63
78
|
- ".rspec"
|
64
79
|
- Gemfile
|
@@ -94,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
94
109
|
version: '0'
|
95
110
|
requirements: []
|
96
111
|
rubyforge_project:
|
97
|
-
rubygems_version: 2.6
|
112
|
+
rubygems_version: 2.7.6
|
98
113
|
signing_key:
|
99
114
|
specification_version: 4
|
100
115
|
summary: A simple configuration library
|