r2-oas 0.3.1 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +50 -0
- data/GEMSPEC.md +2 -2
- data/README.ja.md +54 -37
- data/README.md +55 -32
- data/lib/r2-oas.rb +4 -5
- data/lib/r2-oas/app_configuration.rb +17 -5
- data/lib/r2-oas/app_configuration/deprecation.rb +28 -0
- data/lib/r2-oas/configuration.rb +56 -0
- data/lib/r2-oas/deploy/client.rb +21 -6
- data/lib/r2-oas/{plugins/schema/v3/object → dynamic/schema/v3/object/from_routes}/hookable_base_object.rb +7 -7
- data/lib/r2-oas/errors.rb +5 -0
- data/lib/r2-oas/hooks/hook.rb +7 -5
- data/lib/r2-oas/lib/core_ext/all.rb +5 -0
- data/lib/r2-oas/lib/core_ext/string/filters.rb +29 -0
- data/lib/r2-oas/pluggable_configuration.rb +8 -5
- data/lib/r2-oas/plugin/base.rb +44 -0
- data/lib/r2-oas/plugin/executor.rb +148 -0
- data/lib/r2-oas/plugin/hookable.rb +42 -0
- data/lib/r2-oas/plugin/public.rb +3 -0
- data/lib/r2-oas/plugin/transform/transform.rb +10 -0
- data/lib/r2-oas/plugin/transform/v3/transform.rb +20 -0
- data/lib/r2-oas/plugin/transform/v3/visitable.rb +37 -0
- data/lib/r2-oas/public.rb +5 -0
- data/lib/r2-oas/schema/base.rb +1 -1
- data/lib/r2-oas/schema/builder.rb +1 -1
- data/lib/r2-oas/schema/editor.rb +8 -1
- data/lib/r2-oas/schema/v3/analyzer/path_analyzer.rb +1 -1
- data/lib/r2-oas/schema/v3/builder.rb +1 -1
- data/lib/r2-oas/schema/v3/builder/base_builder.rb +14 -2
- data/lib/r2-oas/schema/v3/builder/doc_builder.rb +10 -2
- data/lib/r2-oas/schema/v3/generator/base_generator.rb +7 -2
- data/lib/r2-oas/schema/v3/generator/doc_generator.rb +1 -1
- data/lib/r2-oas/schema/v3/manager/file/include_ref_base_file_manager.rb +3 -2
- data/lib/r2-oas/schema/v3/object/from_files/base_object.rb +62 -0
- data/lib/r2-oas/schema/v3/object/from_files/components/request_body_object.rb +103 -0
- data/lib/r2-oas/schema/v3/object/from_files/components/schema_object.rb +102 -0
- data/lib/r2-oas/schema/v3/object/from_files/components_object.rb +46 -0
- data/lib/r2-oas/schema/v3/object/from_files/external_document_object.rb +23 -0
- data/lib/r2-oas/schema/v3/object/from_files/info_object.rb +23 -0
- data/lib/r2-oas/schema/v3/object/from_files/openapi_object.rb +61 -0
- data/lib/r2-oas/schema/v3/object/from_files/path_item_object.rb +110 -0
- data/lib/r2-oas/schema/v3/object/from_files/paths_object.rb +33 -0
- data/lib/r2-oas/schema/v3/object/from_files/utils/all.rb +4 -0
- data/lib/r2-oas/schema/v3/object/from_files/utils/deep_methods.rb +27 -0
- data/lib/r2-oas/schema/v3/object/from_files/utils/refs.rb +151 -0
- data/lib/r2-oas/schema/v3/object/{base_object.rb → from_routes/base_object.rb} +11 -1
- data/lib/r2-oas/schema/v3/object/{components → from_routes/components}/request_body_object.rb +23 -19
- data/lib/r2-oas/schema/v3/object/{components → from_routes/components}/schema_object.rb +16 -12
- data/lib/r2-oas/schema/v3/object/{components_object.rb → from_routes/components_object.rb} +11 -11
- data/lib/r2-oas/schema/v3/object/from_routes/external_document_object.rb +28 -0
- data/lib/r2-oas/schema/v3/object/{info_object.rb → from_routes/info_object.rb} +11 -2
- data/lib/r2-oas/schema/v3/object/{openapi_object.rb → from_routes/openapi_object.rb} +12 -11
- data/lib/r2-oas/schema/v3/object/{path_item_object.rb → from_routes/path_item_object.rb} +6 -6
- data/lib/r2-oas/schema/v3/object/{paths_object.rb → from_routes/paths_object.rb} +11 -8
- data/lib/r2-oas/schema/v3/object/{public.rb → from_routes/public.rb} +0 -0
- data/lib/r2-oas/schema/v3/object/{server_object.rb → from_routes/server_object.rb} +0 -0
- data/lib/r2-oas/schema/v3/object/{tag_object.rb → from_routes/tag_object.rb} +2 -1
- data/lib/r2-oas/schema/v3/object/store.rb +54 -0
- data/lib/r2-oas/shared/all.rb +1 -0
- data/lib/r2-oas/shared/callable.rb +17 -0
- data/lib/r2-oas/store.rb +20 -16
- data/lib/r2-oas/support/deprecation.rb +26 -0
- data/lib/r2-oas/support/deprecation/behavior.rb +21 -0
- data/lib/r2-oas/support/deprecation/instance_delegator.rb +42 -0
- data/lib/r2-oas/support/deprecation/reporting.rb +91 -0
- data/lib/r2-oas/task.rb +1 -2
- data/lib/r2-oas/task_logging.rb +3 -7
- data/lib/r2-oas/tasks/common.rake +1 -2
- data/lib/r2-oas/tasks/main.rake +60 -9
- data/lib/r2-oas/version.rb +1 -1
- data/r2-oas.gemspec +1 -6
- metadata +51 -110
- data/.github/ISSUE_TEMPLATE.md +0 -12
- data/.github/PULL_REQUEST_TEMPLATE.md +0 -12
- data/.gitignore +0 -16
- data/.rspec +0 -3
- data/.rubocop.yml +0 -10
- data/.rubocop_todo.yml +0 -291
- data/.travis.yml +0 -26
- data/Appraisals +0 -13
- data/CODE_OF_CONDUCT.md +0 -74
- data/Gemfile +0 -12
- data/Rakefile +0 -8
- data/bin/console +0 -12
- data/bin/setup +0 -8
- data/devscript/all_support_ruby.sh +0 -43
- data/devscript/bundle_for_all_support_ruby.sh +0 -31
- data/devscript/rspec_for_all_support_ruby.sh +0 -27
- data/docs/.nojekyll +0 -0
- data/docs/README.md +0 -173
- data/docs/_sidebar.md +0 -25
- data/docs/attention/if_clash.md +0 -17
- data/docs/index.html +0 -29
- data/docs/schema/3.0.0.md +0 -155
- data/docs/setting/COC.md +0 -14
- data/docs/setting/CORS.md +0 -22
- data/docs/setting/configure.md +0 -176
- data/docs/trableshouting/runtime_error.md +0 -44
- data/docs/usage/analyze_docs.md +0 -875
- data/docs/usage/clean_docs.md +0 -19
- data/docs/usage/deploy_docs.md +0 -839
- data/docs/usage/display_paths_list.md +0 -35
- data/docs/usage/display_paths_stats.md +0 -54
- data/docs/usage/edit_docs.md +0 -218
- data/docs/usage/generate_docs.md +0 -412
- data/docs/usage/monitor_docs.md +0 -219
- data/docs/usage/use_hook_methods.md +0 -236
- data/docs/usage/use_hook_to_generate_docs.md +0 -235
- data/docs/usage/use_schema_namespace.md +0 -181
- data/docs/usage/use_tag_namespace.md +0 -180
- data/docs/usage/view_docs.md +0 -262
- data/gemfiles/ruby_2.3.3.gemfile +0 -11
- data/gemfiles/ruby_2.4.2.gemfile +0 -11
- data/gemfiles/ruby_2.5.8.gemfile +0 -11
- data/gemfiles/ruby_2.6.6.gemfile +0 -11
- data/gemfiles/ruby_2.7.1.gemfile +0 -11
- data/lib/r2-oas/app_configuration/tool.rb +0 -31
- data/lib/r2-oas/app_configuration/tool/paths/stats.rb +0 -43
- data/lib/r2-oas/deploy/swagger-ui/dist/favicon-16x16.png +0 -0
- data/lib/r2-oas/deploy/swagger-ui/dist/favicon-32x32.png +0 -0
- data/lib/r2-oas/deploy/swagger-ui/dist/oauth2-redirect.html +0 -68
- data/lib/r2-oas/deploy/swagger-ui/dist/swagger-ui-bundle.js +0 -134
- data/lib/r2-oas/deploy/swagger-ui/dist/swagger-ui-bundle.js.map +0 -1
- data/lib/r2-oas/deploy/swagger-ui/dist/swagger-ui-standalone-preset.js +0 -22
- data/lib/r2-oas/deploy/swagger-ui/dist/swagger-ui-standalone-preset.js.map +0 -1
- data/lib/r2-oas/deploy/swagger-ui/dist/swagger-ui.css +0 -4
- data/lib/r2-oas/deploy/swagger-ui/dist/swagger-ui.css.map +0 -1
- data/lib/r2-oas/deploy/swagger-ui/dist/swagger-ui.js +0 -9
- data/lib/r2-oas/deploy/swagger-ui/dist/swagger-ui.js.map +0 -1
- data/lib/r2-oas/schema/v3/object/external_document_object.rb +0 -19
- data/lib/r2-oas/tasks/tool.rake +0 -76
- data/lib/r2-oas/tool/paths/ls.rb +0 -15
- data/lib/r2-oas/tool/paths/stats.rb +0 -84
data/lib/r2-oas/deploy/client.rb
CHANGED
@@ -6,22 +6,33 @@ require 'fileutils'
|
|
6
6
|
module R2OAS
|
7
7
|
module Deploy
|
8
8
|
class Client < Schema::Base
|
9
|
+
SWAGGER_UI_DIST_URL = 'https://github.com/swagger-api/swagger-ui/trunk/dist'
|
10
|
+
|
11
|
+
def initialize(options = {})
|
12
|
+
super(options)
|
13
|
+
@download_dir = "#{SecureRandom.uuid[0..7]}/dist"
|
14
|
+
@dist_path = File.expand_path(Rails.root.join(@download_dir), __FILE__)
|
15
|
+
end
|
16
|
+
|
17
|
+
def download_swagger_ui_dist
|
18
|
+
system("svn export #{SWAGGER_UI_DIST_URL} #{@dist_path}")
|
19
|
+
end
|
20
|
+
|
9
21
|
def deploy
|
10
22
|
copy_swagger_ui_dist
|
11
23
|
copy_swagger_ui_index
|
12
24
|
copy_oas_doc_file
|
25
|
+
ensure
|
26
|
+
remove_download_dist
|
13
27
|
end
|
14
28
|
|
15
29
|
private
|
16
30
|
|
17
31
|
def copy_swagger_ui_dist
|
18
32
|
docs_path = File.expand_path(Rails.root.join(deploy_dir_path), __FILE__)
|
19
|
-
return if FileTest.exists?(docs_path)
|
20
|
-
|
21
33
|
FileUtils.mkdir_p(docs_path) unless FileTest.exists?(docs_path)
|
22
|
-
|
23
|
-
|
24
|
-
FileUtils.cp_r(dist_path, docs_path)
|
34
|
+
FileUtils.mkdir_p(@dist_path) unless FileTest.exists?(@dist_path)
|
35
|
+
FileUtils.cp_r(@dist_path, docs_path)
|
25
36
|
end
|
26
37
|
|
27
38
|
def copy_swagger_ui_index
|
@@ -35,10 +46,14 @@ module R2OAS
|
|
35
46
|
|
36
47
|
def copy_oas_doc_file
|
37
48
|
swagger_file_path = File.expand_path(Rails.root.join(deploy_dir_path, doc_save_file_name), __FILE__)
|
38
|
-
oas_doc_file_path = File.expand_path(
|
49
|
+
oas_doc_file_path = File.expand_path(output_path)
|
39
50
|
FileUtils.cp_r(oas_doc_file_path, swagger_file_path)
|
40
51
|
end
|
41
52
|
|
53
|
+
def remove_download_dist
|
54
|
+
FileUtils.rm_rf(File.expand_path('..', @dist_path))
|
55
|
+
end
|
56
|
+
|
42
57
|
# [ref]
|
43
58
|
# https://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Lint/ErbNewArguments
|
44
59
|
def make_index(template)
|
@@ -1,10 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'r2-oas/schema/v3/object/base_object'
|
3
|
+
require 'r2-oas/schema/v3/object/from_routes/base_object'
|
4
4
|
require 'r2-oas/hooks/hook'
|
5
5
|
|
6
6
|
module R2OAS
|
7
|
-
module
|
7
|
+
module Dynamic
|
8
8
|
module Schema
|
9
9
|
module V3
|
10
10
|
class HookableBaseObject < R2OAS::Schema::V3::BaseObject
|
@@ -22,11 +22,11 @@ module R2OAS
|
|
22
22
|
|
23
23
|
def self.inherited(base)
|
24
24
|
base.extend ClassMethods
|
25
|
-
self.hook = Hooks::Hook.register(base)
|
25
|
+
self.hook = Hooks::Hook.register(:dynamic, base)
|
26
26
|
end
|
27
27
|
|
28
28
|
def self.hooks
|
29
|
-
superclass.hook.repository[self].global_hooks_data
|
29
|
+
superclass.hook.repository[:dynamic][self].global_hooks_data
|
30
30
|
end
|
31
31
|
|
32
32
|
def self.hook=(value)
|
@@ -58,8 +58,8 @@ module R2OAS
|
|
58
58
|
|
59
59
|
attr_accessor :doc
|
60
60
|
|
61
|
-
def initialize
|
62
|
-
super
|
61
|
+
def initialize(opts = {})
|
62
|
+
super(opts)
|
63
63
|
self.doc = {}
|
64
64
|
end
|
65
65
|
|
@@ -72,7 +72,7 @@ module R2OAS
|
|
72
72
|
end
|
73
73
|
|
74
74
|
def use_superclass_hook
|
75
|
-
self.class.hook.repository[self.class] = self.class.hook.repository[self.class.superclass]
|
75
|
+
self.class.hook.repository[:dynamic][self.class] = self.class.hook.repository[:dynamic][self.class.superclass]
|
76
76
|
end
|
77
77
|
|
78
78
|
private
|
data/lib/r2-oas/errors.rb
CHANGED
@@ -5,4 +5,9 @@ module R2OAS
|
|
5
5
|
class NoFileExistsError < StandardError; end
|
6
6
|
class NoSupportError < StandardError; end
|
7
7
|
class ChecksumError < StandardError; end
|
8
|
+
class PluginNameError < StandardError; end
|
9
|
+
class PluginDuplicationError < StandardError; end
|
10
|
+
class PluginLoadError < StandardError; end
|
11
|
+
class DepulicateSchemaNameError < StandardError; end
|
12
|
+
class RefInvalidAssignment < StandardError; end
|
8
13
|
end
|
data/lib/r2-oas/hooks/hook.rb
CHANGED
@@ -12,19 +12,21 @@ module R2OAS
|
|
12
12
|
class << self
|
13
13
|
attr_accessor :repository
|
14
14
|
|
15
|
-
def register(target_class)
|
15
|
+
def register(type, target_class)
|
16
16
|
@repository ||= {}
|
17
|
+
@repository[type] ||= {}
|
18
|
+
@type = type
|
17
19
|
@hooks ||= {}
|
18
|
-
@repository[target_class] = Repository.new(target_class)
|
20
|
+
@repository[type][target_class] = Repository.new(target_class)
|
19
21
|
self
|
20
22
|
end
|
21
23
|
|
22
24
|
def on(on, callback, target_class, once = false)
|
23
|
-
target_repository = @repository[target_class]
|
25
|
+
target_repository = @repository[@type][target_class]
|
24
26
|
uid = target_repository.last_hook_id + 1
|
25
27
|
target_repository.last_hook_id = uid
|
26
28
|
|
27
|
-
|
29
|
+
target_repository.global_hooks_data[on] ||= []
|
28
30
|
global_hook = GlobalHook.new(callback, once, uid, target_class)
|
29
31
|
|
30
32
|
target_repository.global_hooks_data[on].push(global_hook)
|
@@ -34,7 +36,7 @@ module R2OAS
|
|
34
36
|
|
35
37
|
# MEMO: Do not Use
|
36
38
|
def off(uid, target_class)
|
37
|
-
target_repository = @repository[target_class]
|
39
|
+
target_repository = @repository[@type][target_class]
|
38
40
|
result = uid
|
39
41
|
|
40
42
|
target_repository.global_hooks_data.each do |on|
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copy from https://github.com/rails/rails/blob/45b609c9964242f5c169d913c612eedce2a47397/activesupport/lib/active_support/core_ext/string/filters.rb#L11
|
4
|
+
|
5
|
+
class String
|
6
|
+
# Returns the string, first removing all whitespace on both ends of
|
7
|
+
# the string, and then changing remaining consecutive whitespace
|
8
|
+
# groups into one space each.
|
9
|
+
#
|
10
|
+
# Note that it handles both ASCII and Unicode whitespace.
|
11
|
+
#
|
12
|
+
# %{ Multi-line
|
13
|
+
# string }.squish # => "Multi-line string"
|
14
|
+
# " foo bar \n \t boo".squish # => "foo bar boo"
|
15
|
+
def squish
|
16
|
+
dup.squish!
|
17
|
+
end
|
18
|
+
|
19
|
+
# Performs a destructive squish. See String#squish.
|
20
|
+
# str = " foo bar \n \t boo"
|
21
|
+
# str.squish! # => "foo bar boo"
|
22
|
+
# str # => "foo bar boo"
|
23
|
+
def squish!
|
24
|
+
gsub!(/\A[[:space:]]+/, '')
|
25
|
+
gsub!(/[[:space:]]+\z/, '')
|
26
|
+
gsub!(/[[:space:]]+/, ' ')
|
27
|
+
self
|
28
|
+
end
|
29
|
+
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
require 'r2-oas/schema/v3/object/from_routes/public'
|
4
|
+
require_relative 'support/deprecation'
|
4
5
|
|
5
6
|
module R2OAS
|
6
7
|
module PluggableConfiguration
|
@@ -16,18 +17,20 @@ module R2OAS
|
|
16
17
|
}
|
17
18
|
# rubocop:enable Style/MutableConstant
|
18
19
|
|
19
|
-
VALID_OPTIONS_KEYS = [
|
20
|
-
|
20
|
+
VALID_OPTIONS_KEYS = %i[
|
21
|
+
use_object_classes
|
21
22
|
].freeze
|
22
23
|
|
23
|
-
|
24
|
+
attr_reader *VALID_OPTIONS_KEYS
|
24
25
|
|
25
26
|
private
|
26
27
|
|
27
28
|
module_function
|
28
29
|
|
29
30
|
def set_default(target)
|
30
|
-
|
31
|
+
Deprecation.silence do
|
32
|
+
target.use_object_classes = DEFAULT_USE_OBJECT_CLASSES
|
33
|
+
end
|
31
34
|
end
|
32
35
|
end
|
33
36
|
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'r2-oas/base'
|
4
|
+
require 'r2-oas/hooks/hook'
|
5
|
+
require_relative 'hookable'
|
6
|
+
|
7
|
+
module R2OAS
|
8
|
+
module Plugin
|
9
|
+
class Base < ::R2OAS::Base
|
10
|
+
extend ::R2OAS::Plugin::Hookable
|
11
|
+
|
12
|
+
class << self
|
13
|
+
attr_accessor :plugin_name, :type, :opts
|
14
|
+
|
15
|
+
def setup(&block)
|
16
|
+
return unless block_given?
|
17
|
+
|
18
|
+
callback = proc { |*args| block.call(*args) }
|
19
|
+
on(:setup, callback)
|
20
|
+
end
|
21
|
+
|
22
|
+
def teardown(&block)
|
23
|
+
return unless block_given?
|
24
|
+
|
25
|
+
callback = proc { |*args| block.call(*args) }
|
26
|
+
on(:teardown, callback)
|
27
|
+
end
|
28
|
+
|
29
|
+
def execute_setup(*args)
|
30
|
+
execute_hook(:setup, *args)
|
31
|
+
end
|
32
|
+
|
33
|
+
def execute_teardown(*args)
|
34
|
+
execute_hook(:teardown, *args)
|
35
|
+
end
|
36
|
+
|
37
|
+
def inherited(base)
|
38
|
+
super
|
39
|
+
base.opts = {}
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,148 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'hookable'
|
4
|
+
require 'r2-oas/errors'
|
5
|
+
|
6
|
+
module R2OAS
|
7
|
+
module Plugin
|
8
|
+
class Executor
|
9
|
+
extend ::R2OAS::Plugin::Hookable
|
10
|
+
|
11
|
+
def initialize(plugins, opts)
|
12
|
+
@plugins = plugins
|
13
|
+
@use_plugin = !!opts[:use_plugin]
|
14
|
+
end
|
15
|
+
|
16
|
+
def execute_transform_plugins(hook_method, *args)
|
17
|
+
return unless @use_plugin
|
18
|
+
return unless @plugins.present?
|
19
|
+
|
20
|
+
@plugin_map ||= self.class.plugin_map(@plugins)
|
21
|
+
|
22
|
+
self.class.execute_transform_plugins(@plugin_map, hook_method, *args)
|
23
|
+
end
|
24
|
+
|
25
|
+
class << self
|
26
|
+
attr_accessor :plugin_map
|
27
|
+
|
28
|
+
def execute_transform_plugins(plugin_map, hook_method, *args)
|
29
|
+
execute_plugins(plugin_map, :transform, hook_method, *args)
|
30
|
+
end
|
31
|
+
|
32
|
+
def execute_plugins(plugin_map, type, hook_method, *args)
|
33
|
+
return unless plugin_map.present?
|
34
|
+
|
35
|
+
plugins_info = plugin_map[type.to_sym][hook_method.to_sym]
|
36
|
+
|
37
|
+
return if plugins_info.nil?
|
38
|
+
|
39
|
+
plugins_info.each do |info|
|
40
|
+
opts = info[:plugin_opts]
|
41
|
+
klass = info[:plugin_klass]
|
42
|
+
klass.send(:opts=, opts) if opts.present?
|
43
|
+
klass.send(info[:execute_hook_method], *args)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# e.g.)
|
48
|
+
# {
|
49
|
+
# transform: {
|
50
|
+
# setup: [
|
51
|
+
# { plugin_name: 'r2oas-transform-plugin-sample1', plugin_klass: Sample1Plugin, hook_method: :setup },
|
52
|
+
# { plugin_name: 'r2oas-transform-plugin-sample2', plugin_klass: Sample2Plugin, hook_method: :setup },
|
53
|
+
# ],
|
54
|
+
# info: [
|
55
|
+
# { plugin_name: 'r2oas-transform-plugin-sample1', plugin_klass: Sample1Plugin, hook_method: :info },
|
56
|
+
# ]
|
57
|
+
# }
|
58
|
+
# }
|
59
|
+
#
|
60
|
+
def plugin_map(plugins)
|
61
|
+
@plugin_map ||= {}
|
62
|
+
return @plugin_map if @plugin_map.present?
|
63
|
+
|
64
|
+
@will_plugins = []
|
65
|
+
|
66
|
+
use_plugins_info = create_use_plugins_info(plugins)
|
67
|
+
|
68
|
+
loaded_plugins_hooks_map = hooks_map.each_with_object({}) do |(klass, repo), result|
|
69
|
+
# MEMO:
|
70
|
+
# klass may be DynamicSchema or Plugin or Other Class
|
71
|
+
next unless klass.respond_to?(:plugin_name)
|
72
|
+
# Plugins that are loaded but not used
|
73
|
+
next unless use_plugins_info.keys.include?(klass.plugin_name)
|
74
|
+
|
75
|
+
result[klass.plugin_name] = { klass: klass, repo: repo }
|
76
|
+
end
|
77
|
+
|
78
|
+
unknown_plugins = use_plugins_info.keys - loaded_plugins_hooks_map.keys
|
79
|
+
|
80
|
+
raise R2OAS::PluginLoadError, "The '#{unknown_plugins.join(', ')}' plugin doesn't exist or can't be loaded" if unknown_plugins.present?
|
81
|
+
|
82
|
+
loaded_plugins_hooks_map.each do |plugin_name, info|
|
83
|
+
plugin_klass = info[:klass]
|
84
|
+
repo = info[:repo]
|
85
|
+
|
86
|
+
repo.global_hooks_data.each do |hook_method, callbacks|
|
87
|
+
callbacks.each do
|
88
|
+
plugin_type = plugin_klass.type
|
89
|
+
|
90
|
+
data = {
|
91
|
+
plugin_name: plugin_name,
|
92
|
+
plugin_klass: plugin_klass,
|
93
|
+
plugin_opts: use_plugins_info[plugin_name],
|
94
|
+
execute_hook_method: "execute_#{hook_method}"
|
95
|
+
}
|
96
|
+
|
97
|
+
if @plugin_map[plugin_type].present?
|
98
|
+
if @plugin_map[plugin_type][hook_method].present?
|
99
|
+
@plugin_map[plugin_type][hook_method].push(data)
|
100
|
+
else
|
101
|
+
@plugin_map[plugin_type][hook_method] = [data]
|
102
|
+
end
|
103
|
+
else
|
104
|
+
@plugin_map[plugin_type] = {}
|
105
|
+
@plugin_map[plugin_type][hook_method] = [data]
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
@plugin_map
|
112
|
+
end
|
113
|
+
|
114
|
+
def create_use_plugins_info(plugins)
|
115
|
+
will_use_plugins = []
|
116
|
+
result = {}
|
117
|
+
|
118
|
+
plugins.each do |plugin_info|
|
119
|
+
case plugin_info
|
120
|
+
when Array
|
121
|
+
plugin_name = plugin_info[0]
|
122
|
+
plugin_opts = plugin_info[1]
|
123
|
+
|
124
|
+
raise PluginNameError, 'Missing plugin name' if plugin_name.blank?
|
125
|
+
|
126
|
+
result[plugin_name] = plugin_opts
|
127
|
+
when String
|
128
|
+
plugin_name = plugin_info
|
129
|
+
plugin_opts = nil
|
130
|
+
|
131
|
+
result[plugin_name] = plugin_opts
|
132
|
+
else
|
133
|
+
raise NoSupportError, "The plugin loading format '#{plugin_info.class}' is incorrect"
|
134
|
+
end
|
135
|
+
|
136
|
+
if will_use_plugins.include?(plugin_name)
|
137
|
+
raise PluginDuplicationError, "Plugin: duplicate '#{plugin_name}'"
|
138
|
+
else
|
139
|
+
will_use_plugins.push(plugin_name)
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
result
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'r2-oas/hooks/hook'
|
4
|
+
|
5
|
+
module R2OAS
|
6
|
+
module Plugin
|
7
|
+
module Hookable
|
8
|
+
def hooks_map
|
9
|
+
hook_klass.repository[:plugin]
|
10
|
+
end
|
11
|
+
|
12
|
+
def hooks
|
13
|
+
hooks_map[self].global_hooks_data
|
14
|
+
end
|
15
|
+
|
16
|
+
def hook_klass=(klass)
|
17
|
+
@@hook_klass = klass
|
18
|
+
end
|
19
|
+
|
20
|
+
def hook_klass
|
21
|
+
@@hook_klass
|
22
|
+
end
|
23
|
+
|
24
|
+
def on(on, callback, once = false)
|
25
|
+
hook_klass.on(on, callback, self, once)
|
26
|
+
end
|
27
|
+
|
28
|
+
# MEMO: Do not Use
|
29
|
+
def off(on, callback, once = false)
|
30
|
+
hook_klass.off(on, callback, self, once)
|
31
|
+
end
|
32
|
+
|
33
|
+
def execute_hook(on, *data)
|
34
|
+
hook_klass.execute_hook(on, *data, self)
|
35
|
+
end
|
36
|
+
|
37
|
+
def has_hook?(name)
|
38
|
+
hook_klass.has_hook?(name, self)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|