frise 0.4.1 → 0.5.1

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: 86558df34daa0ba92e7e7a1863ceb5124ea52c39dc82a85924c4db1bd89cf127
4
- data.tar.gz: fd286367be54e292a6df52daa6f5255810d6e3980bce538d0c2391d5fdab9ca9
3
+ metadata.gz: 68f89536d127f91e812a1c23258ad32ca3d4331970c9af0632cb3f95fce06e52
4
+ data.tar.gz: 129230d3c50d29a25f4e060bfdf4e839d19aa579607c6bead51acf6237ac9c20
5
5
  SHA512:
6
- metadata.gz: c48f86d8190c30bf650055dfa7749ecdf9d2545f4a6c34593c29e402c0da06dd5420eb8244c3f112f8501564a5bf26798acae2fbeb006c10bb1c4eb5dc4e7c1a
7
- data.tar.gz: 679a4edb6364662160f4e1d6872c8949e3fd6338433da50de5a109addec0a31dec69b3013ca4038fbb40283383b15f160ecf4723c546dea53ab6a8d75db6f77c
6
+ metadata.gz: 61f5a83ff2ba3e17ae022dbac6639fa3a316c4739685ed3cec8634a9a12789dd280c4373763bdebea85d82821b02856327df0df6fbb423d55affb8010252ec64
7
+ data.tar.gz: bc65274a574e25cdbe6142bd7bc2dbe7d6d9275143c211987845dc916156ebe2f0d3ff5739490ea177b67157545b6c5c4aef0a96bbe6dfbaa6f9061c35fcfd73
@@ -0,0 +1,40 @@
1
+ name: CI
2
+
3
+ on: [ push, pull_request ]
4
+
5
+ jobs:
6
+ test:
7
+
8
+ runs-on: ubuntu-latest
9
+ strategy:
10
+ fail-fast: false
11
+ matrix:
12
+ ruby: [ 2.6, 2.7, 3 ]
13
+
14
+ steps:
15
+ - uses: actions/checkout@v2
16
+ - name: Set up Ruby
17
+ uses: ruby/setup-ruby@v1
18
+ with:
19
+ ruby-version: ${{ matrix.ruby }}
20
+ bundler-cache: true
21
+ - name: Install dependencies
22
+ run: bundle install
23
+ - name: Run tests
24
+ run: bundle exec rake
25
+ - name: Coveralls Parallel
26
+ uses: coverallsapp/github-action@master
27
+ with:
28
+ github-token: ${{ secrets.github_token }}
29
+ flag-name: ${{ matrix.ruby }}
30
+ parallel: true
31
+
32
+ finish:
33
+ needs: test
34
+ runs-on: ubuntu-latest
35
+ steps:
36
+ - name: Coveralls Finished
37
+ uses: coverallsapp/github-action@master
38
+ with:
39
+ github-token: ${{ secrets.github_token }}
40
+ parallel-finished: true
data/.rubocop.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  AllCops:
2
- TargetRubyVersion: '2.3'
2
+ NewCops: enable
3
3
  Layout/EmptyLineAfterGuardClause:
4
4
  Enabled: false
5
5
  Metrics:
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ### 0.5.1 (March 28, 2022)
2
+
3
+ - Breaking changes
4
+ - Increase minimum required ruby version to 2.6.0 ([#22](https://github.com/velocidi/frise/pull/22)).
5
+ - Bug fixes
6
+ - Fix YAML.safe_load call arguments error in ruby 3.1 ([#26](https://github.com/velocidi/frise/pull/26)).
7
+
1
8
  ### 0.4.1 (July 7, 2020)
2
9
 
3
10
  - New features
data/frise.gemspec CHANGED
@@ -18,14 +18,15 @@ Gem::Specification.new do |spec|
18
18
  f.match(%r{^(test|spec|features|example)/})
19
19
  end
20
20
  spec.require_paths = ['lib']
21
- spec.required_ruby_version = '>= 2.3.0'
21
+ spec.required_ruby_version = '>= 2.6.0'
22
22
 
23
23
  spec.add_dependency 'liquid', '~> 4.0'
24
24
 
25
25
  spec.add_development_dependency 'bundler', '~> 2.0'
26
- spec.add_development_dependency 'coveralls', '~> 0.8'
27
26
  spec.add_development_dependency 'rake', '~> 13.0'
28
27
  spec.add_development_dependency 'rspec', '~> 3.9'
29
- spec.add_development_dependency 'rubocop', '0.77.0'
30
- spec.add_development_dependency 'simplecov', '~> 0.16'
28
+ spec.add_development_dependency 'rubocop', '~> 1.10'
29
+ spec.add_development_dependency 'simplecov', '~> 0.18'
30
+ spec.add_development_dependency 'simplecov-lcov', '0.8.0'
31
+ spec.metadata['rubygems_mfa_required'] = 'true'
31
32
  end
@@ -10,21 +10,20 @@ module Frise
10
10
  class DefaultsLoader
11
11
  SYMBOLS = %w[$all $optional].freeze
12
12
 
13
- def initialize(include_sym: '$include', content_include_sym: '$content_include', schema_sym: '$schema', delete_sym: '$delete')
13
+ def initialize(
14
+ include_sym: '$include',
15
+ content_include_sym: '$content_include',
16
+ schema_sym: '$schema',
17
+ delete_sym: '$delete'
18
+ )
19
+
14
20
  @include_sym = include_sym
15
21
  @content_include_sym = content_include_sym
16
22
  @schema_sym = schema_sym
17
23
  @delete_sym = delete_sym
18
24
  end
19
25
 
20
- def widened_class(obj)
21
- class_name = obj.class.to_s
22
- return 'String' if class_name == 'Hash' && !obj[@content_include_sym].nil?
23
- return 'Boolean' if %w[TrueClass FalseClass].include? class_name
24
- return 'Integer' if %w[Fixnum Bignum].include? class_name
25
- class_name
26
- end
27
-
26
+ # rubocop:disable Lint/DuplicateBranch
28
27
  def merge_defaults_obj(config, defaults)
29
28
  config_class = widened_class(config)
30
29
  defaults_class = widened_class(defaults)
@@ -35,7 +34,8 @@ module Frise
35
34
  elsif config.nil?
36
35
  if defaults_class != 'Hash' then defaults
37
36
  elsif defaults['$optional'] then nil
38
- else merge_defaults_obj({}, defaults)
37
+ else
38
+ merge_defaults_obj({}, defaults)
39
39
  end
40
40
 
41
41
  elsif config == @delete_sym
@@ -60,12 +60,13 @@ module Frise
60
60
 
61
61
  elsif defaults_class != config_class
62
62
  raise "Cannot merge config #{config.inspect} (#{widened_class(config)}) " \
63
- "with default #{defaults.inspect} (#{widened_class(defaults)})"
63
+ "with default #{defaults.inspect} (#{widened_class(defaults)})"
64
64
 
65
65
  else
66
66
  config
67
67
  end
68
68
  end
69
+ # rubocop:enable Lint/DuplicateBranch
69
70
 
70
71
  def merge_defaults_obj_at(config, at_path, defaults)
71
72
  at_path.reverse.each { |key| defaults = { key => defaults } }
@@ -81,5 +82,15 @@ module Frise
81
82
  defaults = Parser.parse(defaults_file, symbol_table) || {}
82
83
  merge_defaults_obj_at(config, at_path, defaults)
83
84
  end
85
+
86
+ private
87
+
88
+ def widened_class(obj)
89
+ class_name = obj.class.to_s
90
+ return 'String' if class_name == 'Hash' && !obj[@content_include_sym].nil?
91
+ return 'Boolean' if %w[TrueClass FalseClass].include? class_name
92
+ return 'Integer' if %w[Fixnum Bignum].include? class_name
93
+ class_name
94
+ end
84
95
  end
85
96
  end
@@ -12,11 +12,9 @@ module Frise
12
12
  @__target_object__ ||= @callable.call
13
13
  end
14
14
 
15
- # rubocop:disable Style/MethodMissingSuper
16
15
  def method_missing(method_name, *args, &block)
17
16
  __target_object__.send(method_name, *args, &block)
18
17
  end
19
- # rubocop:enable Style/MethodMissingSuper
20
18
 
21
19
  def respond_to_missing?(method_name, include_private = false)
22
20
  __target_object__.respond_to?(method_name, include_private)
data/lib/frise/loader.rb CHANGED
@@ -50,7 +50,7 @@ module Frise
50
50
  private
51
51
 
52
52
  def process_includes(config, at_path, root_config, global_vars, include_confs_stack = [])
53
- return config unless config.class == Hash
53
+ return config unless config.instance_of?(Hash)
54
54
 
55
55
  # process $content_include directives
56
56
  config, content_include_confs = extract_content_include(config, at_path)
@@ -69,26 +69,27 @@ module Frise
69
69
  config, next_include_confs = extract_include(config, at_path)
70
70
  include_confs = next_include_confs + include_confs_stack
71
71
  res = if include_confs.empty?
72
- config.map { |k, v| [k, process_includes(v, at_path + [k], root_config, global_vars)] }.to_h
72
+ config.to_h { |k, v| [k, process_includes(v, at_path + [k], root_config, global_vars)] }
73
73
  else
74
74
  Lazy.new do
75
75
  include_conf = include_confs.first
76
- rest_include_confs = include_confs[1..-1]
76
+ rest_include_confs = include_confs[1..]
77
77
  symbol_table = build_symbol_table(root_config, at_path, config, global_vars, include_conf)
78
78
  included_config = Parser.parse(include_conf['file'], symbol_table)
79
79
  config = @defaults_loader.merge_defaults_obj(config, included_config)
80
- process_includes(config, at_path, merge_at(root_config, at_path, config), global_vars, rest_include_confs)
80
+ process_includes(config, at_path, merge_at(root_config, at_path, config), global_vars,
81
+ rest_include_confs)
81
82
  end
82
83
  end
83
84
  @delete_sym.nil? ? res : omit_deleted(res)
84
85
  end
85
86
 
86
87
  def process_schema_includes(schema, at_path, global_vars)
87
- return schema unless schema.class == Hash
88
+ return schema unless schema.instance_of?(Hash)
88
89
 
89
90
  schema, included_schemas = extract_include(schema, at_path)
90
91
  if included_schemas.empty?
91
- schema.map { |k, v| [k, process_schema_includes(v, at_path + [k], global_vars)] }.to_h
92
+ schema.to_h { |k, v| [k, process_schema_includes(v, at_path + [k], global_vars)] }
92
93
  else
93
94
  included_schemas.each do |defaults_conf|
94
95
  schema = Parser.parse(defaults_conf['file'], global_vars).merge(schema)
@@ -98,13 +99,13 @@ module Frise
98
99
  end
99
100
 
100
101
  def process_schemas(config, at_path, global_vars)
101
- return config unless config.class == Hash
102
+ return config unless config.instance_of?(Hash)
102
103
 
103
- config = config.map do |k, v|
104
+ config = config.to_h do |k, v|
104
105
  new_v = process_schemas(v, at_path + [k], global_vars)
105
106
  return nil if !v.nil? && new_v.nil?
106
107
  [k, new_v]
107
- end.to_h
108
+ end
108
109
 
109
110
  config, schema_files = extract_schema(config, at_path)
110
111
  schema_files.each do |schema_file|
@@ -149,10 +150,10 @@ module Frise
149
150
  end
150
151
  end
151
152
 
152
- def extract_special(config, key, at_path)
153
+ def extract_special(config, key, at_path, &block)
153
154
  case config[key]
154
155
  when nil then [config, []]
155
- when Array then [config.reject { |k| k == key }, config[key].map { |e| yield e }]
156
+ when Array then [config.reject { |k| k == key }, config[key].map(&block)]
156
157
  else raise "At #{build_path(at_path)}: illegal value for #{key}: #{config[key].inspect}"
157
158
  end
158
159
  end
@@ -165,6 +166,7 @@ module Frise
165
166
  end
166
167
 
167
168
  # returns the config without the keys whose values are @delete_sym
169
+ # @delete_sym given as array elements are not handled.
168
170
  def omit_deleted(config)
169
171
  config.each_with_object({}) do |(k, v), new_hash|
170
172
  if v.is_a?(Hash)
@@ -182,7 +184,7 @@ module Frise
182
184
  # - `global_vars`: the global variables
183
185
  # - `include_conf`: the $include or $content_include configuration
184
186
  def build_symbol_table(root_config, at_path, config, global_vars, include_conf)
185
- extra_vars = (include_conf['vars'] || {}).map { |k, v| [k, root_config.dig(*v.split('.'))] }.to_h
187
+ extra_vars = (include_conf['vars'] || {}).transform_values { |v| root_config.dig(*v.split('.')) }
186
188
  extra_consts = include_conf['constants'] || {}
187
189
 
188
190
  omit_deleted(config ? merge_at(root_config, at_path, config) : root_config)
data/lib/frise/parser.rb CHANGED
@@ -10,7 +10,7 @@ module Frise
10
10
  class << self
11
11
  def parse(file, symbol_table = nil)
12
12
  return nil unless File.file? file
13
- YAML.safe_load(parse_as_text(file, symbol_table), [], [], true) || {}
13
+ YAML.safe_load(parse_as_text(file, symbol_table), aliases: true) || {}
14
14
  end
15
15
 
16
16
  def parse_as_text(file, symbol_table = nil)
@@ -14,6 +14,8 @@ module Frise
14
14
  attr_reader :errors
15
15
 
16
16
  def initialize(root, validators = nil)
17
+ super()
18
+
17
19
  @root = root
18
20
  @validators = validators
19
21
  @errors = []
@@ -33,7 +35,7 @@ module Frise
33
35
 
34
36
  def get_full_schema(schema)
35
37
  case schema
36
- when Hash then
38
+ when Hash
37
39
  default_type = schema[:enum] || schema[:one_of] ? 'Object' : 'Hash'
38
40
  { type: default_type }.merge(schema)
39
41
  when Symbol then { type: 'Object', validate: schema }
@@ -93,7 +95,7 @@ module Frise
93
95
  def validate_enum(full_schema, obj, path)
94
96
  if full_schema[:enum] && !full_schema[:enum].include?(obj)
95
97
  add_validation_error(path, "invalid value #{obj.inspect}. " \
96
- "Accepted values are #{full_schema[:enum].map(&:inspect).join(', ')}")
98
+ "Accepted values are #{full_schema[:enum].map(&:inspect).join(', ')}")
97
99
  return false
98
100
  end
99
101
  true
@@ -124,7 +126,7 @@ module Frise
124
126
  def validate_remaining_keys(full_schema, obj, path, processed_keys)
125
127
  expected_types = get_expected_types(full_schema)
126
128
  if expected_types.size == 1 && expected_types[0].ancestors.member?(Enumerable)
127
- hash = obj.is_a?(Hash) ? obj : Hash[obj.map.with_index { |x, i| [i, x] }]
129
+ hash = obj.is_a?(Hash) ? obj : obj.map.with_index { |x, i| [i, x] }.to_h
128
130
  hash.each do |key, value|
129
131
  validate_object(path, key, full_schema[:all_keys]) if full_schema[:all_keys] && !key.is_a?(Symbol)
130
132
 
@@ -156,8 +158,8 @@ module Frise
156
158
  def self.parse_symbols(obj)
157
159
  case obj
158
160
  when Array then obj.map { |e| parse_symbols(e) }
159
- when Hash then Hash[obj.map { |k, v| [parse_symbols(k), parse_symbols(v)] }]
160
- when String then obj.start_with?('$') ? obj[1..-1].to_sym : obj
161
+ when Hash then obj.to_h { |k, v| [parse_symbols(k), parse_symbols(v)] }
162
+ when String then obj.start_with?('$') ? obj[1..].to_sym : obj
161
163
  else obj
162
164
  end
163
165
  end
@@ -166,7 +168,17 @@ module Frise
166
168
  validate_obj_at(config, [], schema, **options)
167
169
  end
168
170
 
169
- def self.validate_obj_at(config, at_path, schema, path_prefix: nil, validators: nil, print: nil, fatal: nil, raise_error: nil)
171
+ def self.validate_obj_at(
172
+ config,
173
+ at_path,
174
+ schema,
175
+ path_prefix: nil,
176
+ validators: nil,
177
+ print: nil,
178
+ fatal: nil,
179
+ raise_error: nil
180
+ )
181
+
170
182
  schema = parse_symbols(schema)
171
183
  at_path.reverse.each { |key| schema = { key => schema, :allow_unknown_keys => true } }
172
184
 
@@ -202,6 +214,8 @@ module Frise
202
214
  attr_reader :errors
203
215
 
204
216
  def initialize(errors)
217
+ super()
218
+
205
219
  @errors = errors
206
220
  end
207
221
  end
data/lib/frise/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Frise
4
- VERSION = '0.4.1'
4
+ VERSION = '0.5.1'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: frise
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Velocidi
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-07 00:00:00.000000000 Z
11
+ date: 2022-03-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: liquid
@@ -39,86 +39,86 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '2.0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: coveralls
42
+ name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0.8'
47
+ version: '13.0'
48
48
  type: :development
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.8'
54
+ version: '13.0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: rake
56
+ name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '13.0'
61
+ version: '3.9'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '13.0'
68
+ version: '3.9'
69
69
  - !ruby/object:Gem::Dependency
70
- name: rspec
70
+ name: rubocop
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '3.9'
75
+ version: '1.10'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '3.9'
82
+ version: '1.10'
83
83
  - !ruby/object:Gem::Dependency
84
- name: rubocop
84
+ name: simplecov
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - '='
87
+ - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: 0.77.0
89
+ version: '0.18'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - '='
94
+ - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: 0.77.0
96
+ version: '0.18'
97
97
  - !ruby/object:Gem::Dependency
98
- name: simplecov
98
+ name: simplecov-lcov
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - "~>"
101
+ - - '='
102
102
  - !ruby/object:Gem::Version
103
- version: '0.16'
103
+ version: 0.8.0
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - "~>"
108
+ - - '='
109
109
  - !ruby/object:Gem::Version
110
- version: '0.16'
111
- description:
110
+ version: 0.8.0
111
+ description:
112
112
  email:
113
113
  - hello@velocidi.com
114
114
  executables: []
115
115
  extensions: []
116
116
  extra_rdoc_files: []
117
117
  files:
118
+ - ".github/workflows/CI.yml"
118
119
  - ".gitignore"
119
120
  - ".rspec"
120
121
  - ".rubocop.yml"
121
- - ".travis.yml"
122
122
  - CHANGELOG.md
123
123
  - Gemfile
124
124
  - LICENSE.txt
@@ -135,8 +135,9 @@ files:
135
135
  homepage: https://github.com/velocidi/frise
136
136
  licenses:
137
137
  - Apache-2.0
138
- metadata: {}
139
- post_install_message:
138
+ metadata:
139
+ rubygems_mfa_required: 'true'
140
+ post_install_message:
140
141
  rdoc_options: []
141
142
  require_paths:
142
143
  - lib
@@ -144,15 +145,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
144
145
  requirements:
145
146
  - - ">="
146
147
  - !ruby/object:Gem::Version
147
- version: 2.3.0
148
+ version: 2.6.0
148
149
  required_rubygems_version: !ruby/object:Gem::Requirement
149
150
  requirements:
150
151
  - - ">="
151
152
  - !ruby/object:Gem::Version
152
153
  version: '0'
153
154
  requirements: []
154
- rubygems_version: 3.0.6
155
- signing_key:
155
+ rubygems_version: 3.3.7
156
+ signing_key:
156
157
  specification_version: 4
157
158
  summary: Ruby config library with schema validation, default values and templating
158
159
  test_files: []
data/.travis.yml DELETED
@@ -1,10 +0,0 @@
1
- language: ruby
2
- cache: bundler
3
- rvm:
4
- - 2.3
5
- - 2.4
6
- - 2.5
7
- - 2.6
8
- - 2.7
9
- before_install:
10
- - gem install bundler