nanoc 4.4.7 → 4.5.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.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +9 -7
  3. data/NEWS.md +6 -0
  4. data/lib/nanoc.rb +1 -0
  5. data/lib/nanoc/base.rb +0 -1
  6. data/lib/nanoc/base/feature.rb +1 -1
  7. data/lib/nanoc/base/repos/data_source.rb +1 -1
  8. data/lib/nanoc/base/repos/site_loader.rb +1 -1
  9. data/lib/nanoc/base/services/action_provider.rb +1 -1
  10. data/lib/nanoc/base/services/filter.rb +1 -1
  11. data/lib/nanoc/checking.rb +7 -9
  12. data/lib/nanoc/checking/check.rb +1 -1
  13. data/lib/nanoc/checking/checks.rb +9 -17
  14. data/lib/nanoc/checking/checks/internal_links.rb +2 -0
  15. data/lib/nanoc/checking/checks/mixed_content.rb +2 -0
  16. data/lib/nanoc/checking/checks/stale.rb +2 -0
  17. data/lib/nanoc/checking/runner.rb +2 -2
  18. data/lib/nanoc/cli.rb +9 -6
  19. data/lib/nanoc/cli/commands/deploy.rb +4 -4
  20. data/lib/nanoc/cli/commands/show-plugins.rb +12 -12
  21. data/lib/nanoc/cli/stream_cleaners.rb +7 -7
  22. data/lib/nanoc/data_sources.rb +0 -3
  23. data/lib/nanoc/data_sources/filesystem.rb +2 -0
  24. data/lib/nanoc/deploying/deployer.rb +1 -1
  25. data/lib/nanoc/deploying/deployers.rb +6 -9
  26. data/lib/nanoc/deploying/deployers/fog.rb +2 -0
  27. data/lib/nanoc/deploying/deployers/git.rb +118 -0
  28. data/lib/nanoc/deploying/deployers/rsync.rb +2 -0
  29. data/lib/nanoc/extra.rb +5 -6
  30. data/lib/nanoc/filters.rb +28 -55
  31. data/lib/nanoc/filters/asciidoc.rb +2 -0
  32. data/lib/nanoc/filters/bluecloth.rb +2 -0
  33. data/lib/nanoc/filters/coffeescript.rb +2 -0
  34. data/lib/nanoc/filters/colorize_syntax.rb +2 -0
  35. data/lib/nanoc/filters/erb.rb +2 -0
  36. data/lib/nanoc/filters/erubis.rb +9 -8
  37. data/lib/nanoc/filters/haml.rb +2 -0
  38. data/lib/nanoc/filters/handlebars.rb +2 -0
  39. data/lib/nanoc/filters/kramdown.rb +2 -0
  40. data/lib/nanoc/filters/less.rb +2 -0
  41. data/lib/nanoc/filters/markaby.rb +2 -0
  42. data/lib/nanoc/filters/maruku.rb +2 -0
  43. data/lib/nanoc/filters/mustache.rb +2 -0
  44. data/lib/nanoc/filters/pandoc.rb +2 -0
  45. data/lib/nanoc/filters/rainpress.rb +2 -0
  46. data/lib/nanoc/filters/rdiscount.rb +2 -0
  47. data/lib/nanoc/filters/rdoc.rb +2 -0
  48. data/lib/nanoc/filters/redcarpet.rb +2 -0
  49. data/lib/nanoc/filters/redcloth.rb +2 -0
  50. data/lib/nanoc/filters/relativize_paths.rb +2 -0
  51. data/lib/nanoc/filters/rubypants.rb +2 -0
  52. data/lib/nanoc/filters/sass.rb +2 -0
  53. data/lib/nanoc/filters/slim.rb +2 -0
  54. data/lib/nanoc/filters/typogruby.rb +2 -0
  55. data/lib/nanoc/filters/uglify_js.rb +2 -0
  56. data/lib/nanoc/filters/xsl.rb +2 -0
  57. data/lib/nanoc/filters/yui_compressor.rb +2 -0
  58. data/lib/nanoc/helpers.rb +12 -11
  59. data/lib/nanoc/version.rb +1 -1
  60. data/nanoc.gemspec +1 -0
  61. data/spec/nanoc/base/filter_spec.rb +2 -2
  62. data/spec/nanoc/cli/commands/deploy_spec.rb +2 -2
  63. data/spec/nanoc/cli/commands/show_plugins_spec.rb +18 -0
  64. data/spec/nanoc/deploying/git_spec.rb +302 -0
  65. data/spec/spec_helper.rb +2 -0
  66. data/test/deploying/test_git.rb +261 -0
  67. metadata +20 -5
  68. data/lib/nanoc/base/plugin_registry.rb +0 -219
  69. data/spec/nanoc/base/plugin_registry_spec.rb +0 -29
  70. data/test/base/test_plugin.rb +0 -26
data/spec/spec_helper.rb CHANGED
@@ -76,6 +76,8 @@ RSpec.configure do |c|
76
76
  end
77
77
  end
78
78
 
79
+ RSpec::Matchers.define_negated_matcher :not_match, :match
80
+
79
81
  RSpec::Matchers.define :raise_frozen_error do |_expected|
80
82
  match do |actual|
81
83
  begin
@@ -0,0 +1,261 @@
1
+ class Nanoc::Deploying::Deployers::GitTest < Nanoc::TestCase
2
+ def test_run_with_defaults_options
3
+ # Create deployer
4
+ git = Nanoc::Deploying::Deployers::Git.new(
5
+ 'output/',
6
+ {}
7
+ )
8
+
9
+ # Mock run_cmd
10
+ def git.run_cmd(args, _opts = {})
11
+ @shell_cmd_args = [] unless defined? @shell_cmd_args
12
+ @shell_cmd_args << args.join(' ')
13
+ end
14
+
15
+ # Mock clean_repo?
16
+ def git.clean_repo?
17
+ false
18
+ end
19
+
20
+ # Create output dir + repo
21
+ FileUtils.mkdir_p('output')
22
+ Dir.chdir('output') { system('git', 'init', '--quiet') }
23
+
24
+ # Try running
25
+ git.run
26
+
27
+ commands = <<-EOS
28
+ git config --get remote.origin.url
29
+ git checkout master
30
+ git add -A
31
+ git commit -a --author Nanoc <> -m Automated commit at .+ by Nanoc \\d+\\.\\d+\\.\\d+\\w*
32
+ git push origin master
33
+ EOS
34
+
35
+ assert_match Regexp.new(/^#{commands.chomp}$/), git.instance_eval { @shell_cmd_args.join("\n") }
36
+ end
37
+
38
+ def test_run_with_clean_repository
39
+ # Create deployer
40
+ git = Nanoc::Deploying::Deployers::Git.new(
41
+ 'output/',
42
+ {}
43
+ )
44
+
45
+ # Mock run_cmd
46
+ def git.run_cmd(args, _opts = {})
47
+ @shell_cmd_args = [] unless defined? @shell_cmd_args
48
+ @shell_cmd_args << args.join(' ')
49
+ end
50
+
51
+ # Mock clean_repo?
52
+ def git.clean_repo?
53
+ true
54
+ end
55
+
56
+ # Create output dir + repo
57
+ FileUtils.mkdir_p('output')
58
+ Dir.chdir('output') { system('git', 'init', '--quiet') }
59
+
60
+ # Try running
61
+ git.run
62
+
63
+ commands = <<-EOS
64
+ git config --get remote.origin.url
65
+ git checkout master
66
+ EOS
67
+
68
+ assert_match Regexp.new(/^#{commands.chomp}$/), git.instance_eval { @shell_cmd_args.join("\n") }
69
+ end
70
+
71
+ def test_run_with_custom_options
72
+ # Create deployer
73
+ git = Nanoc::Deploying::Deployers::Git.new(
74
+ 'output/',
75
+ remote: 'github', branch: 'gh-pages', forced: true,
76
+ )
77
+
78
+ # Mock run_cmd
79
+ def git.run_cmd(args, _opts = {})
80
+ @shell_cmd_args = [] unless defined? @shell_cmd_args
81
+ @shell_cmd_args << args.join(' ')
82
+ end
83
+
84
+ # Mock clean_repo?
85
+ def git.clean_repo?
86
+ false
87
+ end
88
+
89
+ # Create output dir + repo
90
+ FileUtils.mkdir_p('output')
91
+ Dir.chdir('output') { system('git', 'init', '--quiet') }
92
+
93
+ # Try running
94
+ git.run
95
+
96
+ commands = <<-EOS
97
+ git config --get remote.github.url
98
+ git checkout gh-pages
99
+ git add -A
100
+ git commit -a --author Nanoc <> -m Automated commit at .+ by Nanoc \\d+\\.\\d+\\.\\d+\\w*
101
+ git push -f github gh-pages
102
+ EOS
103
+
104
+ assert_match Regexp.new(/^#{commands.chomp}$/), git.instance_eval { @shell_cmd_args.join("\n") }
105
+ end
106
+
107
+ def test_run_without_git_init
108
+ # Create deployer
109
+ git = Nanoc::Deploying::Deployers::Git.new(
110
+ 'output/',
111
+ {}
112
+ )
113
+
114
+ # Mock run_cmd
115
+ def git.run_cmd(args, _opts = {})
116
+ @shell_cmd_args = [] unless defined? @shell_cmd_args
117
+ @shell_cmd_args << args.join(' ')
118
+ end
119
+
120
+ # Mock clean_repo?
121
+ def git.clean_repo?
122
+ false
123
+ end
124
+
125
+ # Create site
126
+ FileUtils.mkdir_p('output/.git')
127
+
128
+ # Try running
129
+ git.run
130
+
131
+ commands = <<-EOS
132
+ git config --get remote.origin.url
133
+ git checkout master
134
+ git add -A
135
+ git commit -a --author Nanoc <> -m Automated commit at .+ by Nanoc \\d+\\.\\d+\\.\\d+\\w*
136
+ git push origin master
137
+ EOS
138
+
139
+ assert_match Regexp.new(/^#{commands.chomp}$/), git.instance_eval { @shell_cmd_args.join("\n") }
140
+ end
141
+
142
+ def test_run_with_ssh_url
143
+ # Create deployer
144
+ git = Nanoc::Deploying::Deployers::Git.new(
145
+ 'output/',
146
+ remote: 'git@github.com:myself/myproject.git',
147
+ )
148
+
149
+ # Mock run_cmd
150
+ def git.run_cmd(args, _opts = {})
151
+ @shell_cmd_args = [] unless defined? @shell_cmd_args
152
+ @shell_cmd_args << args.join(' ')
153
+ end
154
+
155
+ # Mock clean_repo?
156
+ def git.clean_repo?
157
+ false
158
+ end
159
+
160
+ # Create output dir + repo
161
+ FileUtils.mkdir_p('output')
162
+ Dir.chdir('output') { system('git', 'init', '--quiet') }
163
+
164
+ # Try running
165
+ git.run
166
+
167
+ commands = <<-EOS
168
+ git checkout master
169
+ git add -A
170
+ git commit -a --author Nanoc <> -m Automated commit at .+ by Nanoc \\d+\\.\\d+\\.\\d+\\w*
171
+ git push git@github.com:myself/myproject.git master
172
+ EOS
173
+
174
+ assert_match Regexp.new(/^#{commands.chomp}$/), git.instance_eval { @shell_cmd_args.join("\n") }
175
+ end
176
+
177
+ def test_run_with_http_url
178
+ # Create deployer
179
+ git = Nanoc::Deploying::Deployers::Git.new(
180
+ 'output/',
181
+ remote: 'https://github.com/nanoc/nanoc.git',
182
+ )
183
+
184
+ # Mock run_cmd
185
+ def git.run_cmd(args, _opts = {})
186
+ @shell_cmd_args = [] unless defined? @shell_cmd_args
187
+ @shell_cmd_args << args.join(' ')
188
+ end
189
+
190
+ # Mock clean_repo?
191
+ def git.clean_repo?
192
+ false
193
+ end
194
+
195
+ # Create output dir + repo
196
+ FileUtils.mkdir_p('output')
197
+ Dir.chdir('output') { system('git', 'init', '--quiet') }
198
+
199
+ # Try running
200
+ git.run
201
+
202
+ commands = <<-EOS
203
+ git checkout master
204
+ git add -A
205
+ git commit -a --author Nanoc <> -m Automated commit at .+ by Nanoc \\d+\\.\\d+\\.\\d+\\w*
206
+ git push https://github.com/nanoc/nanoc.git master
207
+ EOS
208
+
209
+ assert_match Regexp.new(/^#{commands.chomp}$/), git.instance_eval { @shell_cmd_args.join("\n") }
210
+ end
211
+
212
+ def test_clean_repo_on_a_clean_repo
213
+ # Create deployer
214
+ git = Nanoc::Deploying::Deployers::Git.new(
215
+ 'output/',
216
+ remote: 'https://github.com/nanoc/nanoc.git',
217
+ )
218
+
219
+ FileUtils.mkdir_p('output')
220
+
221
+ piper = Nanoc::Extra::Piper.new(stdout: $stdout, stderr: $stderr)
222
+
223
+ Dir.chdir('output') do
224
+ piper.run('git init', nil)
225
+ assert git.send(:clean_repo?)
226
+ end
227
+ end
228
+
229
+ def test_clean_repo_on_a_dirty_repo
230
+ # Create deployer
231
+ git = Nanoc::Deploying::Deployers::Git.new(
232
+ 'output/',
233
+ remote: 'https://github.com/nanoc/nanoc.git',
234
+ )
235
+
236
+ FileUtils.mkdir_p('output')
237
+
238
+ piper = Nanoc::Extra::Piper.new(stdout: $stdout, stderr: $stderr)
239
+ Dir.chdir('output') do
240
+ piper.run('git init', nil)
241
+ FileUtils.touch('foobar')
242
+ refute git.send(:clean_repo?)
243
+ end
244
+ end
245
+
246
+ def test_clean_repo_not_git_repo
247
+ # Create deployer
248
+ git = Nanoc::Deploying::Deployers::Git.new(
249
+ 'output/',
250
+ remote: 'https://github.com/nanoc/nanoc.git',
251
+ )
252
+
253
+ FileUtils.mkdir_p('output')
254
+
255
+ Dir.chdir('output') do
256
+ assert_raises Nanoc::Extra::Piper::Error do
257
+ git.send(:clean_repo?)
258
+ end
259
+ end
260
+ end
261
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nanoc
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.4.7
4
+ version: 4.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Denis Defreyne
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-05 00:00:00.000000000 Z
11
+ date: 2017-01-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cri
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '2.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: ddplugin
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: bundler
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -146,7 +160,6 @@ files:
146
160
  - lib/nanoc/base/errors.rb
147
161
  - lib/nanoc/base/feature.rb
148
162
  - lib/nanoc/base/memoization.rb
149
- - lib/nanoc/base/plugin_registry.rb
150
163
  - lib/nanoc/base/repos.rb
151
164
  - lib/nanoc/base/repos/checksum_store.rb
152
165
  - lib/nanoc/base/repos/compiled_content_cache.rb
@@ -244,6 +257,7 @@ files:
244
257
  - lib/nanoc/deploying/deployer.rb
245
258
  - lib/nanoc/deploying/deployers.rb
246
259
  - lib/nanoc/deploying/deployers/fog.rb
260
+ - lib/nanoc/deploying/deployers/git.rb
247
261
  - lib/nanoc/deploying/deployers/rsync.rb
248
262
  - lib/nanoc/extra.rb
249
263
  - lib/nanoc/extra/core_ext.rb
@@ -329,7 +343,6 @@ files:
329
343
  - spec/nanoc/base/feature_spec.rb
330
344
  - spec/nanoc/base/filter_spec.rb
331
345
  - spec/nanoc/base/item_rep_writer_spec.rb
332
- - spec/nanoc/base/plugin_registry_spec.rb
333
346
  - spec/nanoc/base/repos/checksum_store_spec.rb
334
347
  - spec/nanoc/base/repos/compiled_content_cache_spec.rb
335
348
  - spec/nanoc/base/repos/config_loader_spec.rb
@@ -370,10 +383,12 @@ files:
370
383
  - spec/nanoc/cli/commands/deploy_spec.rb
371
384
  - spec/nanoc/cli/commands/shell_spec.rb
372
385
  - spec/nanoc/cli/commands/show_data_spec.rb
386
+ - spec/nanoc/cli/commands/show_plugins_spec.rb
373
387
  - spec/nanoc/cli/commands/show_rules_spec.rb
374
388
  - spec/nanoc/cli/commands/view_spec.rb
375
389
  - spec/nanoc/data_sources/filesystem_spec.rb
376
390
  - spec/nanoc/deploying/fog_spec.rb
391
+ - spec/nanoc/deploying/git_spec.rb
377
392
  - spec/nanoc/extra/parallel_collection_spec.rb
378
393
  - spec/nanoc/filters/colorize_syntax/rouge_spec.rb
379
394
  - spec/nanoc/filters/less_spec.rb
@@ -448,7 +463,6 @@ files:
448
463
  - test/base/test_memoization.rb
449
464
  - test/base/test_notification_center.rb
450
465
  - test/base/test_outdatedness_checker.rb
451
- - test/base/test_plugin.rb
452
466
  - test/base/test_site.rb
453
467
  - test/base/test_store.rb
454
468
  - test/checking/checks/test_css.rb
@@ -473,6 +487,7 @@ files:
473
487
  - test/data_sources/test_filesystem.rb
474
488
  - test/data_sources/test_filesystem_tools.rb
475
489
  - test/deploying/test_fog.rb
490
+ - test/deploying/test_git.rb
476
491
  - test/deploying/test_rsync.rb
477
492
  - test/extra/core_ext/test_pathname.rb
478
493
  - test/extra/core_ext/test_time.rb
@@ -1,219 +0,0 @@
1
- module Nanoc::Int
2
- # The class responsible for keeping track of all loaded plugins, such as
3
- # filters ({Nanoc::Filter}) and data sources ({Nanoc::DataSource}).
4
- #
5
- # @api private
6
- class PluginRegistry
7
- extend Nanoc::Int::Memoization
8
-
9
- # A module that contains class methods for plugins. It provides functions
10
- # for setting identifiers, registering plugins and finding plugins. Plugin
11
- # classes should extend this module.
12
- module PluginMethods
13
- # @overload identifiers(*identifiers)
14
- #
15
- # Sets the identifiers for this plugin.
16
- #
17
- # @param [Array<Symbol>] identifiers A list of identifiers to assign to
18
- # this plugin.
19
- #
20
- # @return [void]
21
- #
22
- # @overload identifiers
23
- #
24
- # @return [Array<Symbol>] The identifiers for this plugin
25
- def identifiers(*identifiers)
26
- if identifiers.empty?
27
- registry = Nanoc::Int::PluginRegistry.instance
28
- registry.identifiers_of(registry.root_class_of(self), self)
29
- else
30
- register(self, *identifiers)
31
- end
32
- end
33
-
34
- # @overload identifier(identifier)
35
- #
36
- # Sets the identifier for this plugin.
37
- #
38
- # @param [Symbol] identifier An identifier to assign to this plugin.
39
- #
40
- # @return [void]
41
- #
42
- # @overload identifier
43
- #
44
- # @return [Symbol] The first identifier for this plugin
45
- def identifier(identifier = nil)
46
- if identifier
47
- identifiers(identifier)
48
- else
49
- registry = Nanoc::Int::PluginRegistry.instance
50
- registry.identifiers_of(registry.root_class_of(self), self).first
51
- end
52
- end
53
-
54
- # Registers the given class as a plugin with the given identifier.
55
- #
56
- # @param [Class, String] class_or_name The class to register, or a
57
- # string containing the class name to register.
58
- #
59
- # @param [Array<Symbol>] identifiers A list of identifiers to assign to
60
- # this plugin.
61
- #
62
- # @return [void]
63
- def register(class_or_name, *identifiers)
64
- registry = Nanoc::Int::PluginRegistry.instance
65
- root = registry.root_class_of(self)
66
- registry.register(root, class_or_name, *identifiers)
67
- end
68
-
69
- # @return [Hash<Symbol, Class>] All plugins of this type, with keys
70
- # being the identifiers and values the plugin classes
71
- def all
72
- Nanoc::Int::PluginRegistry.instance.find_all(self)
73
- end
74
-
75
- # Returns the plugin with the given name (identifier)
76
- #
77
- # @param [String] name The name of the plugin class to find
78
- #
79
- # @return [Class] The plugin class with the given name
80
- def named(name)
81
- Nanoc::Int::PluginRegistry.instance.find(self, name)
82
- end
83
- end
84
-
85
- # Returns the shared {PluginRegistry} instance, creating it if none exists
86
- # yet.
87
- #
88
- # @return [Nanoc::Int::PluginRegistry] The shared plugin registry
89
- def self.instance
90
- @instance ||= new
91
- end
92
-
93
- # Creates a new plugin registry. This should usually not be necessary; it
94
- # is recommended to use the shared instance (obtained from
95
- # {Nanoc::Int::PluginRegistry.instance}).
96
- def initialize
97
- @identifiers_to_classes = {}
98
- @classes_to_identifiers = {}
99
- end
100
-
101
- # Registers the given class as a plugin.
102
- #
103
- # @param [Class] superclass The superclass of the plugin. For example:
104
- # {Nanoc::Filter}.
105
- #
106
- # @param [Class, String] class_or_name The class to register. This can be
107
- # a string, in which case it will be automatically converted to a proper
108
- # class at lookup. For example: `Nanoc::Filters::ERB`,
109
- # `"Nanoc::Filters::Haml"`.
110
- #
111
- # @param [Symbol] identifiers One or more symbols identifying the class.
112
- # For example: `:haml`, :`erb`.
113
- #
114
- # @return [void]
115
- def register(superclass, class_or_name, *identifiers)
116
- @identifiers_to_classes[superclass] ||= {}
117
- @classes_to_identifiers[superclass] ||= {}
118
-
119
- identifiers.each do |identifier|
120
- @identifiers_to_classes[superclass][identifier.to_sym] = class_or_name
121
- (@classes_to_identifiers[superclass][name_for_class(class_or_name)] ||= []) << identifier.to_sym
122
- end
123
- end
124
-
125
- # @param [Class] superclass The superclass of the plugin. For example:
126
- # {Nanoc::Filter}.
127
- #
128
- # @param [Class] klass The class to get the identifiers for.
129
- #
130
- # @return [Array<Symbol>] An array of identifiers for the given class
131
- def identifiers_of(superclass, klass)
132
- (@classes_to_identifiers[superclass] || {})[name_for_class(klass)] || []
133
- end
134
-
135
- # Finds the plugin that is a subclass of the given class and has the given
136
- # name.
137
- #
138
- # @param [Class] klass The class of the plugin to return
139
- #
140
- # @param [Symbol] name The name of the plugin to return
141
- #
142
- # @return [Class, nil] The plugin with the given name
143
- def find(klass, name)
144
- @identifiers_to_classes[klass] ||= {}
145
- resolve(@identifiers_to_classes[klass][name.to_sym], klass)
146
- end
147
-
148
- # Returns all plugins of the given class.
149
- #
150
- # @param [Class] klass The class of the plugin to return
151
- #
152
- # @return [Enumerable<Class>] A collection of class plugins
153
- def find_all(klass)
154
- @identifiers_to_classes[klass] ||= {}
155
- res = {}
156
- @identifiers_to_classes[klass].each_pair { |k, v| res[k] = resolve(v, k) }
157
- res
158
- end
159
-
160
- # @param [Class] subclass
161
- #
162
- # @return [Class]
163
- #
164
- # @api private
165
- def root_class_of(subclass)
166
- root_class = subclass
167
- root_class = root_class.superclass while root_class.superclass.respond_to?(:register)
168
- root_class
169
- end
170
-
171
- # Returns a list of all plugins. The returned list of plugins is an array
172
- # with array elements in the following format:
173
- #
174
- # { :class => ..., :superclass => ..., :identifiers => ... }
175
- #
176
- # @return [Array<Hash>] A list of all plugins in the format described
177
- def all
178
- plugins = []
179
- @identifiers_to_classes.each_pair do |superclass, submap|
180
- submap.each_pair do |identifier, klass|
181
- # Find existing plugin
182
- existing_plugin = plugins.find do |p|
183
- p[:class] == klass && p[:superclass] == superclass
184
- end
185
-
186
- if existing_plugin
187
- # Add identifier to existing plugin
188
- existing_plugin[:identifiers] << identifier
189
- existing_plugin[:identifiers] = existing_plugin[:identifiers].sort_by(&:to_s)
190
- else
191
- # Create new plugin
192
- plugins << {
193
- class: klass,
194
- superclass: superclass,
195
- identifiers: [identifier],
196
- }
197
- end
198
- end
199
- end
200
-
201
- plugins
202
- end
203
-
204
- protected
205
-
206
- def resolve(class_or_name, _klass)
207
- if class_or_name.is_a?(String)
208
- Kernel.const_get(class_or_name)
209
- else
210
- class_or_name
211
- end
212
- end
213
- memoize :resolve
214
-
215
- def name_for_class(klass)
216
- klass.to_s.sub(/^(::)?/, '::')
217
- end
218
- end
219
- end