rggen-core 0.31.2 → 0.32.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 45a9b6397155e93d65c0c171ec0ac17440baac57ec595e26029c657c1f775766
4
- data.tar.gz: a8da50f308ac9eb4ca9079571b69cbb5c8c630abc59f02962e5547f63605ef98
3
+ metadata.gz: dcbb14dd216582b7b503d8375561dba39eefd175b5b4805a413cd300de7a567a
4
+ data.tar.gz: ad41cb0b010b50ea9b92589ee5c83b90a797b9c6757f612b789ac64924ecc1ab
5
5
  SHA512:
6
- metadata.gz: 8d6e431128bdeb4977c546a2911147666aa47f922e396bf2a575efafb569213511bb789ba39d3fbbb89e9fc24838f144fa91ff727118bb5ecaf57a96a3a45a51
7
- data.tar.gz: afdbe15fec9f8b40ab17054113769b4d4cc3889942da24dc6eeb10aa147bd3e82e39cd69817b09c161ab1ed19b439472562db6d0d58729563756de0a49a9aa71
6
+ metadata.gz: f349b6601893afd5d7ca66e841cb0c0476d8ce29ac53a30a1cc47e1d65fc532ed64b9da36d2790542e064a9d93c8a69b9113529f1aaa1414d09c63655c8719f4
7
+ data.tar.gz: a4815c7d1b0c1123a9c6438bb110ed760d2f054728b5e81b24eedf2d6f1e948e1ee5b05810b6506833343a6686bd13508abbf79129c69329b3ae7916a602e09a
data/README.md CHANGED
@@ -2,7 +2,6 @@
2
2
  [![CI](https://github.com/rggen/rggen-core/workflows/CI/badge.svg)](https://github.com/rggen/rggen-core/actions?query=workflow%3ACI)
3
3
  [![Maintainability](https://api.codeclimate.com/v1/badges/53c8e6654c2b5ecb9142/maintainability)](https://codeclimate.com/github/rggen/rggen-core/maintainability)
4
4
  [![codecov](https://codecov.io/gh/rggen/rggen-core/branch/master/graph/badge.svg)](https://codecov.io/gh/rggen/rggen-core)
5
- [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=rggen_rggen-core&metric=alert_status)](https://sonarcloud.io/dashboard?id=rggen_rggen-core)
6
5
  [![Gitter](https://badges.gitter.im/rggen/rggen.svg)](https://gitter.im/rggen/rggen?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
7
6
 
8
7
  # RgGen::Core
@@ -50,7 +50,11 @@ module RgGen
50
50
  :define_feature,
51
51
  :define_simple_feature,
52
52
  :define_list_feature,
53
- :define_list_item_feature
53
+ :define_list_item_feature,
54
+ :modify_feature,
55
+ :modify_simple_feature,
56
+ :modify_list_feature,
57
+ :modify_list_item_feature
54
58
  ].each do |method_name|
55
59
  define_method(method_name) do |layer, *args, &body|
56
60
  @layers[layer].__send__(__method__, *args, &body)
@@ -39,10 +39,11 @@ module RgGen
39
39
  end
40
40
 
41
41
  def build_factories
42
- factories =
43
- @entries
44
- .map(&:build_factory)
45
- .to_h { |f| [f.layer, f] }
42
+ factories = @entries.to_h do |entry|
43
+ entry
44
+ .build_factory
45
+ .then { |f| [f.layer, f] }
46
+ end
46
47
  factories.each_value { |f| f.component_factories factories }
47
48
  factories.values
48
49
  end
@@ -12,6 +12,10 @@ module RgGen
12
12
  attr_reader :registry
13
13
  attr_reader :name
14
14
 
15
+ def modify(&body)
16
+ eval_body(&body)
17
+ end
18
+
15
19
  def match_entry_type?(entry_type)
16
20
  entry_type == entry_type_name
17
21
  end
@@ -31,6 +35,10 @@ module RgGen
31
35
  end
32
36
  end
33
37
 
38
+ def eval_body(&body)
39
+ block_given? && Docile.dsl_eval(self, @name, &body)
40
+ end
41
+
34
42
  def target_features(_tergets)
35
43
  end
36
44
 
@@ -24,10 +24,23 @@ module RgGen
24
24
  end
25
25
 
26
26
  def define_list_item_feature(list_name, feature_name, context = nil, &body)
27
- entry = @feature_entries[list_name]
28
- entry&.match_entry_type?(:list) ||
29
- (raise BuilderError.new("unknown list feature: #{list_name}"))
30
- entry.define_feature(feature_name, context, &body)
27
+ list_item_entry(list_name).define_feature(feature_name, context, &body)
28
+ end
29
+
30
+ def modify_feature(name, &body)
31
+ modify_entry(:general, name, &body)
32
+ end
33
+
34
+ def modify_simple_feature(name, &body)
35
+ modify_entry(:simple, name, &body)
36
+ end
37
+
38
+ def modify_list_feature(list_name, &body)
39
+ modify_entry(:list, list_name, &body)
40
+ end
41
+
42
+ def modify_list_item_feature(list_name, feature_name, &body)
43
+ list_item_entry(list_name).modify_feature(feature_name, &body)
31
44
  end
32
45
 
33
46
  def enable(list_name = nil, feature_names)
@@ -95,6 +108,20 @@ module RgGen
95
108
  @feature_entries[name] = entry
96
109
  end
97
110
 
111
+ def modify_entry(type, name, &body)
112
+ entry = @feature_entries[name]
113
+ entry&.match_entry_type?(type) ||
114
+ (raise BuilderError.new("unknown feature: #{name}"))
115
+ entry.modify(&body)
116
+ end
117
+
118
+ def list_item_entry(list_name)
119
+ entry = @feature_entries[list_name]
120
+ entry&.match_entry_type?(:list) ||
121
+ (raise BuilderError.new("unknown feature: #{list_name}"))
122
+ entry
123
+ end
124
+
98
125
  def enabled_list_features(list_name)
99
126
  return [] unless enabled_list?(list_name)
100
127
  features = @feature_entries[list_name].features
@@ -10,7 +10,7 @@ module RgGen
10
10
  @feature = Class.new(base_feature)
11
11
  @factory = Class.new(base_factory)
12
12
  attach_shared_context(context, @feature, @factory, self)
13
- block_given? && Docile.dsl_eval(self, @name, &body)
13
+ eval_body(&body)
14
14
  end
15
15
 
16
16
  def define_factory(&body)
@@ -5,30 +5,27 @@ module RgGen
5
5
  module Builder
6
6
  class Layer
7
7
  class Proxy
8
- def initialize
9
- block_given? && yield(self)
8
+ def initialize(list_name, feature_name)
9
+ @list_name = list_name
10
+ @feature_name = feature_name
10
11
  end
11
12
 
12
- attr_setter :body
13
- attr_setter :method_name
14
- attr_setter :list_name
15
- attr_setter :feature_name
13
+ attr_reader :list_name
14
+ attr_reader :feature_name
16
15
 
17
16
  def register_execution(registry, &body)
18
17
  @executions ||= []
19
18
  @executions << { registry: registry, body: body }
20
19
  end
21
20
 
22
- def execute(layer)
21
+ def execute(layer, method_name, &body)
23
22
  Docile.dsl_eval(layer, &body)
24
- @executions&.each { |execution| call_execution(layer, execution) }
25
- end
26
-
27
- private
23
+ return unless @executions
28
24
 
29
- def call_execution(layer, execution)
30
25
  args = [list_name, feature_name, layer.shared_context].compact
31
- execution[:registry].__send__(method_name, *args, &execution[:body])
26
+ @executions.each do |execution|
27
+ execution[:registry].__send__(method_name, *args, &execution[:body])
28
+ end
32
29
  end
33
30
  end
34
31
 
@@ -53,44 +50,55 @@ module RgGen
53
50
  current_shared_context(false)
54
51
  end
55
52
 
53
+ def component_defined?(component_name)
54
+ @feature_registries.key?(component_name)
55
+ end
56
+
56
57
  def define_feature(feature_names, &body)
57
58
  Array(feature_names).each do |feature_name|
58
- do_proxy_call do |proxy|
59
- proxy.body(body)
60
- proxy.method_name(__method__)
61
- proxy.feature_name(feature_name)
62
- end
59
+ do_proxy_call(__method__, nil, feature_name, &body)
60
+ end
61
+ end
62
+
63
+ def modify_feature(feature_names, &body)
64
+ Array(feature_names).each do |feature_name|
65
+ do_proxy_call(__method__, nil, feature_name, &body)
63
66
  end
64
67
  end
65
68
 
66
69
  def define_simple_feature(feature_names, &body)
67
70
  Array(feature_names).each do |feature_name|
68
- do_proxy_call do |proxy|
69
- proxy.body(body)
70
- proxy.method_name(__method__)
71
- proxy.feature_name(feature_name)
72
- end
71
+ do_proxy_call(__method__, nil, feature_name, &body)
72
+ end
73
+ end
74
+
75
+ def modify_simple_feature(feature_names, &body)
76
+ Array(feature_names).each do |feature_name|
77
+ do_proxy_call(__method__, nil, feature_name, &body)
73
78
  end
74
79
  end
75
80
 
76
81
  def define_list_feature(list_names, &body)
77
82
  Array(list_names).each do |list_name|
78
- do_proxy_call do |proxy|
79
- proxy.body(body)
80
- proxy.method_name(__method__)
81
- proxy.list_name(list_name)
82
- end
83
+ do_proxy_call(__method__, list_name, nil, &body)
84
+ end
85
+ end
86
+
87
+ def modify_list_feature(list_names, &body)
88
+ Array(list_names).each do |list_name|
89
+ do_proxy_call(__method__, list_name, nil, &body)
83
90
  end
84
91
  end
85
92
 
86
93
  def define_list_item_feature(list_name, feature_names, &body)
87
94
  Array(feature_names).each do |feature_name|
88
- do_proxy_call do |proxy|
89
- proxy.body(body)
90
- proxy.method_name(__method__)
91
- proxy.list_name(list_name)
92
- proxy.feature_name(feature_name)
93
- end
95
+ do_proxy_call(__method__, list_name, feature_name, &body)
96
+ end
97
+ end
98
+
99
+ def modify_list_item_feature(list_name, feature_names, &body)
100
+ Array(feature_names).each do |feature_name|
101
+ do_proxy_call(__method__, list_name, feature_name, &body)
94
102
  end
95
103
  end
96
104
 
@@ -122,9 +130,9 @@ module RgGen
122
130
  end
123
131
  end
124
132
 
125
- def do_proxy_call(&block)
126
- @proxy = Proxy.new(&block)
127
- @proxy.execute(self)
133
+ def do_proxy_call(method_name, list_name, feature_name, &body)
134
+ @proxy = Proxy.new(list_name, feature_name)
135
+ @proxy.execute(self, method_name, &body)
128
136
  remove_instance_variable(:@proxy)
129
137
  end
130
138
 
@@ -15,7 +15,7 @@ module RgGen
15
15
  @base_feature = Class.new(base_feature)
16
16
  @factory = Class.new(base_factory)
17
17
  attach_shared_context(context, @base_feature, @factory, self)
18
- block_given? && Docile.dsl_eval(self, @name, &body)
18
+ eval_body(&body)
19
19
  end
20
20
 
21
21
  def define_factory(&body)
@@ -31,8 +31,7 @@ module RgGen
31
31
  alias_method :base_feature, :define_base_feature
32
32
 
33
33
  def define_feature(feature_name, context = nil, &body)
34
- @features[feature_name] ||= Class.new(@base_feature)
35
- feature = @features[feature_name]
34
+ feature = @features[feature_name] = Class.new(@base_feature)
36
35
  if context
37
36
  feature.method_defined?(:shared_context) &&
38
37
  (raise BuilderError.new('shared context has already been set'))
@@ -43,6 +42,12 @@ module RgGen
43
42
 
44
43
  alias_method :feature, :define_feature
45
44
 
45
+ def modify_feature(feature_name, &body)
46
+ @features.key?(feature_name) ||
47
+ (raise BuilderError.new("unknown feature: #{feature_name}"))
48
+ body && @features[feature_name].class_exec(feature_name, &body)
49
+ end
50
+
46
51
  def define_default_feature(&body)
47
52
  @default_feature ||= Class.new(@base_feature)
48
53
  body && @default_feature.class_exec(&body)
@@ -5,7 +5,7 @@ module RgGen
5
5
  module Builder
6
6
  class SimpleFeatureEntry < FeatureEntryBase
7
7
  def setup(base_feature, factory, context, &body)
8
- @feature = define_feature(base_feature, context, &body)
8
+ define_feature(base_feature, context, &body)
9
9
  @factory = factory
10
10
  end
11
11
 
@@ -16,15 +16,18 @@ module RgGen
16
16
  end
17
17
 
18
18
  def define_feature(base, context, &body)
19
- feature = Class.new(base)
20
- attach_shared_context(context, feature)
21
- block_given? && feature.class_exec(@name, &body)
22
- feature
19
+ @feature = Class.new(base)
20
+ attach_shared_context(context, @feature)
21
+ eval_body(&body)
23
22
  end
24
23
 
25
24
  def target_feature
26
25
  @feature
27
26
  end
27
+
28
+ def eval_body(&body)
29
+ block_given? && @feature.class_exec(@name, &body)
30
+ end
28
31
  end
29
32
  end
30
33
  end
@@ -18,6 +18,10 @@ module RgGen
18
18
  :define_simple_feature,
19
19
  :define_list_feature,
20
20
  :define_list_item_feature,
21
+ :modify_feature,
22
+ :modify_simple_feature,
23
+ :modify_list_feature,
24
+ :modify_list_item_feature,
21
25
  :define_value_extractor,
22
26
  :enable,
23
27
  :enable_all,
@@ -2,7 +2,6 @@
2
2
 
3
3
  require 'facets/array/merge'
4
4
  require 'facets/file/ext'
5
- require 'facets/hash/except' if RUBY_VERSION < '3.0.0'
6
5
  require 'facets/kernel/blank'
7
6
  require 'facets/pathname/to_path'
8
7
  require 'facets/module/attr_setter'
@@ -9,8 +9,8 @@ module RgGen
9
9
  include ConversionUtility
10
10
 
11
11
  class << self
12
- def property(name, **options, &body)
13
- Property.define(self, name, **options, &body)
12
+ def property(name, ...)
13
+ Property.define(self, name, ...)
14
14
  properties.include?(name) || properties << name
15
15
  end
16
16
 
@@ -49,8 +49,8 @@ module RgGen
49
49
  builders.nil?
50
50
  end
51
51
 
52
- def input_pattern(pattern_or_patterns, **options, &converter)
53
- @input_matcher = InputMatcher.new(pattern_or_patterns, **options, &converter)
52
+ def input_pattern(pattern_or_patterns, ...)
53
+ @input_matcher = InputMatcher.new(pattern_or_patterns, ...)
54
54
  end
55
55
 
56
56
  attr_reader :input_matcher
@@ -87,8 +87,8 @@ module RgGen
87
87
  caller_location.path.include?('docile')
88
88
  end
89
89
 
90
- def create_child_data(layer, *args, &block)
91
- child_data_class.new(layer, @valid_value_lists, *args, &block)
90
+ def create_child_data(layer, ...)
91
+ child_data_class.new(layer, @valid_value_lists, ...)
92
92
  end
93
93
 
94
94
  def child_data_class
@@ -52,7 +52,7 @@ module RgGen
52
52
  /(?<=[[:punct:]&&[^_]])[[:blank:]]+(?=\w)/
53
53
  ).freeze
54
54
 
55
- COMPRESS_BLANK_PATTERN = /[[:blank:]]+/.freeze
55
+ COMPRESS_BLANK_PATTERN = /[[:blank:]]+/
56
56
 
57
57
  def delete_blanks(rhs)
58
58
  rhs
@@ -23,16 +23,16 @@ module RgGen
23
23
 
24
24
  def define(feature)
25
25
  feature.class_exec(self) do |property|
26
- define_method(property.name) do |*args, **keywords, &block|
27
- property.evaluate(self, *args, **keywords, &block)
26
+ define_method(property.name) do |*args, **kwargs, &block|
27
+ property.evaluate(self, *args, **kwargs, &block)
28
28
  end
29
29
  end
30
30
  end
31
31
 
32
- def evaluate(feature, *args, **keywords, &block)
32
+ def evaluate(feature, ...)
33
33
  feature.verify(@options[:verify]) if @options.key?(:verify)
34
34
  if proxy_property?
35
- proxy_property(feature, *args, **keywords, &block)
35
+ proxy_property(feature, ...)
36
36
  else
37
37
  default_property(feature)
38
38
  end
@@ -55,7 +55,7 @@ module RgGen
55
55
  ].any?
56
56
  end
57
57
 
58
- def proxy_property(feature, *args, **keywords, &block)
58
+ def proxy_property(feature, ...)
59
59
  receiver, method =
60
60
  if @costom_property
61
61
  [@costom_property.bind(feature), :call]
@@ -64,7 +64,7 @@ module RgGen
64
64
  else
65
65
  [feature, @options[:forward_to]]
66
66
  end
67
- receiver.__send__(method, *args, **keywords, &block)
67
+ receiver.__send__(method, ...)
68
68
  end
69
69
 
70
70
  def default_property(feature)
@@ -49,10 +49,8 @@ module RgGen
49
49
  end
50
50
 
51
51
  class Visitor < ::Psych::Visitors::ToRuby
52
- if ::Psych::VERSION >= '3.2.0'
53
- def initialize(scalar_scanner, class_loader)
54
- super(scalar_scanner, class_loader, symbolize_names: true)
55
- end
52
+ def initialize(scalar_scanner, class_loader)
53
+ super(scalar_scanner, class_loader, symbolize_names: true)
56
54
  end
57
55
 
58
56
  def accept(node)
@@ -79,7 +77,6 @@ module RgGen
79
77
  def load_yaml(file)
80
78
  parse_yaml(File.binread(file), file)
81
79
  .then { |result| to_ruby(result) }
82
- .then { |result| symbolize_names(result) }
83
80
  end
84
81
 
85
82
  def parse_yaml(yaml, file)
@@ -93,20 +90,6 @@ module RgGen
93
90
  ss = ::Psych::ScalarScanner.new(cl)
94
91
  Visitor.new(ss, cl).accept(result)
95
92
  end
96
-
97
- def symbolize_names(result)
98
- return result if ::Psych::VERSION >= '3.2.0'
99
-
100
- if result.match_class?(Hash)
101
- result
102
- .transform_keys!(&:to_sym)
103
- .transform_values!(&method(:symbolize_names))
104
- elsif result.match_class?(Array)
105
- result.map! { |value| symbolize_names(value) }
106
- end
107
-
108
- result
109
- end
110
93
  end
111
94
  end
112
95
  end
@@ -12,17 +12,17 @@ module RgGen
12
12
 
13
13
  private
14
14
 
15
- VARIABLE_NAME_PATTERN = /[a-z_]\w*/i.freeze
15
+ VARIABLE_NAME_PATTERN = /[a-z_]\w*/i
16
16
 
17
17
  def variable_name
18
18
  VARIABLE_NAME_PATTERN
19
19
  end
20
20
 
21
- BINARY_PATTERN = /[+-]?0b[01](?:_?[01])*/i.freeze
21
+ BINARY_PATTERN = /[+-]?0b[01](?:_?[01])*/i
22
22
 
23
- DECIMAL_PATTERN = /[+-]?(?:[1-9]_?(?:\d_?)*)?\d/.freeze
23
+ DECIMAL_PATTERN = /[+-]?(?:[1-9]_?(?:\d_?)*)?\d/
24
24
 
25
- HEXADECIMAL_PATTERN = /[+-]?0x\h(?:_?\h)*/i.freeze
25
+ HEXADECIMAL_PATTERN = /[+-]?0x\h(?:_?\h)*/i
26
26
 
27
27
  INTEGER_PATTERN =
28
28
  Regexp.union(
@@ -33,13 +33,13 @@ module RgGen
33
33
  INTEGER_PATTERN
34
34
  end
35
35
 
36
- TRUTHY_PATTERN = /true|on|yes/i.freeze
36
+ TRUTHY_PATTERN = /true|on|yes/i
37
37
 
38
38
  def truthy_pattern
39
39
  TRUTHY_PATTERN
40
40
  end
41
41
 
42
- FALSEY_PATTERN = /false|off|no/i.freeze
42
+ FALSEY_PATTERN = /false|off|no/i
43
43
 
44
44
  def falsey_pattern
45
45
  FALSEY_PATTERN
@@ -2,7 +2,7 @@
2
2
 
3
3
  module RgGen
4
4
  module Core
5
- VERSION = '0.31.2'
5
+ VERSION = '0.32.0'
6
6
  MAJOR, MINOR, PATCH = VERSION.split('.').map(&:to_i)
7
7
  end
8
8
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rggen-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.31.2
4
+ version: 0.32.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Taichi Ishitani
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-10-18 00:00:00.000000000 Z
11
+ date: 2023-12-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: docile
@@ -72,20 +72,6 @@ dependencies:
72
72
  - - ">="
73
73
  - !ruby/object:Gem::Version
74
74
  version: '2.0'
75
- - !ruby/object:Gem::Dependency
76
- name: bundler
77
- requirement: !ruby/object:Gem::Requirement
78
- requirements:
79
- - - ">="
80
- - !ruby/object:Gem::Version
81
- version: '0'
82
- type: :development
83
- prerelease: false
84
- version_requirements: !ruby/object:Gem::Requirement
85
- requirements:
86
- - - ">="
87
- - !ruby/object:Gem::Version
88
- version: '0'
89
75
  description: Core library of RgGen tool.
90
76
  email:
91
77
  - rggen@googlegroups.com
@@ -215,15 +201,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
215
201
  requirements:
216
202
  - - ">="
217
203
  - !ruby/object:Gem::Version
218
- version: '2.7'
204
+ version: 3.0.0
219
205
  required_rubygems_version: !ruby/object:Gem::Requirement
220
206
  requirements:
221
207
  - - ">="
222
208
  - !ruby/object:Gem::Version
223
209
  version: '0'
224
210
  requirements: []
225
- rubygems_version: 3.4.19
211
+ rubygems_version: 3.5.3
226
212
  signing_key:
227
213
  specification_version: 4
228
- summary: rggen-core-0.31.2
214
+ summary: rggen-core-0.32.0
229
215
  test_files: []