attributor-flatpack 1.2.2 → 1.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.rubocop.yml +15 -9
- data/.ruby-version +1 -1
- data/CHANGELOG.md +15 -3
- data/Gemfile +2 -0
- data/Guardfile +6 -4
- data/Rakefile +2 -0
- data/attributor-flatpack.gemspec +5 -3
- data/benchmark/Gemfile +2 -0
- data/benchmark/bench.rb +3 -0
- data/bin/console +1 -0
- data/examples/sample_config.rb +2 -0
- data/lib/attributor/flatpack.rb +3 -0
- data/lib/attributor/flatpack/config.rb +27 -6
- data/lib/attributor/flatpack/config_dsl_compiler.rb +3 -0
- data/lib/attributor/flatpack/types/multiline_string.rb +20 -0
- data/lib/attributor/flatpack/undefined_key.rb +2 -0
- data/lib/attributor/flatpack/version.rb +3 -1
- metadata +16 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 05e224a1d45d2c46f2033a79cb42bc58862c40189c221dcece9bf5b77b68c330
|
4
|
+
data.tar.gz: 7e840c73a9af7cf19c4882500fb2b5559da0cf4315561ca635af31c5c3a47c20
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1522bfc14ae927b1fd3aedcb0be2b2de83e33e640f4a0a457bb480b57404cef7345c08c534457a45ee0c327f860321c3641b649f3249ae8541a7f6ea75ccab09
|
7
|
+
data.tar.gz: 8949fdfc0466bf24fb7f33d86054e64b5289a1b678284538144a34c7d592fd53eecfc5dfc61946745871e3c33fd607b6066571ca52eb3630be92462986045714
|
data/.rubocop.yml
CHANGED
@@ -1,20 +1,26 @@
|
|
1
1
|
AllCops:
|
2
|
-
TargetRubyVersion: 2.
|
2
|
+
TargetRubyVersion: 2.7
|
3
|
+
NewCops: enable
|
3
4
|
Style/Documentation:
|
4
5
|
Enabled: false
|
5
|
-
|
6
|
-
|
7
|
-
- lib/attributor/flatpack.rb
|
8
|
-
- lib/attributor/flatpack/config.rb
|
9
|
-
- lib/attributor/flatpack/config_dsl_compiler.rb
|
10
|
-
- lib/attributor/flatpack/undefined_key.rb
|
6
|
+
Metrics/AbcSize:
|
7
|
+
Max: 20
|
11
8
|
Metrics/MethodLength:
|
12
9
|
Enabled: false
|
13
10
|
Metrics/ClassLength:
|
14
11
|
Enabled: false
|
15
|
-
|
16
|
-
Max:
|
12
|
+
Layout/LineLength:
|
13
|
+
Max: 160
|
14
|
+
Exclude:
|
15
|
+
- "spec/**/*.rb"
|
17
16
|
Style/RedundantSelf:
|
18
17
|
Enabled: false
|
19
18
|
Style/DoubleNegation:
|
20
19
|
Enabled: false
|
20
|
+
Metrics/BlockLength:
|
21
|
+
Exclude:
|
22
|
+
- spec/**/*.rb
|
23
|
+
Style/RedundantFetchBlock:
|
24
|
+
Enabled: false
|
25
|
+
Style/HashEachMethods:
|
26
|
+
Enabled: false
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.7.1
|
data/CHANGELOG.md
CHANGED
@@ -1,13 +1,25 @@
|
|
1
1
|
# attributor-flatpack changelog
|
2
2
|
|
3
|
+
## 1.4.1
|
4
|
+
|
5
|
+
- Fix regexp for `Config#subselect` not escaping the separator and not matching properly
|
6
|
+
|
7
|
+
## 1.4
|
8
|
+
|
9
|
+
- Respect `allow_extra: true` option when validating.
|
10
|
+
|
11
|
+
## 1.3
|
12
|
+
|
13
|
+
- Add `Attributor::Flatpack::MultilineString` type to handle multiline strings from environment variables.
|
14
|
+
|
3
15
|
## 1.2
|
4
16
|
|
5
|
-
|
17
|
+
- Add support for redefining the separator
|
6
18
|
|
7
19
|
## 1.1
|
8
20
|
|
9
|
-
|
21
|
+
- Significant performance improvements. See [benchmark results](benchmark/output.txt) for comparisons.
|
10
22
|
|
11
23
|
## 1.0
|
12
24
|
|
13
|
-
|
25
|
+
- Initial Release
|
data/Gemfile
CHANGED
data/Guardfile
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# A sample Guardfile
|
2
4
|
# More info at https://github.com/guard/guard#readme
|
3
5
|
|
@@ -42,8 +44,8 @@ group :red_green_refactor, halt_on_fail: true do
|
|
42
44
|
dsl.watch_spec_files_for(ruby.lib_files)
|
43
45
|
end
|
44
46
|
|
45
|
-
guard :rubocop do
|
46
|
-
|
47
|
-
|
48
|
-
end
|
47
|
+
# guard :rubocop do
|
48
|
+
# watch(/.+\.rb$/)
|
49
|
+
# watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
|
50
|
+
# end
|
49
51
|
end
|
data/Rakefile
CHANGED
data/attributor-flatpack.gemspec
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
lib = File.expand_path('lib', __dir__)
|
2
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
5
|
require 'attributor/flatpack/version'
|
@@ -20,7 +22,7 @@ Gem::Specification.new do |spec| # rubocop:disable Metrics/BlockLength
|
|
20
22
|
spec.require_paths = ['lib']
|
21
23
|
|
22
24
|
spec.add_dependency 'attributor', '>= 5'
|
23
|
-
spec.add_development_dependency 'bundler'
|
25
|
+
spec.add_development_dependency 'bundler'
|
24
26
|
spec.add_development_dependency 'codeclimate-test-reporter'
|
25
27
|
spec.add_development_dependency 'fuubar', '~> 2'
|
26
28
|
spec.add_development_dependency 'guard'
|
@@ -28,8 +30,8 @@ Gem::Specification.new do |spec| # rubocop:disable Metrics/BlockLength
|
|
28
30
|
spec.add_development_dependency 'guard-rubocop'
|
29
31
|
spec.add_development_dependency 'pry'
|
30
32
|
spec.add_development_dependency 'pry-byebug'
|
31
|
-
spec.add_development_dependency 'rake'
|
32
|
-
spec.add_development_dependency 'rspec'
|
33
|
+
spec.add_development_dependency 'rake'
|
34
|
+
spec.add_development_dependency 'rspec'
|
33
35
|
spec.add_development_dependency 'rspec-its'
|
34
36
|
spec.add_development_dependency 'simplecov'
|
35
37
|
end
|
data/benchmark/Gemfile
CHANGED
data/benchmark/bench.rb
CHANGED
data/bin/console
CHANGED
data/examples/sample_config.rb
CHANGED
data/lib/attributor/flatpack.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'attributor'
|
2
4
|
|
3
5
|
require 'attributor/flatpack/version'
|
@@ -5,6 +7,7 @@ require 'attributor/flatpack/config_dsl_compiler'
|
|
5
7
|
|
6
8
|
require 'attributor/flatpack/config'
|
7
9
|
require 'attributor/flatpack/undefined_key'
|
10
|
+
require 'attributor/flatpack/types/multiline_string'
|
8
11
|
|
9
12
|
module Attributor
|
10
13
|
module Flatpack
|
@@ -1,7 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Attributor
|
2
4
|
module Flatpack
|
3
5
|
class Config < Attributor::Hash
|
4
|
-
@separator = '_'
|
6
|
+
@separator = '_'
|
5
7
|
@key_type = Symbol
|
6
8
|
|
7
9
|
class << self
|
@@ -19,6 +21,7 @@ module Attributor
|
|
19
21
|
@separator = sep
|
20
22
|
end
|
21
23
|
klass.options[:dsl_compiler] = ConfigDSLCompiler
|
24
|
+
klass.options[:allow_extra] = true
|
22
25
|
end
|
23
26
|
|
24
27
|
def self.from_hash(object, _context, **_opts)
|
@@ -29,7 +32,8 @@ module Attributor
|
|
29
32
|
def self.example(context = nil, **values)
|
30
33
|
example = super
|
31
34
|
# Need the @raw to be set as well, since we're using it in fetch
|
32
|
-
example.
|
35
|
+
contents = example.instance_variable_get(:@contents)
|
36
|
+
example.instance_variable_set(:@raw, contents.dup)
|
33
37
|
example
|
34
38
|
end
|
35
39
|
|
@@ -107,17 +111,17 @@ module Attributor
|
|
107
111
|
def fetch(key)
|
108
112
|
return @raw[key] if @raw.key?(key)
|
109
113
|
|
110
|
-
|
114
|
+
found_key, found_value = @raw.find do |(k, _v)|
|
111
115
|
k.to_s.casecmp(key.to_s).zero?
|
112
116
|
end
|
113
117
|
|
114
|
-
return found_value if
|
118
|
+
return found_value if found_key
|
115
119
|
|
116
120
|
yield if block_given?
|
117
121
|
end
|
118
122
|
|
119
123
|
def subselect(prefix)
|
120
|
-
prefix_match = /^#{prefix
|
124
|
+
prefix_match = /^#{prefix}#{::Regexp.escape(self.class.separator)}(.*)/i
|
121
125
|
|
122
126
|
selected = @raw.collect do |(k, v)|
|
123
127
|
if (match = prefix_match.match(k))
|
@@ -147,7 +151,8 @@ module Attributor
|
|
147
151
|
# shamelessly copied from Attributor::Model's #validate :(
|
148
152
|
def validate(context = Attributor::DEFAULT_ROOT_CONTEXT)
|
149
153
|
self.validate_attributes(context) +
|
150
|
-
self.validate_requirements(context)
|
154
|
+
self.validate_requirements(context) +
|
155
|
+
self.validate_keys(context)
|
151
156
|
end
|
152
157
|
|
153
158
|
def validate_attributes(context)
|
@@ -164,6 +169,16 @@ module Attributor
|
|
164
169
|
end
|
165
170
|
end
|
166
171
|
|
172
|
+
def validate_keys(context)
|
173
|
+
return [] if self.class.options[:allow_extra]
|
174
|
+
|
175
|
+
errors = (@raw.keys.collect(&:to_s) - self.class.keys.keys.collect(&:to_s)).collect do |extra_key|
|
176
|
+
"Unknown key received: #{extra_key.inspect} for #{Attributor.humanize_context(context)}"
|
177
|
+
end
|
178
|
+
|
179
|
+
errors
|
180
|
+
end
|
181
|
+
|
167
182
|
def pretty_print(context: [])
|
168
183
|
self.collect do |k, v|
|
169
184
|
sub_context = context + [k]
|
@@ -175,6 +190,12 @@ module Attributor
|
|
175
190
|
end
|
176
191
|
end.flatten
|
177
192
|
end
|
193
|
+
|
194
|
+
def dump(**opts)
|
195
|
+
# quick hack to ensure we load all the values into @contents
|
196
|
+
self.validate
|
197
|
+
super
|
198
|
+
end
|
178
199
|
end
|
179
200
|
end
|
180
201
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Attributor
|
2
4
|
module Flatpack
|
3
5
|
class ConfigDSLCompiler < Attributor::HashDSLCompiler
|
@@ -10,6 +12,7 @@ module Attributor
|
|
10
12
|
if attr_type.nil? && block
|
11
13
|
sep = target.separator
|
12
14
|
# Ensure class for subkeys uses the same separator as the parent
|
15
|
+
opts[:allow_extra] = options[:allow_extra]
|
13
16
|
attr_type = ::Class.new(Attributor::Flatpack::Config) do
|
14
17
|
separator sep
|
15
18
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Sometimes a multline string when read in by ruby has escaped newlines, sometimes not.
|
4
|
+
# This type will remove any escaping of newline from a string.
|
5
|
+
|
6
|
+
module Attributor
|
7
|
+
module Flatpack
|
8
|
+
class MultilineString < Attributor::String
|
9
|
+
def self.load(value, context = Attributor::DEFAULT_ROOT_CONTEXT, **options)
|
10
|
+
value.gsub('\\n', "\n")
|
11
|
+
rescue StandardError
|
12
|
+
super
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.example(*)
|
16
|
+
'-----BEGIN EC PRIVATE KEY-----\\nMIHcAgEBBEI\\n3abcdefghijklmnop==\\n-----END EC PRIVATE KEY-----'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: attributor-flatpack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dane Jensen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-06-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: attributor
|
@@ -28,16 +28,16 @@ dependencies:
|
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: codeclimate-test-reporter
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -140,30 +140,30 @@ dependencies:
|
|
140
140
|
name: rake
|
141
141
|
requirement: !ruby/object:Gem::Requirement
|
142
142
|
requirements:
|
143
|
-
- - "
|
143
|
+
- - ">="
|
144
144
|
- !ruby/object:Gem::Version
|
145
|
-
version: '
|
145
|
+
version: '0'
|
146
146
|
type: :development
|
147
147
|
prerelease: false
|
148
148
|
version_requirements: !ruby/object:Gem::Requirement
|
149
149
|
requirements:
|
150
|
-
- - "
|
150
|
+
- - ">="
|
151
151
|
- !ruby/object:Gem::Version
|
152
|
-
version: '
|
152
|
+
version: '0'
|
153
153
|
- !ruby/object:Gem::Dependency
|
154
154
|
name: rspec
|
155
155
|
requirement: !ruby/object:Gem::Requirement
|
156
156
|
requirements:
|
157
|
-
- - "
|
157
|
+
- - ">="
|
158
158
|
- !ruby/object:Gem::Version
|
159
|
-
version: '
|
159
|
+
version: '0'
|
160
160
|
type: :development
|
161
161
|
prerelease: false
|
162
162
|
version_requirements: !ruby/object:Gem::Requirement
|
163
163
|
requirements:
|
164
|
-
- - "
|
164
|
+
- - ">="
|
165
165
|
- !ruby/object:Gem::Version
|
166
|
-
version: '
|
166
|
+
version: '0'
|
167
167
|
- !ruby/object:Gem::Dependency
|
168
168
|
name: rspec-its
|
169
169
|
requirement: !ruby/object:Gem::Requirement
|
@@ -221,6 +221,7 @@ files:
|
|
221
221
|
- lib/attributor/flatpack.rb
|
222
222
|
- lib/attributor/flatpack/config.rb
|
223
223
|
- lib/attributor/flatpack/config_dsl_compiler.rb
|
224
|
+
- lib/attributor/flatpack/types/multiline_string.rb
|
224
225
|
- lib/attributor/flatpack/undefined_key.rb
|
225
226
|
- lib/attributor/flatpack/version.rb
|
226
227
|
homepage: https://github.com/careo/attributor-flatpack
|
@@ -242,8 +243,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
242
243
|
- !ruby/object:Gem::Version
|
243
244
|
version: '0'
|
244
245
|
requirements: []
|
245
|
-
|
246
|
-
rubygems_version: 2.6.14
|
246
|
+
rubygems_version: 3.1.2
|
247
247
|
signing_key:
|
248
248
|
specification_version: 4
|
249
249
|
summary: Attributor type for loading configuration data
|