rggen-core 0.33.1 → 0.34.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +1 -1
  3. data/README.md +1 -1
  4. data/lib/rggen/core/base/component_factory.rb +2 -2
  5. data/lib/rggen/core/base/feature.rb +5 -4
  6. data/lib/rggen/core/base/feature_variable.rb +112 -0
  7. data/lib/rggen/core/base/internal_struct.rb +2 -2
  8. data/lib/rggen/core/builder/builder.rb +5 -4
  9. data/lib/rggen/core/builder/component_registry.rb +6 -6
  10. data/lib/rggen/core/builder/feature_entry_base.rb +4 -4
  11. data/lib/rggen/core/builder/feature_registry.rb +21 -20
  12. data/lib/rggen/core/builder/general_feature_entry.rb +5 -6
  13. data/lib/rggen/core/builder/input_component_registry.rb +2 -2
  14. data/lib/rggen/core/builder/layer.rb +65 -34
  15. data/lib/rggen/core/builder/list_feature_entry.rb +12 -9
  16. data/lib/rggen/core/builder/loader_registry.rb +4 -4
  17. data/lib/rggen/core/builder/plugin_manager.rb +14 -3
  18. data/lib/rggen/core/builder/simple_feature_entry.rb +5 -6
  19. data/lib/rggen/core/configuration/component_factory.rb +2 -2
  20. data/lib/rggen/core/configuration/feature.rb +0 -2
  21. data/lib/rggen/core/configuration/feature_factory.rb +0 -1
  22. data/lib/rggen/core/configuration/input_data.rb +2 -4
  23. data/lib/rggen/core/configuration/loader.rb +0 -1
  24. data/lib/rggen/core/core_extensions/kernel.rb +1 -1
  25. data/lib/rggen/core/core_extensions/object.rb +0 -7
  26. data/lib/rggen/core/dsl.rb +2 -1
  27. data/lib/rggen/core/exceptions.rb +3 -3
  28. data/lib/rggen/core/input_base/component_factory.rb +10 -7
  29. data/lib/rggen/core/input_base/error.rb +1 -1
  30. data/lib/rggen/core/input_base/feature.rb +63 -72
  31. data/lib/rggen/core/input_base/feature_factory.rb +2 -1
  32. data/lib/rggen/core/input_base/input_data.rb +6 -4
  33. data/lib/rggen/core/input_base/input_vaue_parser.rb +2 -12
  34. data/lib/rggen/core/input_base/loader.rb +2 -0
  35. data/lib/rggen/core/input_base/option_hash_parser.rb +1 -1
  36. data/lib/rggen/core/input_base/property.rb +4 -4
  37. data/lib/rggen/core/input_base/verifier.rb +11 -4
  38. data/lib/rggen/core/options.rb +2 -2
  39. data/lib/rggen/core/output_base/code_generatable.rb +77 -0
  40. data/lib/rggen/core/output_base/feature.rb +16 -86
  41. data/lib/rggen/core/register_map/component_factory.rb +2 -4
  42. data/lib/rggen/core/register_map/feature.rb +0 -1
  43. data/lib/rggen/core/register_map/feature_factory.rb +0 -1
  44. data/lib/rggen/core/register_map/input_data.rb +10 -12
  45. data/lib/rggen/core/utility/attribute_setter.rb +13 -10
  46. data/lib/rggen/core/utility/code_utility/source_file.rb +1 -1
  47. data/lib/rggen/core/utility/code_utility.rb +2 -2
  48. data/lib/rggen/core/utility/regexp_patterns.rb +1 -1
  49. data/lib/rggen/core/version.rb +1 -1
  50. data/lib/rggen/core.rb +2 -3
  51. metadata +7 -11
  52. data/lib/rggen/core/configuration/error.rb +0 -20
  53. data/lib/rggen/core/output_base/code_generator.rb +0 -45
  54. data/lib/rggen/core/register_map/error.rb +0 -20
@@ -73,8 +73,15 @@ module RgGen
73
73
  activation && activate_plugins
74
74
  end
75
75
 
76
- def setup_plugin(plugin_name, &block)
77
- @plugins << PluginSpec.new(plugin_name, &block)
76
+ def setup_plugin(plugin_name, &)
77
+ @plugins << PluginSpec.new(plugin_name, &)
78
+ end
79
+
80
+ def update_plugin(plugin_name)
81
+ plugin =
82
+ find_plugin(plugin_name) ||
83
+ (raise PluginError.new("unknown plugin: #{plugin_name}"))
84
+ block_given? && yield(plugin)
78
85
  end
79
86
 
80
87
  def activate_plugins
@@ -83,7 +90,7 @@ module RgGen
83
90
  end
84
91
 
85
92
  def activate_plugin_by_name(plugin_name)
86
- @plugins.find { |plugin| plugin.name == plugin_name }
93
+ find_plugin(plugin_name)
87
94
  &.then do |plugin|
88
95
  plugin.activate(@builder)
89
96
  plugin.activate_additionally(@builder)
@@ -103,6 +110,10 @@ module RgGen
103
110
  raise Core::PluginError.new("cannot load such plugin: #{info}")
104
111
  end
105
112
 
113
+ def find_plugin(plugin_name)
114
+ @plugins.find { |plugin| plugin.name == plugin_name }
115
+ end
116
+
106
117
  def activate_plugin_gem(info)
107
118
  if (gemspec = find_gemspec(info))
108
119
  gem gemspec.name, gemspec.version
@@ -4,8 +4,8 @@ module RgGen
4
4
  module Core
5
5
  module Builder
6
6
  class SimpleFeatureEntry < FeatureEntryBase
7
- def setup(base_feature, factory, context, &body)
8
- define_feature(base_feature, context, &body)
7
+ def setup(base_feature, factory, context)
8
+ define_feature(base_feature, context)
9
9
  @factory = factory
10
10
  end
11
11
 
@@ -15,18 +15,17 @@ module RgGen
15
15
  :simple
16
16
  end
17
17
 
18
- def define_feature(base, context, &body)
18
+ def define_feature(base, context)
19
19
  @feature = Class.new(base)
20
20
  attach_shared_context(context, @feature)
21
- eval_body(&body)
22
21
  end
23
22
 
24
23
  def target_feature
25
24
  @feature
26
25
  end
27
26
 
28
- def eval_body(&body)
29
- block_given? && @feature.class_exec(@name, &body)
27
+ def eval_body(&)
28
+ block_given? && @feature.class_exec(@name, &)
30
29
  end
31
30
  end
32
31
  end
@@ -6,8 +6,8 @@ module RgGen
6
6
  class ComponentFactory < InputBase::ComponentFactory
7
7
  private
8
8
 
9
- def create_input_data(*_args, &block)
10
- InputData.new(valid_value_lists, &block)
9
+ def create_input_data(*_args, &)
10
+ InputData.new(valid_value_lists, &)
11
11
  end
12
12
  end
13
13
  end
@@ -4,8 +4,6 @@ module RgGen
4
4
  module Core
5
5
  module Configuration
6
6
  class Feature < InputBase::Feature
7
- include RaiseError
8
-
9
7
  alias_method :configuration, :component
10
8
  end
11
9
  end
@@ -4,7 +4,6 @@ module RgGen
4
4
  module Core
5
5
  module Configuration
6
6
  class FeatureFactory < InputBase::FeatureFactory
7
- include RaiseError
8
7
  end
9
8
  end
10
9
  end
@@ -4,10 +4,8 @@ module RgGen
4
4
  module Core
5
5
  module Configuration
6
6
  class InputData < InputBase::InputData
7
- include RaiseError
8
-
9
- def initialize(valid_value_lists, &block)
10
- super(nil, valid_value_lists, &block)
7
+ def initialize(valid_value_lists, &)
8
+ super(nil, valid_value_lists, &)
11
9
  end
12
10
 
13
11
  undef_method :child
@@ -4,7 +4,6 @@ module RgGen
4
4
  module Core
5
5
  module Configuration
6
6
  class Loader < InputBase::Loader
7
- include RaiseError
8
7
  end
9
8
  end
10
9
  end
@@ -5,7 +5,7 @@ module Kernel
5
5
 
6
6
  def Integer(arg, base = 0, exception: true)
7
7
  arg = arg.__getobj__ if arg.is_a?(::Delegator)
8
- __orignal_Integer(arg, base, exception: exception)
8
+ __orignal_Integer(arg, base, exception:)
9
9
  end
10
10
 
11
11
  module_function :__orignal_Integer
@@ -1,13 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Object
4
- def export_instance_variable(variable, to)
5
- instance_variable_defined?(variable) &&
6
- instance_variable_get(variable)
7
- .then { |v| block_given? ? yield(v) : v }
8
- .then { |v| to.instance_variable_set(variable, v) }
9
- end
10
-
11
4
  def singleton_exec(...)
12
5
  singleton_class.class_exec(...)
13
6
  end
@@ -26,7 +26,8 @@ module RgGen
26
26
  :enable,
27
27
  :enable_all,
28
28
  :delete,
29
- :setup_plugin
29
+ :setup_plugin,
30
+ :update_plugin
30
31
  ].each do |method_name|
31
32
  def_delegator :'RgGen.builder', method_name
32
33
  end
@@ -25,13 +25,13 @@ module RgGen
25
25
  class PluginError < RgGenError
26
26
  end
27
27
 
28
- class RuntimeError < RgGenError
28
+ class LoadError < RgGenError
29
29
  end
30
30
 
31
- class LoadError < Core::RuntimeError
31
+ class SourceError < RgGenError
32
32
  end
33
33
 
34
- class GeneratorError < Core::RuntimeError
34
+ class GeneratorError < RgGenError
35
35
  end
36
36
  end
37
37
  end
@@ -4,6 +4,8 @@ module RgGen
4
4
  module Core
5
5
  module InputBase
6
6
  class ComponentFactory < Base::ComponentFactory
7
+ include RaiseError
8
+
7
9
  class << self
8
10
  def enable_no_children_error
9
11
  @enable_no_children_error = true
@@ -51,23 +53,24 @@ module RgGen
51
53
  .transform_values(&->(f) { f.valid_value_list })
52
54
  end
53
55
 
54
- def create_input_data(*_args, &block)
56
+ def create_input_data(*_args, &)
55
57
  end
56
58
 
57
59
  def create_features(component, *sources)
58
- create_active_features(component, sources.last)
59
- create_passive_features(component)
60
+ create_active_features(component, sources)
61
+ create_passive_features(component, sources)
60
62
  end
61
63
 
62
- def create_active_features(component, input_data)
64
+ def create_active_features(component, sources)
63
65
  active_feature_factories.each do |name, factory|
64
- create_feature(component, factory, input_data[name])
66
+ input_data = sources.last[name]
67
+ create_feature(component, factory, *sources[0..-2], input_data)
65
68
  end
66
69
  end
67
70
 
68
- def create_passive_features(component)
71
+ def create_passive_features(component, sources)
69
72
  passive_feature_factories.each_value do |factory|
70
- create_feature(component, factory)
73
+ create_feature(component, factory, *sources[0..-2])
71
74
  end
72
75
  end
73
76
 
@@ -18,7 +18,7 @@ module RgGen
18
18
 
19
19
  def error(message, position = nil)
20
20
  pos = extract_error_position(position)
21
- raise error_exception.new(message, pos)
21
+ raise SourceError.new(message, pos)
22
22
  end
23
23
 
24
24
  def extract_error_position(position)
@@ -6,102 +6,85 @@ module RgGen
6
6
  class Feature < Base::Feature
7
7
  include Utility::RegexpPatterns
8
8
  include Utility::TypeChecker
9
+ include RaiseError
9
10
  include ConversionUtility
10
11
 
11
12
  class << self
12
- def property(name, ...)
13
- Property.define(self, name, ...)
14
- properties.include?(name) || properties << name
15
- end
16
-
17
- alias_method :field, :property
18
-
19
13
  def properties
20
- @properties ||= []
14
+ feature_array_variable_get(:@properties)
21
15
  end
22
16
 
23
- def ignore_empty_value(value = nil)
24
- @ignore_empty_value = value unless value.nil?
25
- @ignore_empty_value
17
+ def active_feature?
18
+ !passive_feature?
26
19
  end
27
20
 
28
- def ignore_empty_value?
29
- @ignore_empty_value.nil? || @ignore_empty_value
21
+ def passive_feature?
22
+ feature_array_variable_get(:@builders).nil?
30
23
  end
31
24
 
32
- def build(&block)
33
- (@builders ||= []) << block
25
+ private
26
+
27
+ def property(name, ...)
28
+ Property.define(self, name, ...)
29
+ properties&.include?(name) ||
30
+ feature_array_variable_push(:@properties, name)
34
31
  end
35
32
 
36
- attr_reader :builders
33
+ alias_method :field, :property
37
34
 
38
- def post_build(&block)
39
- (@post_builders ||= []) << block
35
+ def ignore_empty_value(value)
36
+ @ignore_empty_value = value
40
37
  end
41
38
 
42
- attr_reader :post_builders
43
-
44
- def active_feature?
45
- !passive_feature?
39
+ def build(&block)
40
+ feature_array_variable_push(:@builders, block)
46
41
  end
47
42
 
48
- def passive_feature?
49
- builders.nil?
43
+ def post_build(&block)
44
+ feature_array_variable_push(:@post_builders, block)
50
45
  end
51
46
 
52
47
  def input_pattern(pattern_or_patterns, ...)
53
48
  @input_matcher = InputMatcher.new(pattern_or_patterns, ...)
54
49
  end
55
50
 
56
- attr_reader :input_matcher
57
-
58
- def verify(scope, &block)
59
- @verifiers ||= {}
60
- (@verifiers[scope] ||= []) << create_verifier(&block)
61
- end
62
-
63
- attr_reader :verifiers
64
-
65
- def printable(name, &body)
66
- (@printables ||= {})[name] = body
51
+ def verify(scope, prepend: false, &)
52
+ verifyier = create_verifier(&)
53
+ if prepend
54
+ feature_hash_array_variable_prepend(:@verifiers, scope, verifyier)
55
+ else
56
+ feature_hash_array_variable_push(:@verifiers, scope, verifyier)
57
+ end
67
58
  end
68
59
 
69
- attr_reader :printables
70
-
71
- def inherited(subclass)
72
- super
73
- export_instance_variable(:@properties, subclass, &:dup)
74
- export_instance_variable(:@ignore_empty_value, subclass)
75
- export_instance_variable(:@builders, subclass, &:dup)
76
- export_instance_variable(:@post_builders, subclass, &:dup)
77
- export_instance_variable(:@input_matcher, subclass)
78
- export_instance_variable(:@printables, subclass, &:dup)
79
- export_verifiers(subclass) if @verifiers
60
+ def create_verifier(&)
61
+ Verifier.new(&)
80
62
  end
81
63
 
82
- private
83
-
84
- def create_verifier(&body)
85
- Verifier.new(&body)
86
- end
87
-
88
- def export_verifiers(subclass)
89
- subclass
90
- .instance_variable_set(:@verifiers, @verifiers.transform_values(&:dup))
64
+ def printable(name, &body)
65
+ feature_hash_variable_store(:@printables, name, body)
91
66
  end
92
67
  end
93
68
 
94
- def_delegator :'self.class', :properties
95
- def_delegator :'self.class', :active_feature?
96
- def_delegator :'self.class', :passive_feature?
97
- def_delegator :'self.class', :ignore_empty_value?
69
+ def properties
70
+ feature_array_variable_get(:@properties)
71
+ end
98
72
 
99
73
  def build(*args)
100
- self.class.builders && do_build(args)
74
+ builders = feature_array_variable_get(:@builders)
75
+ return unless builders
76
+
77
+ do_build(builders, args)
101
78
  end
102
79
 
103
80
  def post_build
104
- self.class.post_builders&.each { |block| instance_exec(&block) }
81
+ feature_array_variable_get(:@post_builders)
82
+ &.each { |block| instance_exec(&block) }
83
+ end
84
+
85
+ def ignore_empty_value?
86
+ feaure_scala_variable_get(:@ignore_empty_value)
87
+ .then { _1.nil? || _1 }
105
88
  end
106
89
 
107
90
  def verify(scope)
@@ -109,11 +92,12 @@ module RgGen
109
92
  end
110
93
 
111
94
  def printables
112
- helper.printables&.map { |name, body| [name, printable(name, &body)] }
95
+ feature_hash_variable_get(:@printables)
96
+ &.map { |name, body| [name, printable(name, &body)] }
113
97
  end
114
98
 
115
99
  def printable?
116
- !helper.printables.nil?
100
+ !feature_hash_variable_get(:@printables).nil?
117
101
  end
118
102
 
119
103
  def inspect
@@ -135,23 +119,27 @@ module RgGen
135
119
 
136
120
  private
137
121
 
138
- def do_build(args)
122
+ def do_build(builders, args)
139
123
  @position = args.last.position
140
124
  match_automatically? && match_pattern(args.last)
141
- execute_build_blocks(args)
125
+ execute_build_blocks(builders, args)
142
126
  end
143
127
 
144
- def execute_build_blocks(args)
128
+ def execute_build_blocks(builders, args)
145
129
  args = [*args, args.last.options] if args.last.with_options?
146
- self.class.builders.each { |builder| instance_exec(*args, &builder) }
130
+ builders.each { |builder| instance_exec(*args, &builder) }
131
+ end
132
+
133
+ def input_matcher
134
+ feaure_scala_variable_get(:@input_matcher)
147
135
  end
148
136
 
149
137
  def match_automatically?
150
- self.class.input_matcher&.match_automatically?
138
+ input_matcher&.match_automatically?
151
139
  end
152
140
 
153
141
  def match_pattern(rhs)
154
- @match_data, @match_index = self.class.input_matcher&.match(rhs)
142
+ @match_data, @match_index = input_matcher&.match(rhs)
155
143
  end
156
144
 
157
145
  attr_reader :match_data
@@ -166,12 +154,15 @@ module RgGen
166
154
  end
167
155
 
168
156
  def do_verify(scope)
169
- self.class.verifiers&.[](scope)&.each { |verifier| verifier.verify(self) }
157
+ verifiers = feature_hash_array_variable_get(:@verifiers)
158
+ return unless verifiers
159
+
160
+ verifiers[scope]&.each { |verifier| verifier.verify(self) }
170
161
  (@verified ||= {})[scope] = true
171
162
  end
172
163
 
173
- def printable(name, &body)
174
- block_given? ? instance_exec(&body) : __send__(name)
164
+ def printable(name, &)
165
+ block_given? ? instance_exec(&) : __send__(name)
175
166
  end
176
167
  end
177
168
  end
@@ -5,6 +5,7 @@ module RgGen
5
5
  module InputBase
6
6
  class FeatureFactory < Base::FeatureFactory
7
7
  include Utility::TypeChecker
8
+ include RaiseError
8
9
 
9
10
  class << self
10
11
  def convert_value(&block)
@@ -66,7 +67,7 @@ module RgGen
66
67
 
67
68
  def parse_input_value(input_value, value_format)
68
69
  format, options = value_format
69
- VALUE_PARSERS[format].new(error_exception, **options).parse(input_value)
70
+ VALUE_PARSERS[format].new(**options).parse(input_value)
70
71
  end
71
72
 
72
73
  def override_input_value(input_value, parsed_value, options)
@@ -4,6 +4,8 @@ module RgGen
4
4
  module Core
5
5
  module InputBase
6
6
  class InputData
7
+ include RaiseError
8
+
7
9
  def initialize(layer, valid_value_lists, *_args)
8
10
  @layer = layer
9
11
  @valid_value_lists = valid_value_lists
@@ -37,9 +39,9 @@ module RgGen
37
39
 
38
40
  attr_reader :children
39
41
 
40
- def child(layer, value_list = nil, &block)
42
+ def child(layer, value_list = nil, &)
41
43
  create_child_data(layer) do |child_data|
42
- child_data.build_by_block(&block)
44
+ child_data.build_by_block(&)
43
45
  child_data.values(value_list)
44
46
  @children << child_data
45
47
  end
@@ -98,8 +100,8 @@ module RgGen
98
100
 
99
101
  protected
100
102
 
101
- def build_by_block(&block)
102
- block_given? && Docile.dsl_eval(self, &block)
103
+ def build_by_block(&)
104
+ block_given? && Docile.dsl_eval(self, &)
103
105
  end
104
106
  end
105
107
  end
@@ -5,9 +5,9 @@ module RgGen
5
5
  module InputBase
6
6
  class InputValueParser
7
7
  include Utility::TypeChecker
8
+ include RaiseError
8
9
 
9
- def initialize(exception, **_option)
10
- @exception = exception
10
+ def initialize(**_options)
11
11
  end
12
12
 
13
13
  private
@@ -15,16 +15,6 @@ module RgGen
15
15
  def split_string(string, separator, limit)
16
16
  string&.split(separator, limit)&.map(&:strip)
17
17
  end
18
-
19
- def error(message, position_or_input_value = nil)
20
- position =
21
- if position_or_input_value.respond_to?(:position)
22
- position_or_input_value.position
23
- else
24
- position_or_input_value
25
- end
26
- raise @exception.new(message, position)
27
- end
28
18
  end
29
19
  end
30
20
  end
@@ -4,6 +4,8 @@ module RgGen
4
4
  module Core
5
5
  module InputBase
6
6
  class Loader
7
+ include RaiseError
8
+
7
9
  def self.support_types(types = nil)
8
10
  types && (@support_types ||= []).concat(types.map(&:to_sym))
9
11
  @support_types
@@ -4,7 +4,7 @@ module RgGen
4
4
  module Core
5
5
  module InputBase
6
6
  class OptionHashParser < InputValueParser
7
- def initialize(exception, allowed_options: nil, multiple_values: false)
7
+ def initialize(allowed_options: nil, multiple_values: false)
8
8
  super
9
9
  @allowed_options = allowed_options
10
10
  @multiple_values = multiple_values
@@ -4,18 +4,18 @@ module RgGen
4
4
  module Core
5
5
  module InputBase
6
6
  class Property
7
- def self.define(feature, name, **options, &body)
8
- new(name, options, &body).define(feature)
7
+ def self.define(feature, name, **options, &)
8
+ new(name, options, &).define(feature)
9
9
  end
10
10
 
11
- def initialize(name, options, &body)
11
+ def initialize(name, options, &)
12
12
  @name = name
13
13
  @options = options
14
14
  @costom_property =
15
15
  if options[:body]
16
16
  create_costom_property(&options[:body])
17
17
  elsif block_given?
18
- create_costom_property(&body)
18
+ create_costom_property(&)
19
19
  end
20
20
  end
21
21
 
@@ -4,8 +4,8 @@ module RgGen
4
4
  module Core
5
5
  module InputBase
6
6
  class Verifier
7
- def initialize(&block)
8
- instance_eval(&block)
7
+ def initialize(&)
8
+ instance_eval(&)
9
9
  end
10
10
 
11
11
  def check_error(&block)
@@ -20,6 +20,10 @@ module RgGen
20
20
  @message = block
21
21
  end
22
22
 
23
+ def position(&block)
24
+ @position = block
25
+ end
26
+
23
27
  def verify(feature, *values)
24
28
  if @error_checker
25
29
  feature.instance_exec(*values, &@error_checker)
@@ -31,8 +35,11 @@ module RgGen
31
35
  private
32
36
 
33
37
  def default_error_check(feature, values)
34
- feature.instance_exec(*values, &@condition) &&
35
- feature.__send__(:error, feature.instance_exec(*values, &@message))
38
+ return unless feature.instance_exec(*values, &@condition)
39
+
40
+ message = feature.instance_exec(*values, &@message)
41
+ position = @position && feature.instance_exec(*values, &@position)
42
+ feature.__send__(:error, message, position)
36
43
  end
37
44
  end
38
45
  end
@@ -67,8 +67,8 @@ module RgGen
67
67
  @options ||= {}
68
68
  end
69
69
 
70
- def self.add_option(option_name, &body)
71
- options[option_name] = Option.new(option_name, &body)
70
+ def self.add_option(option_name, &)
71
+ options[option_name] = Option.new(option_name, &)
72
72
  end
73
73
 
74
74
  def initialize