r2-oas 0.4.0 → 0.4.1
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/CHANGELOG.md +11 -0
- data/README.md +5 -1
- data/lib/r2-oas.rb +1 -2
- data/lib/r2-oas/app_configuration.rb +0 -4
- data/lib/r2-oas/configuration.rb +8 -4
- 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/support/deprecation.rb +2 -0
- data/lib/r2-oas/task.rb +1 -2
- data/lib/r2-oas/tasks/main.rake +30 -1
- data/lib/r2-oas/version.rb +1 -1
- data/r2-oas.gemspec +0 -2
- metadata +6 -37
- 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/tasks/tool.rake +0 -86
- data/lib/r2-oas/tool/paths/ls.rb +0 -15
- data/lib/r2-oas/tool/paths/stats.rb +0 -84
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a6ff37fb9f530ea30d7a06154dd6036ae63fdbd1358cab2d38bad3b2fd6334fc
|
4
|
+
data.tar.gz: 99f6574107d260c8961d645c1dfbc29b19143b19d5a903554e4576be39280f9f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 964aefff2e439e5d0eab907fc0c1301826dd81bdefa23f07d8ec822b054a4eb31c689b8e927e0ed28b4c790a26013c8d14d65d5706205fec5a02207fee661ec3
|
7
|
+
data.tar.gz: 484e127af388c3b633a5a7683f8493fa95fa2d1a6ef4981d227e37ce2676d7022170c18d708eb6ecb23eacfa9c48ac39865fe9e746e7d6fd94073e224c673047
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,16 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## v0.4.1
|
4
|
+
|
5
|
+
2020-8-24
|
6
|
+
|
7
|
+
- [`Breaking`] Remove `tool` tasks because it is infrequently used, it costs ([#162](https://github.com/yukihirop/r2-oas/pull/162))
|
8
|
+
- `routes:oas:paths_ls`
|
9
|
+
- `routes:oas:paths_stats`
|
10
|
+
- [`Feature`] Add `SKIP_PLUGIN` enviroment variables ([#160](https://github.com/yukihirop/r2-oas/pull/160))
|
11
|
+
|
12
|
+
Please see milestone [v0.4.1](https://github.com/yukihirop/r2-oas/milestone/6?closed=1)
|
13
|
+
|
3
14
|
## v0.4.0
|
4
15
|
|
5
16
|
2020-07-22
|
data/README.md
CHANGED
data/lib/r2-oas.rb
CHANGED
@@ -11,8 +11,7 @@ module R2OAS
|
|
11
11
|
extend Configuration
|
12
12
|
require 'r2-oas/task'
|
13
13
|
require 'r2-oas/plugin/public'
|
14
|
-
require 'r2-oas/lib/core_ext/
|
15
|
-
require 'r2-oas/lib/core_ext/object/blank'
|
14
|
+
require 'r2-oas/lib/core_ext/all'
|
16
15
|
|
17
16
|
autoload :Base, 'r2-oas/base'
|
18
17
|
autoload :NoImplementError, 'r2-oas/errors'
|
@@ -2,7 +2,6 @@
|
|
2
2
|
|
3
3
|
require_relative 'app_configuration/server'
|
4
4
|
require_relative 'app_configuration/swagger'
|
5
|
-
require_relative 'app_configuration/tool'
|
6
5
|
require_relative 'app_configuration/deprecation'
|
7
6
|
|
8
7
|
module R2OAS
|
@@ -43,7 +42,6 @@ module R2OAS
|
|
43
42
|
DEFAULT_HTTP_METHODS_WHEN_GENERATE_REQUEST_BODY = %w[post patch put]
|
44
43
|
DEFAULT_IGNORED_HTTP_STATUSES_WHEN_GENERATE_COMPONENT_SCHEMA = %w[204 404]
|
45
44
|
# rubocop:enable Style/MutableConstant
|
46
|
-
DEFAULT_TOOL = Tool.new
|
47
45
|
# :dot or :underbar
|
48
46
|
DEFAULT_NAMESPACE_TYPE = :dot
|
49
47
|
DEFAULT_DEPLOY_DIR_PATH = './deploy_docs'
|
@@ -67,7 +65,6 @@ module R2OAS
|
|
67
65
|
http_statuses_when_http_method
|
68
66
|
http_methods_when_generate_request_body
|
69
67
|
ignored_http_statuses_when_generate_component_schema
|
70
|
-
tool
|
71
68
|
namespace_type
|
72
69
|
deploy_dir_path
|
73
70
|
plugins
|
@@ -106,7 +103,6 @@ module R2OAS
|
|
106
103
|
target.interval_to_save_edited_tmp_schema = DEFAULT_INTERVAL_TO_SAVE_EDITED_TMP_SCHEMA
|
107
104
|
target.swagger = DEFAULT_SWAGGER
|
108
105
|
target.http_statuses_when_http_method = DEFAULT_HTTP_STATUSES_WHEN_HTTP_METHOD
|
109
|
-
target.tool = DEFAULT_TOOL
|
110
106
|
target.http_methods_when_generate_request_body = DEFAULT_HTTP_METHODS_WHEN_GENERATE_REQUEST_BODY
|
111
107
|
target.ignored_http_statuses_when_generate_component_schema = DEFAULT_IGNORED_HTTP_STATUSES_WHEN_GENERATE_COMPONENT_SCHEMA
|
112
108
|
target.namespace_type = DEFAULT_NAMESPACE_TYPE
|
data/lib/r2-oas/configuration.rb
CHANGED
@@ -70,10 +70,7 @@ module R2OAS
|
|
70
70
|
end
|
71
71
|
|
72
72
|
def load_tasks
|
73
|
-
|
74
|
-
Dir.glob("#{tasks_path}/**/*.rake").sort.each do |file|
|
75
|
-
load file if FileTest.exists?(file)
|
76
|
-
end
|
73
|
+
load_local_tasks
|
77
74
|
end
|
78
75
|
|
79
76
|
def init
|
@@ -103,6 +100,13 @@ module R2OAS
|
|
103
100
|
|
104
101
|
private
|
105
102
|
|
103
|
+
def load_local_tasks
|
104
|
+
tasks_path = File.expand_path("#{root_dir_path}/#{local_tasks_dir_name}")
|
105
|
+
Dir.glob("#{tasks_path}/**/*.rake").sort.each do |file|
|
106
|
+
load file if FileTest.exists?(file)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
106
110
|
def load_local_plugins
|
107
111
|
plugins_path = File.expand_path("#{root_dir_path}/#{local_plugins_dir_name}")
|
108
112
|
Dir.glob("#{plugins_path}/**/*.rb").sort.each do |file|
|
@@ -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
|
data/lib/r2-oas/task.rb
CHANGED
@@ -4,8 +4,7 @@ module R2OAS
|
|
4
4
|
class Task < ::Rails::Railtie
|
5
5
|
rake_tasks do
|
6
6
|
main_task_path = File.join(File.dirname(__FILE__), './tasks/main.rake')
|
7
|
-
|
8
|
-
Dir[main_task_path, tool_task_path].each { |f| load f }
|
7
|
+
Dir[main_task_path].each { |f| load f }
|
9
8
|
end
|
10
9
|
end
|
11
10
|
end
|
data/lib/r2-oas/tasks/main.rake
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
require 'r2-oas/schema/editor'
|
4
4
|
require 'r2-oas/schema/ui'
|
5
5
|
require 'r2-oas/schema/monitor'
|
6
|
+
require 'r2-oas/deploy/client'
|
6
7
|
require 'r2-oas/task_logging'
|
7
8
|
load File.expand_path('common.rake', __dir__)
|
8
9
|
|
@@ -44,7 +45,8 @@ namespace :routes do
|
|
44
45
|
FileUtils.mkdir_p(output_dir_path) unless FileTest.exists?(output_dir_path)
|
45
46
|
|
46
47
|
is_overrirde_src = override_src.eql? 'true'
|
47
|
-
|
48
|
+
use_plugin = skip_plugin.eql? 'false'
|
49
|
+
builder_options = { unit_paths_file_path: unit_paths_file_path, use_plugin: use_plugin, output: true }
|
48
50
|
builder = R2OAS::Schema::Builder.new(builder_options)
|
49
51
|
builder.build_docs
|
50
52
|
|
@@ -111,6 +113,29 @@ namespace :routes do
|
|
111
113
|
end
|
112
114
|
end
|
113
115
|
|
116
|
+
desc '[R2-OAS] Deploy OAS Document'
|
117
|
+
task deploy: [:common] do
|
118
|
+
start do
|
119
|
+
client_options = {}
|
120
|
+
client = R2OAS::Deploy::Client.new(client_options)
|
121
|
+
|
122
|
+
download_dist_th = Thread.new do
|
123
|
+
puts 'Download swagger-api/swagger-ui/dist ... (async)'
|
124
|
+
client.download_swagger_ui_dist
|
125
|
+
end
|
126
|
+
|
127
|
+
output_dir_path = File.expand_path(R2OAS.output_dir_path)
|
128
|
+
FileUtils.mkdir_p(output_dir_path) unless FileTest.exists?(output_dir_path)
|
129
|
+
|
130
|
+
builder_options = { unit_paths_file_path: unit_paths_file_path, use_plugin: true, output: true }
|
131
|
+
builder = R2OAS::Schema::Builder.new(builder_options)
|
132
|
+
builder.build_docs
|
133
|
+
|
134
|
+
download_dist_th.join
|
135
|
+
client.deploy
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
114
139
|
private
|
115
140
|
|
116
141
|
def unit_paths_file_path
|
@@ -128,5 +153,9 @@ namespace :routes do
|
|
128
153
|
def override_src
|
129
154
|
ENV.fetch('OVERRIDE_SRC', 'false')
|
130
155
|
end
|
156
|
+
|
157
|
+
def skip_plugin
|
158
|
+
ENV.fetch('SKIP_PLUGIN', 'false')
|
159
|
+
end
|
131
160
|
end
|
132
161
|
end
|
data/lib/r2-oas/version.rb
CHANGED
data/r2-oas.gemspec
CHANGED
@@ -33,9 +33,7 @@ Gem::Specification.new do |spec|
|
|
33
33
|
spec.add_runtime_dependency 'easy_diff', '>= 1.0.0'
|
34
34
|
spec.add_runtime_dependency 'eventmachine', '>= 1.2.0'
|
35
35
|
spec.add_runtime_dependency 'key_flatten', '>= 1.0.0'
|
36
|
-
spec.add_runtime_dependency 'paint'
|
37
36
|
spec.add_runtime_dependency 'railties', '>= 4.2.5'
|
38
|
-
spec.add_runtime_dependency 'terminal-table', '>= 1.6.0'
|
39
37
|
spec.add_runtime_dependency 'watir', '>= 6.16.5'
|
40
38
|
spec.add_development_dependency 'bundler', '>= 1.17'
|
41
39
|
spec.add_development_dependency 'coveralls'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: r2-oas
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- yukihirop
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-08-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: docker-api
|
@@ -66,20 +66,6 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: 1.0.0
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: paint
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - ">="
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '0'
|
76
|
-
type: :runtime
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - ">="
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
83
69
|
- !ruby/object:Gem::Dependency
|
84
70
|
name: railties
|
85
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -94,20 +80,6 @@ dependencies:
|
|
94
80
|
- - ">="
|
95
81
|
- !ruby/object:Gem::Version
|
96
82
|
version: 4.2.5
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: terminal-table
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - ">="
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: 1.6.0
|
104
|
-
type: :runtime
|
105
|
-
prerelease: false
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
107
|
-
requirements:
|
108
|
-
- - ">="
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version: 1.6.0
|
111
83
|
- !ruby/object:Gem::Dependency
|
112
84
|
name: watir
|
113
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -263,8 +235,6 @@ files:
|
|
263
235
|
- lib/r2-oas/app_configuration/swagger.rb
|
264
236
|
- lib/r2-oas/app_configuration/swagger/editor.rb
|
265
237
|
- lib/r2-oas/app_configuration/swagger/ui.rb
|
266
|
-
- lib/r2-oas/app_configuration/tool.rb
|
267
|
-
- lib/r2-oas/app_configuration/tool/paths/stats.rb
|
268
238
|
- lib/r2-oas/base.rb
|
269
239
|
- lib/r2-oas/configuration.rb
|
270
240
|
- lib/r2-oas/configuration/paths_config.rb
|
@@ -275,8 +245,10 @@ files:
|
|
275
245
|
- lib/r2-oas/hooks/global_hook.rb
|
276
246
|
- lib/r2-oas/hooks/hook.rb
|
277
247
|
- lib/r2-oas/hooks/repository.rb
|
248
|
+
- lib/r2-oas/lib/core_ext/all.rb
|
278
249
|
- lib/r2-oas/lib/core_ext/hash/deep_merge.rb
|
279
250
|
- lib/r2-oas/lib/core_ext/object/blank.rb
|
251
|
+
- lib/r2-oas/lib/core_ext/string/filters.rb
|
280
252
|
- lib/r2-oas/lib/three-way-merge/twm.rb
|
281
253
|
- lib/r2-oas/logger/stdout_logger.rb
|
282
254
|
- lib/r2-oas/pluggable_configuration.rb
|
@@ -380,9 +352,6 @@ files:
|
|
380
352
|
- lib/r2-oas/task_logging.rb
|
381
353
|
- lib/r2-oas/tasks/common.rake
|
382
354
|
- lib/r2-oas/tasks/main.rake
|
383
|
-
- lib/r2-oas/tasks/tool.rake
|
384
|
-
- lib/r2-oas/tool/paths/ls.rb
|
385
|
-
- lib/r2-oas/tool/paths/stats.rb
|
386
355
|
- lib/r2-oas/version.rb
|
387
356
|
- r2-oas.gemspec
|
388
357
|
homepage: https://github.com/yukihirop/r2-oas
|
@@ -390,9 +359,9 @@ licenses:
|
|
390
359
|
- MIT
|
391
360
|
metadata:
|
392
361
|
bug_tracker_uri: https://github.com/yukihirop/r2-oas/issues
|
393
|
-
changelog_uri: https://github.com/yukihirop/r2-oas/blob/v0.4.
|
362
|
+
changelog_uri: https://github.com/yukihirop/r2-oas/blob/v0.4.1/CHANGELOG.md
|
394
363
|
documentation_uri: https://yukihirop.github.io/r2-oas
|
395
|
-
source_code_uri: https://github.com/yukihirop/r2-oas/tree/v0.4.
|
364
|
+
source_code_uri: https://github.com/yukihirop/r2-oas/tree/v0.4.1
|
396
365
|
post_install_message:
|
397
366
|
rdoc_options: []
|
398
367
|
require_paths:
|
@@ -1,31 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative 'tool/paths/stats'
|
4
|
-
|
5
|
-
module R2OAS
|
6
|
-
module AppConfiguration
|
7
|
-
class Tool
|
8
|
-
DEFAULT_PATHS_STATS = PathsStats.new
|
9
|
-
|
10
|
-
VALID_OPTIONS_KEYS = [
|
11
|
-
:paths_stats
|
12
|
-
].freeze
|
13
|
-
|
14
|
-
attr_accessor *VALID_OPTIONS_KEYS
|
15
|
-
|
16
|
-
def initialize
|
17
|
-
set_default
|
18
|
-
end
|
19
|
-
|
20
|
-
def configure
|
21
|
-
yield self
|
22
|
-
end
|
23
|
-
|
24
|
-
private
|
25
|
-
|
26
|
-
def set_default
|
27
|
-
self.paths_stats = DEFAULT_PATHS_STATS
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
@@ -1,43 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module R2OAS
|
4
|
-
module AppConfiguration
|
5
|
-
class Tool
|
6
|
-
class PathsStats
|
7
|
-
DEFAULT_MONTH_TO_TURN_TO_WARNING_COLOR = 3
|
8
|
-
DEFAULT_WARNING_COLOR = :red
|
9
|
-
DEFAULT_TABLE_TITLE_COLOR = :yellow
|
10
|
-
DEFAULT_HEADING_COLOR = :yellow
|
11
|
-
DEFAULT_HIGHLIGHT_COLOR = :magenta
|
12
|
-
|
13
|
-
VALID_OPTIONS_KEYS = %i[
|
14
|
-
month_to_turn_to_warning_color
|
15
|
-
warning_color
|
16
|
-
table_title_color
|
17
|
-
heading_color
|
18
|
-
highlight_color
|
19
|
-
].freeze
|
20
|
-
|
21
|
-
attr_accessor *VALID_OPTIONS_KEYS
|
22
|
-
|
23
|
-
def initialize
|
24
|
-
set_default
|
25
|
-
end
|
26
|
-
|
27
|
-
def configure
|
28
|
-
yield self
|
29
|
-
end
|
30
|
-
|
31
|
-
private
|
32
|
-
|
33
|
-
def set_default
|
34
|
-
self.month_to_turn_to_warning_color = DEFAULT_MONTH_TO_TURN_TO_WARNING_COLOR
|
35
|
-
self.warning_color = DEFAULT_WARNING_COLOR
|
36
|
-
self.table_title_color = DEFAULT_TABLE_TITLE_COLOR
|
37
|
-
self.heading_color = DEFAULT_HEADING_COLOR
|
38
|
-
self.highlight_color = DEFAULT_HIGHLIGHT_COLOR
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
data/lib/r2-oas/tasks/tool.rake
DELETED
@@ -1,86 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'r2-oas/deploy/client'
|
4
|
-
require 'r2-oas/tool/paths/ls'
|
5
|
-
require 'r2-oas/tool/paths/stats'
|
6
|
-
require 'r2-oas/task_logging'
|
7
|
-
load File.expand_path('common.rake', __dir__)
|
8
|
-
|
9
|
-
namespace :routes do
|
10
|
-
namespace :oas do
|
11
|
-
desc '[R2-OAS] Deploy OAS Document'
|
12
|
-
task deploy: [:common] do
|
13
|
-
start do
|
14
|
-
client_options = {}
|
15
|
-
client = R2OAS::Deploy::Client.new(client_options)
|
16
|
-
|
17
|
-
download_dist_th = Thread.new do
|
18
|
-
puts 'Download swagger-api/swagger-ui/dist ... (async)'
|
19
|
-
client.download_swagger_ui_dist
|
20
|
-
end
|
21
|
-
|
22
|
-
output_dir_path = File.expand_path(R2OAS.output_dir_path)
|
23
|
-
FileUtils.mkdir_p(output_dir_path) unless FileTest.exists?(output_dir_path)
|
24
|
-
|
25
|
-
builder_options = { unit_paths_file_path: unit_paths_file_path, use_plugin: true, output: true }
|
26
|
-
builder = R2OAS::Schema::Builder.new(builder_options)
|
27
|
-
builder.build_docs
|
28
|
-
|
29
|
-
download_dist_th.join
|
30
|
-
client.deploy
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
desc '[R2-OAS] Display paths list'
|
35
|
-
task paths_ls: [:common] do
|
36
|
-
fd = IO.sysopen('/dev/null', 'w+')
|
37
|
-
$stdout = IO.new(fd)
|
38
|
-
logger.level = :null
|
39
|
-
|
40
|
-
start do
|
41
|
-
$stdout = StringIO.new
|
42
|
-
|
43
|
-
paths_ls_options = {}
|
44
|
-
paths_ls = R2OAS::Tool::Paths::Ls.new(paths_ls_options)
|
45
|
-
paths_ls.print
|
46
|
-
end
|
47
|
-
|
48
|
-
result = $stdout.string
|
49
|
-
$stdout = STDOUT
|
50
|
-
puts result
|
51
|
-
end
|
52
|
-
|
53
|
-
desc '[R2-OAS] Display paths stats'
|
54
|
-
task paths_stats: [:common] do
|
55
|
-
fd = IO.sysopen('/dev/null', 'w+')
|
56
|
-
$stdout = IO.new(fd)
|
57
|
-
logger.level = :null
|
58
|
-
|
59
|
-
start do
|
60
|
-
builder_options = { skip_load_dot_paths: true }
|
61
|
-
builder = R2OAS::Schema::Builder.new(builder_options)
|
62
|
-
builder.build_docs
|
63
|
-
|
64
|
-
$stdout = StringIO.new
|
65
|
-
|
66
|
-
paths_log_options = {}
|
67
|
-
paths_log = R2OAS::Tool::Paths::Stats.new(paths_log_options)
|
68
|
-
paths_log.print
|
69
|
-
end
|
70
|
-
|
71
|
-
result = $stdout.string
|
72
|
-
$stdout = STDOUT
|
73
|
-
puts result
|
74
|
-
end
|
75
|
-
|
76
|
-
private
|
77
|
-
|
78
|
-
def unit_paths_file_path
|
79
|
-
ENV.fetch('PATHS_FILE', '')
|
80
|
-
end
|
81
|
-
|
82
|
-
def existing_schema_file_path
|
83
|
-
ENV.fetch('OAS_FILE', '')
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
data/lib/r2-oas/tool/paths/ls.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module R2OAS
|
4
|
-
module Tool
|
5
|
-
module Paths
|
6
|
-
class Ls < Base
|
7
|
-
def print
|
8
|
-
Dir.glob("#{schema_save_dir_path}/paths/**/**.yml").each do |path|
|
9
|
-
puts path.sub(%r{^#{Dir.getwd}/?}, '')
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
@@ -1,84 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'terminal-table'
|
4
|
-
require 'paint'
|
5
|
-
require 'forwardable'
|
6
|
-
|
7
|
-
module R2OAS
|
8
|
-
module Tool
|
9
|
-
module Paths
|
10
|
-
class Stats < Base
|
11
|
-
extend Forwardable
|
12
|
-
|
13
|
-
TIMESTAMPS = ['Created At', 'Updated At'].freeze
|
14
|
-
TABLE_TITLE = 'Paths Stats'
|
15
|
-
|
16
|
-
def initialize(options = {})
|
17
|
-
super
|
18
|
-
@paths_list = Dir.glob("#{schema_save_dir_path}/paths/**/**.yml")
|
19
|
-
@path_from = Pathname(File.dirname(File.expand_path(root_dir_path)))
|
20
|
-
@paths_stats = tool.paths_stats
|
21
|
-
end
|
22
|
-
|
23
|
-
def print
|
24
|
-
table.title = Paint[TABLE_TITLE, table_title_color]
|
25
|
-
puts table
|
26
|
-
puts "\n#{Paint['Red', warning_color]}: over #{month_to_turn_to_warning_color} months since the last update."
|
27
|
-
end
|
28
|
-
|
29
|
-
private
|
30
|
-
|
31
|
-
def_delegators :@paths_stats, :month_to_turn_to_warning_color, :warning_color, :table_title_color, :heading_color, :highlight_color
|
32
|
-
|
33
|
-
def table
|
34
|
-
@table ||= Terminal::Table.new do |t|
|
35
|
-
@paths_list.each_with_index do |file_path, index|
|
36
|
-
t.headings = ['No', 'File Path', *TIMESTAMPS].map { |head| Paint[head, heading_color] }
|
37
|
-
t << table_content(index, file_path)
|
38
|
-
t.style = { all_separators: true }
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def table_content(index, file_path)
|
44
|
-
content = [(index + 1).to_s, relative_file_path(file_path), *timestamps(file_path)]
|
45
|
-
if file_path.in? paths_config.many_paths_file_paths
|
46
|
-
content.map { |c| Paint[c, highlight_color] }
|
47
|
-
else
|
48
|
-
content
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
def relative_file_path(file_path)
|
53
|
-
path_to = Pathname(file_path)
|
54
|
-
path_to.relative_path_from(@path_from).to_s
|
55
|
-
end
|
56
|
-
|
57
|
-
def timestamps(file_path)
|
58
|
-
timestamps_data(file_path) do |result, stat|
|
59
|
-
mtime = stat.mtime
|
60
|
-
result.deep_merge!(
|
61
|
-
mtime: expired?(mtime) ? Paint[mtime, warning_color] : mtime
|
62
|
-
)
|
63
|
-
end.values
|
64
|
-
end
|
65
|
-
|
66
|
-
def timestamps_data(file_path)
|
67
|
-
stat = File::Stat.new(file_path)
|
68
|
-
result = {
|
69
|
-
birthtime: stat.birthtime,
|
70
|
-
mtime: stat.mtime
|
71
|
-
}
|
72
|
-
yield result, stat if block_given?
|
73
|
-
result
|
74
|
-
end
|
75
|
-
|
76
|
-
def expired?(mtime)
|
77
|
-
month = month_to_turn_to_warning_color.send(:month)
|
78
|
-
expired_at = Time.current.ago(month)
|
79
|
-
mtime < expired_at
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|