frise 0.4.0 → 0.4.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: 59666a0c683f8357e7da23de68bd0cc07b386299943e772dd40d9d641ac2d8c7
4
- data.tar.gz: 6827402a3f207d909845c0fa386f61cd3d32b989206e15d22b58202830406c88
3
+ metadata.gz: 86558df34daa0ba92e7e7a1863ceb5124ea52c39dc82a85924c4db1bd89cf127
4
+ data.tar.gz: fd286367be54e292a6df52daa6f5255810d6e3980bce538d0c2391d5fdab9ca9
5
5
  SHA512:
6
- metadata.gz: 75c11d0c64a9d0a7f37c3b7702ab2000c09d76900c8c58477bc2426ea47ef766b3c03f77c0fd15928fd55a636009fe33f6e2e19efe8f6454945a3a22ea8b86b3
7
- data.tar.gz: 582bb37e6e27f4da44aa496321abf66def05ca151218680c776772fc893824f03ab61ed6e11d3c2006853bd627d53f378eb79f3190033d69869a8ee574184177
6
+ metadata.gz: c48f86d8190c30bf650055dfa7749ecdf9d2545f4a6c34593c29e402c0da06dd5420eb8244c3f112f8501564a5bf26798acae2fbeb006c10bb1c4eb5dc4e7c1a
7
+ data.tar.gz: 679a4edb6364662160f4e1d6872c8949e3fd6338433da50de5a109addec0a31dec69b3013ca4038fbb40283383b15f160ecf4723c546dea53ab6a8d75db6f77c
@@ -5,5 +5,6 @@ rvm:
5
5
  - 2.4
6
6
  - 2.5
7
7
  - 2.6
8
+ - 2.7
8
9
  before_install:
9
10
  - gem install bundler
@@ -1,3 +1,9 @@
1
+ ### 0.4.1 (July 7, 2020)
2
+
3
+ - New features
4
+ - `$delete` directive is now available in config files, allowing users to delete parts of the
5
+ config sub-tree ([#20](https://github.com/velocidi/frise/pull/20)).
6
+
1
7
  ### 0.4.0 (November 29, 2019)
2
8
 
3
9
  - Breaking changes
@@ -10,10 +10,11 @@ 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')
13
+ def initialize(include_sym: '$include', content_include_sym: '$content_include', schema_sym: '$schema', delete_sym: '$delete')
14
14
  @include_sym = include_sym
15
15
  @content_include_sym = content_include_sym
16
16
  @schema_sym = schema_sym
17
+ @delete_sym = delete_sym
17
18
  end
18
19
 
19
20
  def widened_class(obj)
@@ -37,6 +38,9 @@ module Frise
37
38
  else merge_defaults_obj({}, defaults)
38
39
  end
39
40
 
41
+ elsif config == @delete_sym
42
+ config
43
+
40
44
  elsif defaults_class == 'Array' && config_class == 'Array'
41
45
  defaults + config
42
46
 
@@ -13,6 +13,7 @@ module Frise
13
13
  def initialize(include_sym: '$include',
14
14
  content_include_sym: '$content_include',
15
15
  schema_sym: '$schema',
16
+ delete_sym: '$delete',
16
17
  pre_loaders: [],
17
18
  validators: nil,
18
19
  exit_on_fail: true)
@@ -20,6 +21,7 @@ module Frise
20
21
  @include_sym = include_sym
21
22
  @content_include_sym = content_include_sym
22
23
  @schema_sym = schema_sym
24
+ @delete_sym = delete_sym
23
25
  @pre_loaders = pre_loaders
24
26
  @validators = validators
25
27
  @exit_on_fail = exit_on_fail
@@ -27,7 +29,8 @@ module Frise
27
29
  @defaults_loader = DefaultsLoader.new(
28
30
  include_sym: include_sym,
29
31
  content_include_sym: content_include_sym,
30
- schema_sym: schema_sym
32
+ schema_sym: schema_sym,
33
+ delete_sym: delete_sym
31
34
  )
32
35
  end
33
36
 
@@ -39,8 +42,8 @@ module Frise
39
42
  config = pre_loader.call(config)
40
43
  end
41
44
 
42
- config = process_includes(config, [], config, global_vars) if @include_sym
43
- config = process_schemas(config, [], global_vars) if @schema_sym
45
+ config = process_includes(config, [], config, global_vars) unless @include_sym.nil?
46
+ config = process_schemas(config, [], global_vars) unless @schema_sym.nil?
44
47
  config
45
48
  end
46
49
 
@@ -65,18 +68,19 @@ module Frise
65
68
  # process $include directives
66
69
  config, next_include_confs = extract_include(config, at_path)
67
70
  include_confs = next_include_confs + include_confs_stack
68
- if include_confs.empty?
69
- config.map { |k, v| [k, process_includes(v, at_path + [k], root_config, global_vars)] }.to_h
70
- else
71
- Lazy.new do
72
- include_conf = include_confs.first
73
- rest_include_confs = include_confs[1..-1]
74
- symbol_table = build_symbol_table(root_config, at_path, config, global_vars, include_conf)
75
- included_config = Parser.parse(include_conf['file'], symbol_table)
76
- config = @defaults_loader.merge_defaults_obj(config, included_config)
77
- process_includes(config, at_path, merge_at(root_config, at_path, config), global_vars, rest_include_confs)
78
- end
79
- end
71
+ res = if include_confs.empty?
72
+ config.map { |k, v| [k, process_includes(v, at_path + [k], root_config, global_vars)] }.to_h
73
+ else
74
+ Lazy.new do
75
+ include_conf = include_confs.first
76
+ rest_include_confs = include_confs[1..-1]
77
+ symbol_table = build_symbol_table(root_config, at_path, config, global_vars, include_conf)
78
+ included_config = Parser.parse(include_conf['file'], symbol_table)
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)
81
+ end
82
+ end
83
+ @delete_sym.nil? ? res : omit_deleted(res)
80
84
  end
81
85
 
82
86
  def process_schema_includes(schema, at_path, global_vars)
@@ -160,6 +164,17 @@ module Frise
160
164
  config.merge(head => merge_at(config[head], tail, to_merge))
161
165
  end
162
166
 
167
+ # returns the config without the keys whose values are @delete_sym
168
+ def omit_deleted(config)
169
+ config.each_with_object({}) do |(k, v), new_hash|
170
+ if v.is_a?(Hash)
171
+ new_hash[k] = omit_deleted(v)
172
+ else
173
+ new_hash[k] = v unless v == @delete_sym
174
+ end
175
+ end
176
+ end
177
+
163
178
  # builds the symbol table for the Liquid renderization of a file, based on:
164
179
  # - `root_config`: the root of the whole config
165
180
  # - `at_path`: the current path
@@ -170,7 +185,7 @@ module Frise
170
185
  extra_vars = (include_conf['vars'] || {}).map { |k, v| [k, root_config.dig(*v.split('.'))] }.to_h
171
186
  extra_consts = include_conf['constants'] || {}
172
187
 
173
- (config ? merge_at(root_config, at_path, config) : root_config)
188
+ omit_deleted(config ? merge_at(root_config, at_path, config) : root_config)
174
189
  .merge(global_vars)
175
190
  .merge(extra_vars)
176
191
  .merge(extra_consts)
@@ -163,7 +163,7 @@ module Frise
163
163
  end
164
164
 
165
165
  def self.validate_obj(config, schema, options = {})
166
- validate_obj_at(config, [], schema, options)
166
+ validate_obj_at(config, [], schema, **options)
167
167
  end
168
168
 
169
169
  def self.validate_obj_at(config, at_path, schema, path_prefix: nil, validators: nil, print: nil, fatal: nil, raise_error: nil)
@@ -188,11 +188,11 @@ module Frise
188
188
  end
189
189
 
190
190
  def self.validate(config, schema_file, options = {})
191
- validate_obj_at(config, [], Parser.parse(schema_file) || { allow_unknown_keys: true }, options)
191
+ validate_obj_at(config, [], Parser.parse(schema_file) || { allow_unknown_keys: true }, **options)
192
192
  end
193
193
 
194
194
  def self.validate_at(config, at_path, schema_file, options = {})
195
- validate_obj_at(config, at_path, Parser.parse(schema_file) || { allow_unknown_keys: true }, options)
195
+ validate_obj_at(config, at_path, Parser.parse(schema_file) || { allow_unknown_keys: true }, **options)
196
196
  end
197
197
  end
198
198
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Frise
4
- VERSION = '0.4.0'
4
+ VERSION = '0.4.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.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Velocidi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-11-29 00:00:00.000000000 Z
11
+ date: 2020-07-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: liquid
@@ -151,8 +151,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0'
153
153
  requirements: []
154
- rubyforge_project:
155
- rubygems_version: 2.7.3
154
+ rubygems_version: 3.0.6
156
155
  signing_key:
157
156
  specification_version: 4
158
157
  summary: Ruby config library with schema validation, default values and templating