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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 1720918d95b599552ba22661add4aebf7066bd13
4
- data.tar.gz: 0bea3bcfc51e38894f83d8f221e88c3482d5373e
2
+ SHA256:
3
+ metadata.gz: b05b410d3b35c4b341e2f10ec7ca684936c692f21a67452197b5e231c25c87f3
4
+ data.tar.gz: fc5368013c4f4b73d461c3dfabf43be74f37153208f5e0caa1d152765fb37e61
5
5
  SHA512:
6
- metadata.gz: a8509516768a5a9e84ffef2ae63ffeba5760e0f4e1fbaab6674c29cda12378c89c95f59e7b5dc92717d775847a5f22b3c8b5968d10446d62b090c9b74aab86db
7
- data.tar.gz: 3825943e70cfc28c67f7e2718c158b4531b57092bc7403c5864e677cb24cdc63133d0dbc83532ac89a2e92735f7e8e9cab691bd62e8962cf19b756b5156bf10f
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
@@ -23,4 +23,5 @@ Gem::Specification.new do |spec|
23
23
  spec.add_development_dependency "bundler", "~> 1.15"
24
24
  spec.add_development_dependency "rake", "~> 10.0"
25
25
  spec.add_development_dependency "rspec", "~> 3.0"
26
+ spec.add_development_dependency "rspec_junit_formatter"
26
27
  end
@@ -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!
@@ -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
@@ -1,3 +1,3 @@
1
1
  module KingKonf
2
- VERSION = "0.1.10"
2
+ VERSION = "0.2.0"
3
3
  end
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.1.10
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-08 00:00:00.000000000 Z
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.13
112
+ rubygems_version: 2.7.6
98
113
  signing_key:
99
114
  specification_version: 4
100
115
  summary: A simple configuration library