rggen-core 0.25.2 → 0.26.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: 6b2cb2ac6ff0638f1b58234ece63f36d8ae6c0c9b370404d11767fcadd49f1ae
4
- data.tar.gz: 8ca7963204bf42554d6c2715a0141e2a4b0fa577281f083aa3e171f9e3dee930
3
+ metadata.gz: fe3a65999b49b800216dea110ca47e81c71cf4fe0a65626f50526be374647713
4
+ data.tar.gz: 160dbda800f4fef46bbe18ef34810851082d09271eb7754b6b4508eb4f56c8fd
5
5
  SHA512:
6
- metadata.gz: 0df06ca1ce1bada021e283edd6c57c39f1349d4a32cf6109e943e3f728b951a424f62928362fcf4562c3ca896853b5fd7a25d4fdeb26e4b18bcb4067f51f3454
7
- data.tar.gz: a543383fed2f6e8a97bebe34710c3dbce0914ee25034c97a17df708cc21128172afd48381395077e71655a3d77e3cad84306c352eb23684ccba8a74f5544b4ef
6
+ metadata.gz: eae55af6cdaa6eff67f15ef508dcd32af950d72f18621d0b8769011957c9c6a72c9f3c41557d197a0c1e9fec25ecaff34364f3518cd04c12f22bdb6ee8efa6af
7
+ data.tar.gz: 3d030a72ade1067dbb7450ff30ef4cffc3d97430e73a4ea96f9fb310a5cb633e314f1a9b280d4c4e615b1fce2ace5f5456f2881bd76a18fa05cef60420989ada
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2017-2021 Taichi Ishitani
3
+ Copyright (c) 2017-2022 Taichi Ishitani
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -44,7 +44,7 @@ Feedbacks, bug reports, questions and etc. are wellcome! You can post them by us
44
44
 
45
45
  ## Copyright & License
46
46
 
47
- Copyright © 2017-2021 Taichi Ishitani. RgGen::Core is licensed under the [MIT License](https://opensource.org/licenses/MIT), see [LICENSE](LICENSE) for futher details.
47
+ Copyright © 2017-2022 Taichi Ishitani. RgGen::Core is licensed under the [MIT License](https://opensource.org/licenses/MIT), see [LICENSE](LICENSE) for futher details.
48
48
 
49
49
  ## Code of Conduct
50
50
 
@@ -27,7 +27,7 @@ module RgGen
27
27
  if root_factory?
28
28
  [nil, preprocess(args)]
29
29
  else
30
- [args.first, preprocess(args[1..-1])]
30
+ [args.first, preprocess(args[1..])]
31
31
  end
32
32
  create_component(parent, sources) do |component|
33
33
  build_component(parent, component, sources)
@@ -42,7 +42,7 @@ module RgGen
42
42
  factories =
43
43
  @entries
44
44
  .map(&:build_factory)
45
- .map { |f| [f.layer, f] }.to_h
45
+ .to_h { |f| [f.layer, f] }
46
46
  factories.each_value { |f| f.component_factories factories }
47
47
  factories.values
48
48
  end
@@ -22,26 +22,80 @@ module RgGen
22
22
  end
23
23
  end
24
24
 
25
+ class PluginInfo
26
+ attr_reader :name
27
+ attr_reader :setup_path
28
+ attr_reader :gem_name
29
+ attr_reader :version
30
+
31
+ def parse(setup_path_or_name, version)
32
+ setup_path_or_name = setup_path_or_name.to_s.strip
33
+ @name, @setup_path, @gem_name, @version =
34
+ if setup_file_directly_given?(setup_path_or_name)
35
+ [nil, setup_path_or_name, *find_plugin_gem(setup_path_or_name)]
36
+ else
37
+ [
38
+ setup_path_or_name, get_setup_path(setup_path_or_name),
39
+ extract_gem_name(setup_path_or_name), version
40
+ ]
41
+ end
42
+ self
43
+ end
44
+
45
+ def to_s
46
+ if name && version
47
+ "#{name} (#{version})"
48
+ elsif name
49
+ name
50
+ else
51
+ setup_path
52
+ end
53
+ end
54
+
55
+ private
56
+
57
+ def setup_file_directly_given?(setup_path_or_name)
58
+ File.ext(setup_path_or_name) == 'rb' ||
59
+ File.basename(setup_path_or_name, '.*') == 'setup'
60
+ end
61
+
62
+ def find_plugin_gem(setup_path)
63
+ gemspec =
64
+ Gem::Specification
65
+ .each.find { |spec| match_gemspec?(spec, setup_path) }
66
+ gemspec && [gemspec.name, gemspec.version]
67
+ end
68
+
69
+ def match_gemspec?(gemspec, setup_path)
70
+ gemspec.full_require_paths.any?(&setup_path.method(:start_with?))
71
+ end
72
+
73
+ def extract_gem_name(plugin_name)
74
+ plugin_name.split('/', 2).first
75
+ end
76
+
77
+ def get_setup_path(plugin_name)
78
+ base, sub_directory = plugin_name.split('/', 2)
79
+ base = base.sub(/^rggen[-_]/, '').tr('-', '_')
80
+ File.join(*['rggen', base, sub_directory, 'setup'].compact)
81
+ end
82
+ end
83
+
25
84
  class PluginManager
26
85
  def initialize(builder)
27
86
  @builder = builder
28
87
  @plugins = []
29
88
  end
30
89
 
31
- def load_plugin(setup_path_or_name)
32
- setup_path_or_name = setup_path_or_name.to_s.strip
33
- setup_path, root_dir =
34
- if setup_file_directly_given?(setup_path_or_name)
35
- [setup_path_or_name, extract_root_dir(setup_path_or_name)]
36
- else
37
- [get_setup_path(setup_path_or_name), nil]
38
- end
39
- read_setup_file(setup_path, setup_path_or_name, root_dir)
90
+ def load_plugin(setup_path_or_name, version = nil)
91
+ info = PluginInfo.new.parse(setup_path_or_name, version)
92
+ read_setup_file(info)
40
93
  end
41
94
 
42
95
  def load_plugins(plugins, no_default_plugins, activation = true)
43
96
  RgGen.builder(@builder)
44
- merge_plugins(plugins, no_default_plugins).each(&method(:load_plugin))
97
+ merge_plugins(plugins, no_default_plugins)
98
+ .each { |plugin| load_plugin(*plugin) }
45
99
  activation && activate_plugins
46
100
  end
47
101
 
@@ -64,45 +118,11 @@ module RgGen
64
118
 
65
119
  private
66
120
 
67
- def setup_file_directly_given?(setup_path_or_name)
68
- File.ext(setup_path_or_name) == 'rb' ||
69
- File.basename(setup_path_or_name, '.*') == 'setup'
70
- end
71
-
72
- def extract_root_dir(setup_path)
73
- Pathname
74
- .new(setup_path)
75
- .ascend.find(&method(:rggen_dir?))
76
- &.parent
77
- &.to_s
78
- end
79
-
80
- def rggen_dir?(path)
81
- path.each_filename.to_a[-2..-1] == ['lib', 'rggen']
82
- end
83
-
84
- def get_setup_path(name)
85
- base, sub_directory = name.split('/', 2)
86
- base = base.sub(/^rggen[-_]/, '').tr('-', '_')
87
- File.join(*['rggen', base, sub_directory, 'setup'].compact)
88
- end
89
-
90
- def read_setup_file(setup_path, setup_path_or_name, root_dir)
91
- if setup_path == DEFAULT_PLUGSINS
92
- gem 'rggen', DEFAULT_PLUGSINS_VERSION
93
- elsif root_dir
94
- $LOAD_PATH.unshift(root_dir)
95
- end
96
-
97
- require setup_path
121
+ def read_setup_file(info)
122
+ info.gem_name && gem(info.gem_name, info.version)
123
+ require info.setup_path
98
124
  rescue ::LoadError
99
- message =
100
- if setup_path_or_name == setup_path
101
- "cannot load such plugin: #{setup_path_or_name}"
102
- else
103
- "cannot load such plugin: #{setup_path_or_name} (#{setup_path})"
104
- end
105
- raise Core::PluginError.new(message)
125
+ raise Core::PluginError.new("cannot load such plugin: #{info}")
106
126
  end
107
127
 
108
128
  def merge_plugins(plugins, no_default_plugins)
@@ -114,7 +134,6 @@ module RgGen
114
134
  end
115
135
 
116
136
  DEFAULT_PLUGSINS = 'rggen/setup'
117
- DEFAULT_PLUGSINS_VERSION = "~> #{MAJOR}.#{MINOR}.0"
118
137
 
119
138
  def default_plugins(no_default_plugins)
120
139
  load_default_plugins?(no_default_plugins) && DEFAULT_PLUGSINS || nil
@@ -129,7 +148,9 @@ module RgGen
129
148
 
130
149
  def plugins_from_env
131
150
  ENV['RGGEN_PLUGINS']
132
- &.split(':')&.map(&:strip)&.reject(&:empty?)
151
+ &.split(':')
152
+ &.reject(&:blank?)
153
+ &.map { |entry| entry.split(',', 2) }
133
154
  end
134
155
 
135
156
  def plugin?(plugin_module)
@@ -3,6 +3,7 @@
3
3
  require 'facets/array/merge'
4
4
  require 'facets/file/ext'
5
5
  require 'facets/hash/except' if RUBY_VERSION < '3.0.0'
6
+ require 'facets/kernel/blank'
6
7
  require 'facets/pathname/to_path'
7
8
  require 'facets/module/attr_setter'
8
9
  require 'facets/module/lastname'
@@ -45,9 +45,7 @@ module RgGen
45
45
  end
46
46
 
47
47
  def load_file(file)
48
- build_by_block(&instance_eval(<<~BODY, file, 1))
49
- -> { #{File.binread(file)} } # -> { File.binread(file) }
50
- BODY
48
+ build_by_block { instance_eval(File.binread(file), file, 1) }
51
49
  end
52
50
 
53
51
  private
@@ -42,11 +42,9 @@ module RgGen
42
42
  end
43
43
 
44
44
  def format_sub_layer(read_data, input_data, layer, file)
45
- format_sub_layer_data(read_data, layer, file)
46
- &.flat_map { |sub_layer, data_array| [sub_layer].product(data_array) }
47
- &.each do |(sub_layer, data)|
48
- format(data, input_data.child(sub_layer), sub_layer, file)
49
- end
45
+ format_sub_layer_data(read_data, layer, file)&.each do |(sub_layer, data)|
46
+ format(data, input_data.child(sub_layer), sub_layer, file)
47
+ end
50
48
  end
51
49
 
52
50
  def format_layer_data(_read_data, _layer, _file)
@@ -6,22 +6,13 @@ module RgGen
6
6
  module YAMLLoader
7
7
  private
8
8
 
9
- if RUBY_VERSION >= '2.6.0'
10
- def yaml_safe_load(yaml, file)
11
- YAML.safe_load(
12
- yaml,
13
- permitted_classes: [Symbol], aliases: true, filename: file,
14
- symbolize_names: true
15
- )
16
- end
17
- else
18
- def yaml_safe_load(yaml, file)
19
- YAML.safe_load(yaml, [Symbol], [], true, file, symbolize_names: true)
20
- end
21
- end
22
-
23
9
  def load_yaml(file)
24
- yaml_safe_load(File.binread(file), file)
10
+ yaml = File.binread(file)
11
+ YAML.safe_load(
12
+ yaml,
13
+ permitted_classes: [Symbol], aliases: true,
14
+ filename: file, symbolize_names: true
15
+ )
25
16
  end
26
17
  end
27
18
  end
@@ -109,9 +109,9 @@ module RgGen
109
109
  end
110
110
 
111
111
  Options.add_option(:plugins) do |option|
112
- option.long_option '--plugin PLUGIN'
112
+ option.long_option '--plugin PLUGIN[:VERSION]'
113
113
  option.default { [] }
114
- option.action { |value, options| options[:plugins] << value }
114
+ option.action { |value, options| options[:plugins] << value.split(':', 2) }
115
115
  option.description 'Load a RgGen plugin ' \
116
116
  "(name of plugin/path to 'setup.rb' file)"
117
117
  end
@@ -32,7 +32,7 @@ module RgGen
32
32
 
33
33
  def create_directory(path)
34
34
  directory = path.dirname
35
- directory.directory? || directory.mkpath
35
+ directory.directory? || FileUtils.mkpath(directory)
36
36
  end
37
37
  end
38
38
  end
@@ -47,12 +47,12 @@ module RgGen
47
47
  end
48
48
 
49
49
  def format_array_sub_layer_data(read_data, layer, file)
50
- read_data.each_with_object({}) do |data, sub_layer_data|
50
+ read_data.each_with_object([]) do |data, sub_layer_data|
51
51
  format_hash_sub_layer_data(data, layer, file, sub_layer_data)
52
52
  end
53
53
  end
54
54
 
55
- def format_hash_sub_layer_data(read_data, layer, file, sub_layer_data = {})
55
+ def format_hash_sub_layer_data(read_data, layer, file, sub_layer_data = [])
56
56
  convert_to_hash(read_data, file)
57
57
  .slice(*SUB_LAYER_KEYS[layer])
58
58
  .each { |k, v| merge_sub_layer_data(sub_layer_data, layer, k, v) }
@@ -61,9 +61,10 @@ module RgGen
61
61
 
62
62
  def merge_sub_layer_data(sub_layer_data, layer, key, value)
63
63
  if SUB_LAYER_KEY_MAP[layer].key?(key)
64
- (sub_layer_data[SUB_LAYER_KEY_MAP[layer][key]] ||= []).concat(value)
64
+ sub_layer_data
65
+ .concat([SUB_LAYER_KEY_MAP[layer][key]].product(value))
65
66
  else
66
- (sub_layer_data[key] ||= []) << value
67
+ sub_layer_data << [key, value]
67
68
  end
68
69
  end
69
70
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  module RgGen
4
4
  module Core
5
- VERSION = '0.25.2'
5
+ VERSION = '0.26.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.25.2
4
+ version: 0.26.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-16 00:00:00.000000000 Z
11
+ date: 2022-03-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: docile
@@ -195,6 +195,7 @@ licenses:
195
195
  metadata:
196
196
  bug_tracker_uri: https://github.com/rggen/rggen-core/issues
197
197
  mailing_list_uri: https://groups.google.com/d/forum/rggen
198
+ rubygems_mfa_required: 'true'
198
199
  source_code_uri: https://github.com/rggen/rggen-core
199
200
  wiki_uri: https://github.com/rggen/rggen/wiki
200
201
  post_install_message:
@@ -205,15 +206,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
205
206
  requirements:
206
207
  - - ">="
207
208
  - !ruby/object:Gem::Version
208
- version: '2.5'
209
+ version: '2.6'
209
210
  required_rubygems_version: !ruby/object:Gem::Requirement
210
211
  requirements:
211
212
  - - ">="
212
213
  - !ruby/object:Gem::Version
213
214
  version: '0'
214
215
  requirements: []
215
- rubygems_version: 3.4.19
216
+ rubygems_version: 3.3.3
216
217
  signing_key:
217
218
  specification_version: 4
218
- summary: rggen-core-0.25.2
219
+ summary: rggen-core-0.26.0
219
220
  test_files: []