rggen-core 0.21.0 → 0.22.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rggen/core.rb +1 -1
- data/lib/rggen/core/builder/builder.rb +7 -19
- data/lib/rggen/core/builder/plugin_manager.rb +140 -0
- data/lib/rggen/core/dsl.rb +3 -1
- data/lib/rggen/core/exceptions.rb +3 -0
- data/lib/rggen/core/generator.rb +3 -3
- data/lib/rggen/core/options.rb +12 -14
- data/lib/rggen/core/printers.rb +11 -7
- data/lib/rggen/core/version.rb +1 -1
- metadata +4 -4
- data/lib/rggen/core/builder/plugins.rb +0 -79
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d6fde36c04e21476aef2a09a20a3d22467bf6f4a28fa4f831c7aa7208bdb0a9a
|
4
|
+
data.tar.gz: 0735722aae6a60569505b06ec3c3c9465c47f201138056752a00cc29b780d5a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4f1ae60ad3e557b0f18514cb803c635134f93f922deae475db97745571b0ff38a0ce7571c2cef324ed1ac4250fc2e3e5d78d9d48689cfafe827d4ed938425684
|
7
|
+
data.tar.gz: 589c74ee6817e7b5aa90595c7d358f2e2db730cf3b06af40ce737da62135680fd55df52259294501c2c43b063d67908b5cd0b1fe8d8fa06d9efdbe7ef05ff1cc
|
data/lib/rggen/core.rb
CHANGED
@@ -95,7 +95,7 @@ require_relative 'core/builder/simple_feature_entry'
|
|
95
95
|
require_relative 'core/builder/list_feature_entry'
|
96
96
|
require_relative 'core/builder/feature_registry'
|
97
97
|
require_relative 'core/builder/layer'
|
98
|
-
require_relative 'core/builder/
|
98
|
+
require_relative 'core/builder/plugin_manager'
|
99
99
|
require_relative 'core/builder/builder'
|
100
100
|
require_relative 'core/builder'
|
101
101
|
|
@@ -4,13 +4,15 @@ module RgGen
|
|
4
4
|
module Core
|
5
5
|
module Builder
|
6
6
|
class Builder
|
7
|
+
extend Forwardable
|
8
|
+
|
7
9
|
def initialize
|
8
10
|
initialize_component_registries
|
9
11
|
initialize_layers
|
10
|
-
@
|
12
|
+
@plugin_manager = PluginManager.new(self)
|
11
13
|
end
|
12
14
|
|
13
|
-
attr_reader :
|
15
|
+
attr_reader :plugin_manager
|
14
16
|
|
15
17
|
def input_component_registry(name, &body)
|
16
18
|
component_registry(:input, name, body)
|
@@ -88,23 +90,9 @@ module RgGen
|
|
88
90
|
RegisterMap.setup(self)
|
89
91
|
end
|
90
92
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
def activate_plugins(**options)
|
96
|
-
plugins.activate(self, **options)
|
97
|
-
end
|
98
|
-
|
99
|
-
def load_setup_file(file, activation = true)
|
100
|
-
(file.nil? || file.empty?) &&
|
101
|
-
(raise Core::LoadError.new('no setup file is given'))
|
102
|
-
File.readable?(file) ||
|
103
|
-
(raise Core::LoadError.new("cannot load such setup file: #{file}"))
|
104
|
-
RgGen.builder(self)
|
105
|
-
load(file)
|
106
|
-
activation && activate_plugins
|
107
|
-
end
|
93
|
+
def_delegator :plugin_manager, :load_plugin
|
94
|
+
def_delegator :plugin_manager, :load_plugins
|
95
|
+
def_delegator :plugin_manager, :setup
|
108
96
|
|
109
97
|
private
|
110
98
|
|
@@ -0,0 +1,140 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RgGen
|
4
|
+
module Core
|
5
|
+
module Builder
|
6
|
+
class Plugin
|
7
|
+
DEFAULT_PLUGIN_VERSION = '0.0.0'
|
8
|
+
|
9
|
+
def initialize(plugin_module, &block)
|
10
|
+
@plugin_module = plugin_module
|
11
|
+
@block = block
|
12
|
+
plugin_name # check if plugin name is given
|
13
|
+
end
|
14
|
+
|
15
|
+
def default_setup(builder)
|
16
|
+
@plugin_module.respond_to?(:default_setup) &&
|
17
|
+
@plugin_module.default_setup(builder)
|
18
|
+
end
|
19
|
+
|
20
|
+
def optional_setup(builder)
|
21
|
+
@block && @plugin_module.instance_exec(builder, &@block)
|
22
|
+
end
|
23
|
+
|
24
|
+
def plugin_name
|
25
|
+
if @plugin_module.const_defined?(:PLUGIN_NAME)
|
26
|
+
@plugin_module.const_get(:PLUGIN_NAME)
|
27
|
+
elsif @plugin_module.respond_to?(:plugin_name)
|
28
|
+
@plugin_module.plugin_name
|
29
|
+
else
|
30
|
+
raise Core::PluginError.new('no plugin name is given')
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def version
|
35
|
+
if @plugin_module.const_defined?(:VERSION)
|
36
|
+
@plugin_module.const_get(:VERSION)
|
37
|
+
elsif @plugin_module.respond_to?(:version)
|
38
|
+
@plugin_module.version
|
39
|
+
else
|
40
|
+
DEFAULT_PLUGIN_VERSION
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def version_info
|
45
|
+
"#{plugin_name} #{version}"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
class PluginManager
|
50
|
+
def initialize(builder)
|
51
|
+
@builder = builder
|
52
|
+
@plugins = []
|
53
|
+
end
|
54
|
+
|
55
|
+
def load_plugin(setup_path_or_name)
|
56
|
+
setup_path_or_name = setup_path_or_name.to_s.strip
|
57
|
+
setup_path =
|
58
|
+
if setup_file_directly_given?(setup_path_or_name)
|
59
|
+
setup_path_or_name
|
60
|
+
else
|
61
|
+
get_setup_path(setup_path_or_name)
|
62
|
+
end
|
63
|
+
read_setup_file(setup_path, setup_path_or_name)
|
64
|
+
end
|
65
|
+
|
66
|
+
def load_plugins(plugins, no_default_plugins, activation = true)
|
67
|
+
RgGen.builder(@builder)
|
68
|
+
merge_plugins(plugins, no_default_plugins)
|
69
|
+
.each { |plugin| load_plugin(*plugin) }
|
70
|
+
activation && activate_plugins
|
71
|
+
end
|
72
|
+
|
73
|
+
def setup(plugin_module, &block)
|
74
|
+
@plugins << Plugin.new(plugin_module, &block)
|
75
|
+
end
|
76
|
+
|
77
|
+
def activate_plugins(**options)
|
78
|
+
options[:no_default_setup] ||
|
79
|
+
@plugins.each { |plugin| plugin.default_setup(@builder) }
|
80
|
+
options[:no_optional_setup] ||
|
81
|
+
@plugins.each { |plugin| plugin.optional_setup(@builder) }
|
82
|
+
end
|
83
|
+
|
84
|
+
def version_info
|
85
|
+
@plugins.map(&:version_info)
|
86
|
+
end
|
87
|
+
|
88
|
+
private
|
89
|
+
|
90
|
+
def setup_file_directly_given?(setup_path_or_name)
|
91
|
+
File.ext(setup_path_or_name) == 'rb' ||
|
92
|
+
File.basename(setup_path_or_name, '.*') == 'setup'
|
93
|
+
end
|
94
|
+
|
95
|
+
def get_setup_path(name)
|
96
|
+
base, sub_directory = name.split('/', 2)
|
97
|
+
base = base.sub(/^rggen[-_]/, '').tr('-', '_')
|
98
|
+
File.join(*[
|
99
|
+
'rggen', base, sub_directory || '', 'setup'
|
100
|
+
].reject(&:empty?))
|
101
|
+
end
|
102
|
+
|
103
|
+
def read_setup_file(setup_path, setup_path_or_name)
|
104
|
+
require setup_path
|
105
|
+
rescue ::LoadError
|
106
|
+
raise Core::PluginError.new([
|
107
|
+
"cannot load such plugin: #{setup_path_or_name}",
|
108
|
+
setup_path_or_name != setup_path && " (#{setup_path})" || ''
|
109
|
+
].join)
|
110
|
+
end
|
111
|
+
|
112
|
+
def merge_plugins(plugins, no_default_plugins)
|
113
|
+
[
|
114
|
+
*default_plugins(no_default_plugins),
|
115
|
+
*plugins_from_env,
|
116
|
+
*plugins
|
117
|
+
]
|
118
|
+
end
|
119
|
+
|
120
|
+
DEFAULT_PLUGSINS = 'rggen/setup'
|
121
|
+
|
122
|
+
def default_plugins(no_default_plugins)
|
123
|
+
load_default_plugins?(no_default_plugins) && DEFAULT_PLUGSINS || nil
|
124
|
+
end
|
125
|
+
|
126
|
+
def load_default_plugins?(no_default_plugins)
|
127
|
+
return false if no_default_plugins
|
128
|
+
return false if ENV.key?('RGGEN_NO_DEFAULT_PLUGINS')
|
129
|
+
return false if Gem.find_files(DEFAULT_PLUGSINS).empty?
|
130
|
+
true
|
131
|
+
end
|
132
|
+
|
133
|
+
def plugins_from_env
|
134
|
+
ENV['RGGEN_PLUGINS']
|
135
|
+
&.split(':')&.map(&:strip)&.reject(&:empty?)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
data/lib/rggen/core/dsl.rb
CHANGED
@@ -15,11 +15,13 @@ module RgGen
|
|
15
15
|
:define_simple_feature,
|
16
16
|
:define_list_feature,
|
17
17
|
:define_list_item_feature,
|
18
|
+
:define_value_extractor,
|
18
19
|
:enable,
|
19
20
|
:disable_all,
|
20
21
|
:disable,
|
21
22
|
:delete,
|
22
|
-
:setup
|
23
|
+
:setup,
|
24
|
+
:load_plugin
|
23
25
|
].each do |method_name|
|
24
26
|
def_delegator :'RgGen.builder', method_name
|
25
27
|
end
|
data/lib/rggen/core/generator.rb
CHANGED
@@ -4,7 +4,7 @@ module RgGen
|
|
4
4
|
module Core
|
5
5
|
class Generator
|
6
6
|
def run(builder, options)
|
7
|
-
|
7
|
+
load_plugins(builder, options)
|
8
8
|
load_configuration(builder, options[:configuration])
|
9
9
|
load_register_map(builder, options.register_map_files)
|
10
10
|
write_files(builder, options)
|
@@ -15,8 +15,8 @@ module RgGen
|
|
15
15
|
attr_reader :configuration
|
16
16
|
attr_reader :register_map
|
17
17
|
|
18
|
-
def
|
19
|
-
builder.
|
18
|
+
def load_plugins(builder, options)
|
19
|
+
builder.load_plugins(options[:plugins], options[:no_default_plugins])
|
20
20
|
end
|
21
21
|
|
22
22
|
def load_configuration(builder, file)
|
data/lib/rggen/core/options.rb
CHANGED
@@ -101,21 +101,19 @@ module RgGen
|
|
101
101
|
end
|
102
102
|
end
|
103
103
|
|
104
|
-
Options.add_option(:
|
105
|
-
option.long_option '--
|
106
|
-
option.default
|
107
|
-
option.
|
108
|
-
|
109
|
-
|
110
|
-
ENV['RGGEN_DEFAULT_SETUP_FILE'] || define_setup_file_from_const
|
111
|
-
end
|
104
|
+
Options.add_option(:no_default_plugins) do |option|
|
105
|
+
option.long_option '--no-default-plugins'
|
106
|
+
option.default false
|
107
|
+
option.action { |_, options| options[:no_default_plugins] = true }
|
108
|
+
option.description 'Do not load default plugins'
|
109
|
+
end
|
112
110
|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
111
|
+
Options.add_option(:plugins) do |option|
|
112
|
+
option.long_option '--plugin PLUGIN'
|
113
|
+
option.default { [] }
|
114
|
+
option.action { |value, options| options[:plugins] << value }
|
115
|
+
option.description 'Load a RgGen plugin ' \
|
116
|
+
"(name of plugin/path to 'setup.rb' file)"
|
119
117
|
end
|
120
118
|
|
121
119
|
Options.add_option(:configuration) do |option|
|
data/lib/rggen/core/printers.rb
CHANGED
@@ -18,18 +18,20 @@ module RgGen
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def run(builder, options)
|
21
|
-
verbose? &&
|
21
|
+
verbose? && load_plugins(builder, options)
|
22
22
|
puts version_message(builder)
|
23
23
|
end
|
24
24
|
|
25
25
|
private
|
26
26
|
|
27
|
-
def
|
28
|
-
|
27
|
+
def load_plugins(builder, options)
|
28
|
+
plugins = options[:plugins]
|
29
|
+
no_default_plugins = options[:no_default_plugins]
|
30
|
+
builder.load_plugins(plugins, no_default_plugins, false)
|
29
31
|
end
|
30
32
|
|
31
|
-
def
|
32
|
-
|
33
|
+
def verbose?
|
34
|
+
@verbose
|
33
35
|
end
|
34
36
|
|
35
37
|
def version_message(builder)
|
@@ -44,8 +46,10 @@ module RgGen
|
|
44
46
|
end
|
45
47
|
|
46
48
|
def verbose_version(builder)
|
47
|
-
[
|
48
|
-
|
49
|
+
[
|
50
|
+
"rggen-core #{Core::VERSION}",
|
51
|
+
*builder.plugin_manager.version_info
|
52
|
+
].map { |version_info| " - #{version_info}" }
|
49
53
|
end
|
50
54
|
end
|
51
55
|
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.22.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: 2020-
|
11
|
+
date: 2020-08-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: docile
|
@@ -98,7 +98,7 @@ files:
|
|
98
98
|
- lib/rggen/core/builder/list_feature_entry.rb
|
99
99
|
- lib/rggen/core/builder/loader_registry.rb
|
100
100
|
- lib/rggen/core/builder/output_component_registry.rb
|
101
|
-
- lib/rggen/core/builder/
|
101
|
+
- lib/rggen/core/builder/plugin_manager.rb
|
102
102
|
- lib/rggen/core/builder/simple_feature_entry.rb
|
103
103
|
- lib/rggen/core/cli.rb
|
104
104
|
- lib/rggen/core/configuration.rb
|
@@ -189,5 +189,5 @@ requirements: []
|
|
189
189
|
rubygems_version: 3.1.2
|
190
190
|
signing_key:
|
191
191
|
specification_version: 4
|
192
|
-
summary: rggen-core-0.
|
192
|
+
summary: rggen-core-0.22.0
|
193
193
|
test_files: []
|
@@ -1,79 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module RgGen
|
4
|
-
module Core
|
5
|
-
module Builder
|
6
|
-
class Plugin
|
7
|
-
DEFAULT_PLUGIN_VERSION = '0.0.0'
|
8
|
-
|
9
|
-
def initialize(name, module_or_version, &block)
|
10
|
-
@name = name
|
11
|
-
@block = block
|
12
|
-
@version, @plugin_module =
|
13
|
-
if module_or_version.is_a?(Module)
|
14
|
-
[extract_version(module_or_version), module_or_version]
|
15
|
-
else
|
16
|
-
[module_or_version || DEFAULT_PLUGIN_VERSION]
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
attr_reader :name
|
21
|
-
attr_reader :version
|
22
|
-
|
23
|
-
def default_setup(builder)
|
24
|
-
@plugin_module &&
|
25
|
-
begin
|
26
|
-
@plugin_module.respond_to?(:default_setup) &&
|
27
|
-
@plugin_module.default_setup(builder)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def optional_setup(builder)
|
32
|
-
@block &&
|
33
|
-
if @plugin_module
|
34
|
-
@plugin_module.instance_exec(builder, &@block)
|
35
|
-
else
|
36
|
-
@block.call(builder)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
def version_info
|
41
|
-
"#{name} #{version}"
|
42
|
-
end
|
43
|
-
|
44
|
-
private
|
45
|
-
|
46
|
-
def extract_version(plugin_module)
|
47
|
-
if plugin_module.const_defined?(:VERSION)
|
48
|
-
plugin_module.const_get(:VERSION)
|
49
|
-
elsif plugin_module.respond_to?(:version)
|
50
|
-
plugin_module.version
|
51
|
-
else
|
52
|
-
DEFAULT_PLUGIN_VERSION
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
class Plugins
|
58
|
-
def initialize
|
59
|
-
@plugins = []
|
60
|
-
end
|
61
|
-
|
62
|
-
def add(name, module_or_version, &block)
|
63
|
-
@plugins << Plugin.new(name, module_or_version, &block)
|
64
|
-
end
|
65
|
-
|
66
|
-
def activate(builder, **options)
|
67
|
-
options[:no_default_setup] ||
|
68
|
-
@plugins.each { |plugin| plugin.default_setup(builder) }
|
69
|
-
options[:no_optional_setup] ||
|
70
|
-
@plugins.each { |plugin| plugin.optional_setup(builder) }
|
71
|
-
end
|
72
|
-
|
73
|
-
def version_info
|
74
|
-
@plugins.map(&:version_info)
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|