rggen-core 0.24.0 → 0.25.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 +4 -4
- data/lib/rggen/core.rb +2 -1
- data/lib/rggen/core/base/component.rb +5 -6
- data/lib/rggen/core/base/component_factory.rb +8 -5
- data/lib/rggen/core/builder/builder.rb +6 -8
- data/lib/rggen/core/builder/feature_registry.rb +11 -8
- data/lib/rggen/core/builder/list_feature_entry.rb +5 -9
- data/lib/rggen/core/builder/loader_registry.rb +1 -2
- data/lib/rggen/core/builder/simple_feature_entry.rb +4 -4
- data/lib/rggen/core/core_extensions/object.rb +4 -4
- data/lib/rggen/core/facets.rb +1 -0
- data/lib/rggen/core/input_base/component.rb +12 -0
- data/lib/rggen/core/input_base/component_factory.rb +1 -0
- data/lib/rggen/core/input_base/feature.rb +20 -6
- data/lib/rggen/core/input_base/input_data.rb +17 -14
- data/lib/rggen/core/input_base/input_matcher.rb +5 -5
- data/lib/rggen/core/input_base/loader.rb +15 -15
- data/lib/rggen/core/input_base/property.rb +17 -11
- data/lib/rggen/core/input_base/yaml_loader.rb +1 -22
- data/lib/rggen/core/output_base/code_generator.rb +4 -5
- data/lib/rggen/core/output_base/document_component_factory.rb +10 -0
- data/lib/rggen/core/output_base/feature.rb +15 -11
- data/lib/rggen/core/output_base/file_writer.rb +1 -1
- data/lib/rggen/core/output_base/source_file_component_factory.rb +15 -0
- data/lib/rggen/core/output_base/template_engine.rb +4 -5
- data/lib/rggen/core/register_map/hash_loader.rb +6 -9
- data/lib/rggen/core/utility/code_utility/code_block.rb +11 -5
- data/lib/rggen/core/version.rb +1 -1
- metadata +6 -5
- data/lib/rggen/core/base/proxy_call.rb +0 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 57e33c7b563198efa0e1d2c20adcb0b6896d72d4575673c9f64761aeca93779a
|
4
|
+
data.tar.gz: 61e593cab9704bdc330a3767791afc9e6373020809777c7cd4f67ac18adb7b92
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 40b23ff5bd0eca3b9a53cda4cb37a220bd8e7a5648bfce598c1404031bfb43421eda997eb8a7c37868e31418a54c7267d336f72631d29522106c20dc3752433a
|
7
|
+
data.tar.gz: 6918ad93d019dd22e4af13205eb5c8529b1ae8b7c71cd50352b183ae84d3c5a54682189e606859adcd7e70cd292f42d11b8621997cff95ac2e89e2b47f876d1f
|
data/lib/rggen/core.rb
CHANGED
@@ -27,7 +27,6 @@ require_relative 'core/utility/regexp_patterns'
|
|
27
27
|
|
28
28
|
require_relative 'core/exceptions'
|
29
29
|
|
30
|
-
require_relative 'core/base/proxy_call'
|
31
30
|
require_relative 'core/base/internal_struct'
|
32
31
|
require_relative 'core/base/shared_context'
|
33
32
|
require_relative 'core/base/component'
|
@@ -87,6 +86,8 @@ require_relative 'core/output_base/file_writer'
|
|
87
86
|
require_relative 'core/output_base/raise_error'
|
88
87
|
require_relative 'core/output_base/component'
|
89
88
|
require_relative 'core/output_base/component_factory'
|
89
|
+
require_relative 'core/output_base/source_file_component_factory'
|
90
|
+
require_relative 'core/output_base/document_component_factory'
|
90
91
|
require_relative 'core/output_base/feature'
|
91
92
|
require_relative 'core/output_base/feature_factory'
|
92
93
|
|
@@ -70,15 +70,14 @@ module RgGen
|
|
70
70
|
|
71
71
|
def define_proxy_calls(receiver, methods)
|
72
72
|
Array(methods)
|
73
|
-
.map(&:to_sym)
|
74
73
|
.each { |method| define_proxy_call(receiver, method) }
|
75
74
|
end
|
76
75
|
|
77
|
-
def define_proxy_call(receiver,
|
78
|
-
@
|
79
|
-
|
80
|
-
|
81
|
-
@
|
76
|
+
def define_proxy_call(receiver, method_name)
|
77
|
+
(@proxy_receivers ||= {})[method_name.to_sym] = receiver
|
78
|
+
define_singleton_method(method_name) do |*args, &block|
|
79
|
+
name = __method__
|
80
|
+
@proxy_receivers[name].__send__(name, *args, &block)
|
82
81
|
end
|
83
82
|
end
|
84
83
|
end
|
@@ -43,11 +43,15 @@ module RgGen
|
|
43
43
|
|
44
44
|
def create_component(parent, sources, &block)
|
45
45
|
actual_sources = Array(select_actual_sources(*sources))
|
46
|
-
|
47
|
-
.new(parent, component_name, layer, *actual_sources, &block)
|
46
|
+
create_component?(*actual_sources) &&
|
47
|
+
@target_component.new(parent, component_name, layer, *actual_sources, &block)
|
48
48
|
end
|
49
49
|
|
50
|
-
def select_actual_sources(*
|
50
|
+
def select_actual_sources(*_sources)
|
51
|
+
end
|
52
|
+
|
53
|
+
def create_component?(*_sources)
|
54
|
+
true
|
51
55
|
end
|
52
56
|
|
53
57
|
def build_component(parent, component, sources)
|
@@ -88,8 +92,7 @@ module RgGen
|
|
88
92
|
end
|
89
93
|
|
90
94
|
def create_child(component, *args)
|
91
|
-
|
92
|
-
factory.create(component, *args)
|
95
|
+
find_child_factory(*args).create(component, *args)
|
93
96
|
end
|
94
97
|
end
|
95
98
|
end
|
@@ -43,9 +43,8 @@ module RgGen
|
|
43
43
|
else
|
44
44
|
@layers.values
|
45
45
|
end
|
46
|
-
target_layers
|
47
|
-
layer.add_feature_registry(name, registry)
|
48
|
-
end
|
46
|
+
target_layers
|
47
|
+
.each { |layer| layer.add_feature_registry(name, registry) }
|
49
48
|
end
|
50
49
|
|
51
50
|
[
|
@@ -79,8 +78,7 @@ module RgGen
|
|
79
78
|
if targets.empty?
|
80
79
|
@component_registries[type]
|
81
80
|
else
|
82
|
-
@component_registries[type]
|
83
|
-
.select { |name, _| targets.include?(name) }
|
81
|
+
@component_registries[type].slice(*targets)
|
84
82
|
end
|
85
83
|
registries.each_value.map(&:build_factory)
|
86
84
|
end
|
@@ -130,9 +128,9 @@ module RgGen
|
|
130
128
|
|
131
129
|
def component_registry(type, name, &body)
|
132
130
|
registries = @component_registries[type]
|
133
|
-
|
134
|
-
|
135
|
-
|
131
|
+
registries.key?(name) ||
|
132
|
+
(registries[name] = COMPONENT_REGISTRIES[type].new(name, self))
|
133
|
+
body && Docile.dsl_eval(registries[name], &body) || registries[name]
|
136
134
|
end
|
137
135
|
end
|
138
136
|
end
|
@@ -12,11 +12,11 @@ module RgGen
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def define_simple_feature(name, context = nil, &body)
|
15
|
-
create_new_entry(:simple, name, context, body)
|
15
|
+
create_new_entry(:simple, name, context, &body)
|
16
16
|
end
|
17
17
|
|
18
18
|
def define_list_feature(list_name, context = nil, &body)
|
19
|
-
create_new_entry(:list, list_name, context, body)
|
19
|
+
create_new_entry(:list, list_name, context, &body)
|
20
20
|
end
|
21
21
|
|
22
22
|
def define_list_item_feature(list_name, feature_name, context = nil, &body)
|
@@ -88,10 +88,9 @@ module RgGen
|
|
88
88
|
end
|
89
89
|
|
90
90
|
def build_factories
|
91
|
-
@
|
92
|
-
.
|
93
|
-
.
|
94
|
-
.to_h
|
91
|
+
@feature_entries
|
92
|
+
.slice(*@enabled_features.keys)
|
93
|
+
.transform_values(&method(:build_factory))
|
95
94
|
end
|
96
95
|
|
97
96
|
private
|
@@ -100,9 +99,9 @@ module RgGen
|
|
100
99
|
simple: SimpleFeatureEntry, list: ListFeatureEntry
|
101
100
|
}.freeze
|
102
101
|
|
103
|
-
def create_new_entry(type, name, context, body)
|
102
|
+
def create_new_entry(type, name, context, &body)
|
104
103
|
entry = FEATURE_ENTRIES[type].new(self, name)
|
105
|
-
entry.setup(@base_feature, @factory, context, body)
|
104
|
+
entry.setup(@base_feature, @factory, context, &body)
|
106
105
|
@feature_entries[name] = entry
|
107
106
|
end
|
108
107
|
|
@@ -117,6 +116,10 @@ module RgGen
|
|
117
116
|
.feature?(feature_name)
|
118
117
|
@enabled_features[list_name].include?(feature_name)
|
119
118
|
end
|
119
|
+
|
120
|
+
def build_factory(entry)
|
121
|
+
entry.build_factory(@enabled_features[entry.name])
|
122
|
+
end
|
120
123
|
end
|
121
124
|
end
|
122
125
|
end
|
@@ -15,11 +15,11 @@ module RgGen
|
|
15
15
|
attr_reader :registry
|
16
16
|
attr_reader :name
|
17
17
|
|
18
|
-
def setup(base_feature, base_factory, context, body)
|
18
|
+
def setup(base_feature, base_factory, context, &body)
|
19
19
|
@base_feature = Class.new(base_feature)
|
20
20
|
@factory = Class.new(base_factory)
|
21
21
|
context && attach_shared_context(context)
|
22
|
-
|
22
|
+
block_given? && Docile.dsl_eval(self, @name, &body)
|
23
23
|
end
|
24
24
|
|
25
25
|
def match_entry_type?(entry_type)
|
@@ -49,9 +49,8 @@ module RgGen
|
|
49
49
|
@features[feature_name] ||= Class.new(@base_feature)
|
50
50
|
feature = @features[feature_name]
|
51
51
|
if context
|
52
|
-
feature.method_defined?(:shared_context) &&
|
53
|
-
raise BuilderError.new('shared context has already been set')
|
54
|
-
)
|
52
|
+
feature.method_defined?(:shared_context) &&
|
53
|
+
(raise BuilderError.new('shared context has already been set'))
|
55
54
|
feature.attach_context(context)
|
56
55
|
end
|
57
56
|
body && feature.class_exec(feature_name, &body)
|
@@ -87,10 +86,7 @@ module RgGen
|
|
87
86
|
end
|
88
87
|
|
89
88
|
def target_features(enabled_features)
|
90
|
-
enabled_features
|
91
|
-
.select { |n| @features.key?(n) }
|
92
|
-
.map { |n| [n, @features[n]] }
|
93
|
-
.to_h
|
89
|
+
@features.slice(*enabled_features)
|
94
90
|
end
|
95
91
|
end
|
96
92
|
end
|
@@ -12,8 +12,8 @@ module RgGen
|
|
12
12
|
attr_reader :registry
|
13
13
|
attr_reader :name
|
14
14
|
|
15
|
-
def setup(base_feature, factory, context, body)
|
16
|
-
@feature = define_feature(base_feature, context, body)
|
15
|
+
def setup(base_feature, factory, context, &body)
|
16
|
+
@feature = define_feature(base_feature, context, &body)
|
17
17
|
@factory = factory
|
18
18
|
end
|
19
19
|
|
@@ -27,10 +27,10 @@ module RgGen
|
|
27
27
|
|
28
28
|
private
|
29
29
|
|
30
|
-
def define_feature(base, context, body)
|
30
|
+
def define_feature(base, context, &body)
|
31
31
|
feature = Class.new(base)
|
32
32
|
context && feature.attach_context(context)
|
33
|
-
|
33
|
+
block_given? && feature.class_exec(@name, &body)
|
34
34
|
feature
|
35
35
|
end
|
36
36
|
end
|
@@ -2,10 +2,10 @@
|
|
2
2
|
|
3
3
|
class Object
|
4
4
|
def export_instance_variable(variable, to)
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
instance_variable_defined?(variable) &&
|
6
|
+
instance_variable_get(variable)
|
7
|
+
.yield_self { |v| block_given? ? yield(v) : v }
|
8
|
+
.yield_self { |v| to.instance_variable_set(variable, v) }
|
9
9
|
end
|
10
10
|
|
11
11
|
def singleton_exec(*args, &block)
|
data/lib/rggen/core/facets.rb
CHANGED
@@ -9,10 +9,22 @@ module RgGen
|
|
9
9
|
define_proxy_calls(feature, feature.properties)
|
10
10
|
end
|
11
11
|
|
12
|
+
def document_only
|
13
|
+
@document_only = true
|
14
|
+
end
|
15
|
+
|
16
|
+
def document_only?
|
17
|
+
instance_variable_defined?(:@document_only) && @document_only
|
18
|
+
end
|
19
|
+
|
12
20
|
def properties
|
13
21
|
features.flat_map(&:properties)
|
14
22
|
end
|
15
23
|
|
24
|
+
def post_build
|
25
|
+
features.each(&:post_build)
|
26
|
+
end
|
27
|
+
|
16
28
|
def verify(scope)
|
17
29
|
features.each { |feature| feature.verify(scope) }
|
18
30
|
children.each { |child| child.verify(scope) } if scope == :all
|
@@ -34,6 +34,13 @@ module RgGen
|
|
34
34
|
|
35
35
|
attr_reader :builders
|
36
36
|
|
37
|
+
def post_build(&block)
|
38
|
+
@post_builders ||= []
|
39
|
+
@post_builders << block
|
40
|
+
end
|
41
|
+
|
42
|
+
attr_reader :post_builders
|
43
|
+
|
37
44
|
def active_feature?
|
38
45
|
!passive_feature?
|
39
46
|
end
|
@@ -68,6 +75,7 @@ module RgGen
|
|
68
75
|
export_instance_variable(:@properties, subclass, &:dup)
|
69
76
|
export_instance_variable(:@ignore_empty_value, subclass)
|
70
77
|
export_instance_variable(:@builders, subclass, &:dup)
|
78
|
+
export_instance_variable(:@post_builders, subclass, &:dup)
|
71
79
|
export_instance_variable(:@input_matcher, subclass)
|
72
80
|
export_instance_variable(:@printables, subclass, &:dup)
|
73
81
|
export_verifiers(subclass) if @verifiers
|
@@ -95,6 +103,12 @@ module RgGen
|
|
95
103
|
self.class.builders && do_build(args)
|
96
104
|
end
|
97
105
|
|
106
|
+
def post_build
|
107
|
+
self.class.post_builders&.each do |post_builder|
|
108
|
+
instance_exec(&post_builder)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
98
112
|
def verify(scope)
|
99
113
|
verified?(scope) || do_verify(scope)
|
100
114
|
end
|
@@ -102,7 +116,7 @@ module RgGen
|
|
102
116
|
def printables
|
103
117
|
helper
|
104
118
|
.printables
|
105
|
-
&.map { |name, body| [name, printable(name, body)] }
|
119
|
+
&.map { |name, body| [name, printable(name, &body)] }
|
106
120
|
end
|
107
121
|
|
108
122
|
def printable?
|
@@ -119,10 +133,10 @@ module RgGen
|
|
119
133
|
|
120
134
|
def do_build(args)
|
121
135
|
@position = args.last.position
|
122
|
-
|
123
|
-
match_automatically? && match_pattern(
|
136
|
+
value = args.last.value
|
137
|
+
match_automatically? && match_pattern(value)
|
124
138
|
Array(self.class.builders)
|
125
|
-
.each { |builder| instance_exec(*args, &builder) }
|
139
|
+
.each { |builder| instance_exec(*args[0..-2], value, &builder) }
|
126
140
|
end
|
127
141
|
|
128
142
|
attr_reader :position
|
@@ -154,8 +168,8 @@ module RgGen
|
|
154
168
|
(@verified ||= {})[scope] = true
|
155
169
|
end
|
156
170
|
|
157
|
-
def printable(name, body)
|
158
|
-
|
171
|
+
def printable(name, &body)
|
172
|
+
block_given? ? instance_exec(&body) : __send__(name)
|
159
173
|
end
|
160
174
|
end
|
161
175
|
end
|
@@ -17,14 +17,8 @@ module RgGen
|
|
17
17
|
|
18
18
|
def value(value_name, value, position = nil)
|
19
19
|
symbolized_name = value_name.to_sym
|
20
|
-
|
21
|
-
|
22
|
-
case value
|
23
|
-
when InputValue
|
24
|
-
value
|
25
|
-
else
|
26
|
-
InputValue.new(value, position)
|
27
|
-
end
|
20
|
+
valid_value?(symbolized_name) &&
|
21
|
+
assign_value(symbolized_name, value, position)
|
28
22
|
end
|
29
23
|
|
30
24
|
def []=(value_name, position_or_value, value = nil)
|
@@ -44,14 +38,14 @@ module RgGen
|
|
44
38
|
|
45
39
|
def child(layer, value_list = nil, &block)
|
46
40
|
create_child_data(layer) do |child_data|
|
47
|
-
child_data.build_by_block(block)
|
41
|
+
child_data.build_by_block(&block)
|
48
42
|
child_data.values(value_list)
|
49
43
|
@children << child_data
|
50
44
|
end
|
51
45
|
end
|
52
46
|
|
53
47
|
def load_file(file)
|
54
|
-
build_by_block(instance_eval(<<~BODY, file, 1))
|
48
|
+
build_by_block(&instance_eval(<<~BODY, file, 1))
|
55
49
|
-> { #{File.binread(file)} } # -> { File.binread(file) }
|
56
50
|
BODY
|
57
51
|
end
|
@@ -62,6 +56,16 @@ module RgGen
|
|
62
56
|
@valid_value_lists[layer].include?(value_name)
|
63
57
|
end
|
64
58
|
|
59
|
+
def assign_value(value_name, value, position)
|
60
|
+
@values[value_name] =
|
61
|
+
case value
|
62
|
+
when InputValue
|
63
|
+
value
|
64
|
+
else
|
65
|
+
InputValue.new(value, position)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
65
69
|
def define_setter_methods
|
66
70
|
@valid_value_lists[layer].each(&method(:define_setter_method))
|
67
71
|
end
|
@@ -73,8 +77,7 @@ module RgGen
|
|
73
77
|
end
|
74
78
|
|
75
79
|
def value_setter(value_name, value, position)
|
76
|
-
position
|
77
|
-
value(value_name, value, position)
|
80
|
+
value(value_name, value, position || position_from_caller)
|
78
81
|
end
|
79
82
|
|
80
83
|
def position_from_caller
|
@@ -96,8 +99,8 @@ module RgGen
|
|
96
99
|
|
97
100
|
protected
|
98
101
|
|
99
|
-
def build_by_block(block)
|
100
|
-
|
102
|
+
def build_by_block(&block)
|
103
|
+
block_given? && Docile.dsl_eval(self, &block)
|
101
104
|
end
|
102
105
|
end
|
103
106
|
end
|
@@ -11,9 +11,10 @@ module RgGen
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def match(rhs)
|
14
|
-
rhs
|
15
|
-
|
16
|
-
|
14
|
+
rhs
|
15
|
+
.to_s
|
16
|
+
.yield_self { |s| ignore_blanks? && delete_blanks(s) || s }
|
17
|
+
.yield_self(&method(:match_patterns))
|
17
18
|
end
|
18
19
|
|
19
20
|
def match_automatically?
|
@@ -64,8 +65,7 @@ module RgGen
|
|
64
65
|
index, match_data =
|
65
66
|
@patterns
|
66
67
|
.transform_values { |pattern| pattern.match(rhs) }
|
67
|
-
.
|
68
|
-
.max_by { |_, m| m[0].length }
|
68
|
+
.max_by { |_, m| m && m[0].length || 0 }
|
69
69
|
match_data && [convert_match_data(match_data), index]
|
70
70
|
end
|
71
71
|
|
@@ -53,33 +53,33 @@ module RgGen
|
|
53
53
|
end
|
54
54
|
|
55
55
|
def format_layer_data_by_extractors(read_data, layer)
|
56
|
-
layer_data =
|
57
|
-
|
58
|
-
|
59
|
-
.
|
60
|
-
.each do |extractor|
|
61
|
-
extract_value(read_data, extractor, layer_data, value)
|
62
|
-
end
|
63
|
-
end
|
56
|
+
layer_data =
|
57
|
+
valid_values(layer)
|
58
|
+
.map { |value_name| extract_value(read_data, layer, value_name) }
|
59
|
+
.compact.to_h
|
64
60
|
layer_data.empty? ? nil : layer_data
|
65
61
|
end
|
66
62
|
|
67
|
-
def extract_value(read_data,
|
68
|
-
|
69
|
-
|
63
|
+
def extract_value(read_data, layer, value_name)
|
64
|
+
value =
|
65
|
+
@extractors
|
66
|
+
.select { |extractor| extractor.target_value?(layer, value_name) }
|
67
|
+
.map { |extractor| extractor.extract(read_data) }
|
68
|
+
.compact.last
|
69
|
+
value && [value_name, value]
|
70
70
|
end
|
71
71
|
|
72
72
|
def filter_layer_data(layer_data, layer)
|
73
|
-
layer_data
|
74
|
-
.select { |key, _| valid_values(layer).include?(key) }
|
73
|
+
layer_data.slice(*valid_values(layer))
|
75
74
|
end
|
76
75
|
|
77
76
|
def format_sub_layer_data(_read_data, _layer, _file)
|
78
77
|
end
|
79
78
|
|
80
79
|
def valid_values(layer)
|
81
|
-
@valid_value_lists[layer]
|
82
|
-
|
80
|
+
list = @valid_value_lists[layer]
|
81
|
+
ignore_values = @ignore_values[layer]
|
82
|
+
ignore_values && (list - ignore_values) || list
|
83
83
|
end
|
84
84
|
end
|
85
85
|
end
|
@@ -5,13 +5,18 @@ module RgGen
|
|
5
5
|
module InputBase
|
6
6
|
class Property
|
7
7
|
def self.define(feature, name, **options, &body)
|
8
|
-
new(name, options, body).define(feature)
|
8
|
+
new(name, options, &body).define(feature)
|
9
9
|
end
|
10
10
|
|
11
|
-
def initialize(name, options, body)
|
11
|
+
def initialize(name, options, &body)
|
12
12
|
@name = name
|
13
13
|
@options = options
|
14
|
-
@costom_property =
|
14
|
+
@costom_property =
|
15
|
+
if options[:body]
|
16
|
+
create_costom_property(&options[:body])
|
17
|
+
elsif block_given?
|
18
|
+
create_costom_property(&body)
|
19
|
+
end
|
15
20
|
end
|
16
21
|
|
17
22
|
attr_reader :name
|
@@ -19,15 +24,15 @@ module RgGen
|
|
19
24
|
def define(feature)
|
20
25
|
feature.class_exec(self) do |property|
|
21
26
|
define_method(property.name) do |*args, &block|
|
22
|
-
property.evaluate(self, args, block)
|
27
|
+
property.evaluate(self, args, &block)
|
23
28
|
end
|
24
29
|
end
|
25
30
|
end
|
26
31
|
|
27
|
-
def evaluate(feature, args, block)
|
32
|
+
def evaluate(feature, args, &block)
|
28
33
|
feature.verify(@options[:verify]) if @options.key?(:verify)
|
29
34
|
if proxy_property?
|
30
|
-
proxy_property(feature, args, block)
|
35
|
+
proxy_property(feature, args, &block)
|
31
36
|
else
|
32
37
|
default_property(feature)
|
33
38
|
end
|
@@ -35,7 +40,7 @@ module RgGen
|
|
35
40
|
|
36
41
|
private
|
37
42
|
|
38
|
-
def create_costom_property(body)
|
43
|
+
def create_costom_property(&body)
|
39
44
|
body && Module.new.module_eval do
|
40
45
|
define_method(:__costom_property__, &body)
|
41
46
|
instance_method(:__costom_property__)
|
@@ -50,7 +55,7 @@ module RgGen
|
|
50
55
|
].any?
|
51
56
|
end
|
52
57
|
|
53
|
-
def proxy_property(feature, args, block)
|
58
|
+
def proxy_property(feature, args, &block)
|
54
59
|
receiver, method =
|
55
60
|
if @costom_property
|
56
61
|
[@costom_property.bind(feature), :call]
|
@@ -63,7 +68,7 @@ module RgGen
|
|
63
68
|
end
|
64
69
|
|
65
70
|
def default_property(feature)
|
66
|
-
varible_name = "@#{@name
|
71
|
+
varible_name = "@#{@name.to_s.delete_suffix('?')}"
|
67
72
|
if feature.instance_variable_defined?(varible_name)
|
68
73
|
feature.instance_variable_get(varible_name)
|
69
74
|
elsif @options.key?(:initial)
|
@@ -74,8 +79,9 @@ module RgGen
|
|
74
79
|
end
|
75
80
|
|
76
81
|
def set_initial_value(feature, varible_name)
|
77
|
-
|
78
|
-
|
82
|
+
@options[:initial]
|
83
|
+
.yield_self { |v| evaluate_default_initial_value(feature, v) }
|
84
|
+
.yield_self { |v| feature.instance_variable_set(varible_name, v) }
|
79
85
|
end
|
80
86
|
|
81
87
|
def evaluate_default_initial_value(feature, value)
|
@@ -14,30 +14,9 @@ module RgGen
|
|
14
14
|
symbolize_names: true
|
15
15
|
)
|
16
16
|
end
|
17
|
-
elsif RUBY_VERSION >= '2.5.0'
|
18
|
-
def yaml_safe_load(yaml, file)
|
19
|
-
YAML.safe_load(yaml, [Symbol], [], true, file, symbolize_names: true)
|
20
|
-
end
|
21
17
|
else
|
22
18
|
def yaml_safe_load(yaml, file)
|
23
|
-
|
24
|
-
symbolize_keys(reuslt)
|
25
|
-
end
|
26
|
-
|
27
|
-
def symbolize_keys(result)
|
28
|
-
case result
|
29
|
-
when Hash then symbolize_hash(result)
|
30
|
-
when Array then symbolize_array(result)
|
31
|
-
else result
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def symbolize_hash(result)
|
36
|
-
result.map { |key, value| [key.to_sym, symbolize_keys(value)] }.to_h
|
37
|
-
end
|
38
|
-
|
39
|
-
def symbolize_array(result)
|
40
|
-
result.map(&method(:symbolize_keys))
|
19
|
+
YAML.safe_load(yaml, [Symbol], [], true, file, symbolize_names: true)
|
41
20
|
end
|
42
21
|
end
|
43
22
|
|
@@ -4,14 +4,13 @@ module RgGen
|
|
4
4
|
module Core
|
5
5
|
module OutputBase
|
6
6
|
class CodeGenerator
|
7
|
-
def register(kind, block)
|
8
|
-
|
9
|
-
code_blocks[kind] << block
|
7
|
+
def register(kind, &block)
|
8
|
+
block_given? && (code_blocks[kind] << block)
|
10
9
|
end
|
11
10
|
|
12
11
|
def generate(context, code, kind)
|
13
12
|
code_blocks[kind].each do |block|
|
14
|
-
execute_code_block(context, code, block)
|
13
|
+
execute_code_block(context, code, &block)
|
15
14
|
end
|
16
15
|
end
|
17
16
|
|
@@ -27,7 +26,7 @@ module RgGen
|
|
27
26
|
@code_blocks ||= Hash.new { |blocks, kind| blocks[kind] = [] }
|
28
27
|
end
|
29
28
|
|
30
|
-
def execute_code_block(context, code, block)
|
29
|
+
def execute_code_block(context, code, &block)
|
31
30
|
if block.arity.zero?
|
32
31
|
code << context.instance_exec(&block)
|
33
32
|
else
|
@@ -40,26 +40,30 @@ module RgGen
|
|
40
40
|
|
41
41
|
[:pre_code, :main_code, :post_code].each do |phase|
|
42
42
|
define_method(phase) do |kind, **options, &body|
|
43
|
-
|
44
|
-
if options[:from_template]
|
45
|
-
caller_location = caller_locations(1, 1).first
|
46
|
-
template_path = extract_template_path(options)
|
47
|
-
-> { process_template(template_path, caller_location) }
|
48
|
-
else
|
49
|
-
body
|
50
|
-
end
|
51
|
-
code_generators[__method__] ||= CodeGenerator.new
|
52
|
-
code_generators[__method__].register(kind, block)
|
43
|
+
register_code_generator(__method__, kind, **options, &body)
|
53
44
|
end
|
54
45
|
end
|
55
46
|
|
47
|
+
def register_code_generator(phase, kind, **options, &body)
|
48
|
+
block =
|
49
|
+
if options[:from_template]
|
50
|
+
path = extract_template_path(options)
|
51
|
+
location = caller_locations(2, 1).first
|
52
|
+
-> { process_template(path, location) }
|
53
|
+
else
|
54
|
+
body
|
55
|
+
end
|
56
|
+
(code_generators[phase] ||= CodeGenerator.new)
|
57
|
+
.register(kind, &block)
|
58
|
+
end
|
59
|
+
|
56
60
|
def extract_template_path(options)
|
57
61
|
path = options[:from_template]
|
58
62
|
path.equal?(true) ? nil : path
|
59
63
|
end
|
60
64
|
|
61
65
|
def write_file(file_name_pattern, &body)
|
62
|
-
@file_writer = FileWriter.new(file_name_pattern, body)
|
66
|
+
@file_writer = FileWriter.new(file_name_pattern, &body)
|
63
67
|
end
|
64
68
|
|
65
69
|
def export(*methods)
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RgGen
|
4
|
+
module Core
|
5
|
+
module OutputBase
|
6
|
+
class SourceFileComponentFactory < ComponentFactory
|
7
|
+
private
|
8
|
+
|
9
|
+
def create_component?(_, register_map)
|
10
|
+
!register_map.document_only?
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -11,15 +11,14 @@ module RgGen
|
|
11
11
|
caller_location ||= caller_locations(1, 1).first
|
12
12
|
path = File.ext(caller_location.path, file_extension.to_s)
|
13
13
|
end
|
14
|
-
render(context,
|
14
|
+
render(context, template(path))
|
15
15
|
end
|
16
16
|
|
17
17
|
private
|
18
18
|
|
19
|
-
def
|
20
|
-
@templates ||=
|
21
|
-
|
22
|
-
end
|
19
|
+
def template(path)
|
20
|
+
@templates ||= {}
|
21
|
+
(@templates[path] ||= parse_template(path))
|
23
22
|
end
|
24
23
|
end
|
25
24
|
end
|
@@ -29,14 +29,13 @@ module RgGen
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def format_array_layer_data(read_data, layer, file)
|
32
|
-
read_data
|
33
|
-
|
34
|
-
|
32
|
+
read_data
|
33
|
+
.map { |data| fomrat_hash_layer_data(data, layer, file) }
|
34
|
+
.inject(&:merge)
|
35
35
|
end
|
36
36
|
|
37
37
|
def fomrat_hash_layer_data(read_data, layer, file)
|
38
|
-
convert_to_hash(read_data, file)
|
39
|
-
.reject { |key, _| SUB_LAYER_KEYS[layer]&.include?(key) }
|
38
|
+
convert_to_hash(read_data, file).except(*SUB_LAYER_KEYS[layer])
|
40
39
|
end
|
41
40
|
|
42
41
|
def format_sub_layer_data(read_data, layer, file)
|
@@ -55,10 +54,8 @@ module RgGen
|
|
55
54
|
|
56
55
|
def format_hash_sub_layer_data(read_data, layer, file, sub_layer_data = {})
|
57
56
|
convert_to_hash(read_data, file)
|
58
|
-
.
|
59
|
-
.each
|
60
|
-
merge_sub_layer_data(sub_layer_data, layer, key, value)
|
61
|
-
end
|
57
|
+
.slice(*SUB_LAYER_KEYS[layer])
|
58
|
+
.each { |k, v| merge_sub_layer_data(sub_layer_data, layer, k, v) }
|
62
59
|
sub_layer_data
|
63
60
|
end
|
64
61
|
|
@@ -15,11 +15,13 @@ module RgGen
|
|
15
15
|
attr_reader :indent
|
16
16
|
|
17
17
|
def <<(rhs)
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
18
|
+
case rhs
|
19
|
+
when String then push_string(rhs)
|
20
|
+
when CodeBlock then push_code_block(rhs)
|
21
|
+
when Array then rhs.inject(self, :<<)
|
22
|
+
when code? then self << rhs.to_code
|
23
|
+
else push_word(rhs)
|
24
|
+
end
|
23
25
|
end
|
24
26
|
|
25
27
|
def indent=(indent)
|
@@ -74,6 +76,10 @@ module RgGen
|
|
74
76
|
self
|
75
77
|
end
|
76
78
|
|
79
|
+
def code?
|
80
|
+
->(rhs) { rhs.respond_to?(:to_code) }
|
81
|
+
end
|
82
|
+
|
77
83
|
def newline
|
78
84
|
"\n"
|
79
85
|
end
|
data/lib/rggen/core/version.rb
CHANGED
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.
|
4
|
+
version: 0.25.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: 2021-
|
11
|
+
date: 2021-02-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: docile
|
@@ -106,7 +106,6 @@ files:
|
|
106
106
|
- lib/rggen/core/base/feature_factory.rb
|
107
107
|
- lib/rggen/core/base/feature_layer_extension.rb
|
108
108
|
- lib/rggen/core/base/internal_struct.rb
|
109
|
-
- lib/rggen/core/base/proxy_call.rb
|
110
109
|
- lib/rggen/core/base/shared_context.rb
|
111
110
|
- lib/rggen/core/builder.rb
|
112
111
|
- lib/rggen/core/builder/builder.rb
|
@@ -158,11 +157,13 @@ files:
|
|
158
157
|
- lib/rggen/core/output_base/code_generator.rb
|
159
158
|
- lib/rggen/core/output_base/component.rb
|
160
159
|
- lib/rggen/core/output_base/component_factory.rb
|
160
|
+
- lib/rggen/core/output_base/document_component_factory.rb
|
161
161
|
- lib/rggen/core/output_base/erb_engine.rb
|
162
162
|
- lib/rggen/core/output_base/feature.rb
|
163
163
|
- lib/rggen/core/output_base/feature_factory.rb
|
164
164
|
- lib/rggen/core/output_base/file_writer.rb
|
165
165
|
- lib/rggen/core/output_base/raise_error.rb
|
166
|
+
- lib/rggen/core/output_base/source_file_component_factory.rb
|
166
167
|
- lib/rggen/core/output_base/template_engine.rb
|
167
168
|
- lib/rggen/core/plugin.rb
|
168
169
|
- lib/rggen/core/printers.rb
|
@@ -204,7 +205,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
204
205
|
requirements:
|
205
206
|
- - ">="
|
206
207
|
- !ruby/object:Gem::Version
|
207
|
-
version: '2.
|
208
|
+
version: '2.5'
|
208
209
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
209
210
|
requirements:
|
210
211
|
- - ">="
|
@@ -214,5 +215,5 @@ requirements: []
|
|
214
215
|
rubygems_version: 3.2.3
|
215
216
|
signing_key:
|
216
217
|
specification_version: 4
|
217
|
-
summary: rggen-core-0.
|
218
|
+
summary: rggen-core-0.25.0
|
218
219
|
test_files: []
|
@@ -1,18 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module RgGen
|
4
|
-
module Core
|
5
|
-
module Base
|
6
|
-
class ProxyCall
|
7
|
-
def initialize(receiver, method)
|
8
|
-
@receiver = receiver
|
9
|
-
@method = method
|
10
|
-
end
|
11
|
-
|
12
|
-
def call(*args, &block)
|
13
|
-
@receiver.__send__(@method, *args, &block)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|