yard-rails_plugin 0.0.3 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4ee5828356df79f9af3841f7af240528c7492e282006ea6aadd898e722e5fc51
4
- data.tar.gz: 233988e9b1e65313f07e71f7883cd3a95e054f7b9eca51e108d16945d29ff62f
3
+ metadata.gz: e88656913ac29d98c067db26b3947b6267ab4d5dc1a4b21a0985127604ab39ac
4
+ data.tar.gz: de9a523a1c980e8c1ffba286fcc702216a3be1906902121d65bb01da382a8026
5
5
  SHA512:
6
- metadata.gz: 5259b1ea921d2edf76559a0e35d1d984361db8ccca868200490bafd057d16e419b1f25df3baf663db311396cc4abeb26437343458ec51b7d17ac597353de7c51
7
- data.tar.gz: 047d79b8493048018b46f92a40223d9a24734ec15331b38a83b7672b9a0d2bc634fa6396aff1adb24e075af5b5436f8d0adb3875de891ab5f1cc87c1e9ab5a2e
6
+ metadata.gz: 4405d5d9d4969b61c1a4934b1de53b9d3d926c79410539e4172929869f2f5f8bb22c539f0ede99c005819f34aa9c316a3b2208d3da09f12e384cf7c29cca0279
7
+ data.tar.gz: 546a576c1ffe817254263c8c9e2b48f1e96b5562e909cedbedebd0f6fe55d61fc2d270b0476c0efccbde1cef4c5ebe3117b8211e3b4b1f28aa5c611f6a78a6b1
data/.rubocop.yml ADDED
@@ -0,0 +1,109 @@
1
+ ---
2
+ AllCops:
3
+ Exclude:
4
+ - 'node_modules/**/*'
5
+ - 'tmp/**/*'
6
+ - 'vendor/**/*'
7
+ - '.git/**/*'
8
+ - 'db/schema.rb'
9
+ - 'db/data_schema.rb'
10
+ - 'db/data/*my*.rb'
11
+ - '**/*.rake'
12
+ - 'storage/**/*'
13
+ - '**/shims/**'
14
+ - '**.py'
15
+ - bin/**
16
+ NewCops: enable
17
+
18
+ Layout/EndOfLine:
19
+ EnforcedStyle: lf
20
+ Layout/EmptyLinesAroundAttributeAccessor:
21
+ Enabled: true
22
+ Layout/SpaceAroundMethodCallOperator:
23
+ Enabled: true
24
+ Lint/DeprecatedOpenSSLConstant:
25
+ Enabled: true
26
+ Lint/DuplicateBranch:
27
+ Enabled: true
28
+ Lint/DuplicateElsifCondition:
29
+ Enabled: true
30
+ Lint/DuplicateRegexpCharacterClassElement:
31
+ Enabled: true
32
+ Lint/EmptyBlock: # (new in 1.1)
33
+ Enabled: true
34
+ Lint/EmptyClass: # (new in 1.3)
35
+ Enabled: true
36
+ Lint/MixedRegexpCaptureTypes:
37
+ Enabled: true
38
+ Lint/MissingSuper:
39
+ Exclude:
40
+ - 'lib/creds.rb'
41
+ Lint/NoReturnInBeginEndBlocks: # (new in 1.2)
42
+ Enabled: true
43
+ Lint/PercentStringArray:
44
+ Exclude:
45
+ - 'config/initializers/secure_headers.rb'
46
+ Lint/RaiseException:
47
+ Enabled: true
48
+ Lint/StructNewOverride:
49
+ Enabled: true
50
+ Lint/ToEnumArguments: # (new in 1.1)
51
+ Enabled: true
52
+ Lint/UnmodifiedReduceAccumulator: # (new in 1.1)
53
+ Enabled: true
54
+ Metrics/AbcSize:
55
+ Enabled: false
56
+ Metrics/ClassLength:
57
+ Exclude:
58
+ - "test/*/*"
59
+ Metrics/MethodLength:
60
+ Enabled: false
61
+ Metrics/BlockLength:
62
+ Exclude:
63
+ - 'config/initializers/secure_headers.rb'
64
+ Style/AccessorGrouping:
65
+ Enabled: true
66
+ Style/ArgumentsForwarding: # (new in 1.1)
67
+ Enabled: true
68
+ Style/ArrayCoercion:
69
+ Enabled: true
70
+ Style/BisectedAttrAccessor:
71
+ Enabled: true
72
+ Style/CaseLikeIf:
73
+ Enabled: true
74
+ Style/CollectionCompact: # (new in 1.2)
75
+ Enabled: true
76
+ Style/DocumentDynamicEvalDefinition: # (new in 1.1)
77
+ Enabled: true
78
+ Style/ExponentialNotation:
79
+ Enabled: true
80
+ Style/HashAsLastArrayItem:
81
+ Enabled: true
82
+ Style/HashLikeCase:
83
+ Enabled: true
84
+ Style/HashEachMethods:
85
+ Enabled: true
86
+ Style/HashTransformKeys:
87
+ Enabled: true
88
+ Style/HashTransformValues:
89
+ Enabled: true
90
+ Style/NegatedIfElseCondition: # (new in 1.2)
91
+ Enabled: true
92
+ Style/NilLambda: # (new in 1.3)
93
+ Enabled: true
94
+ Style/RedundantAssignment:
95
+ Enabled: true
96
+ Style/RedundantFetchBlock:
97
+ Enabled: true
98
+ Style/RedundantFileExtensionInRequire:
99
+ Enabled: true
100
+ Style/RedundantRegexpCharacterClass:
101
+ Enabled: true
102
+ Style/RedundantRegexpEscape:
103
+ Enabled: true
104
+ Style/RescueStandardError:
105
+ Enabled: true
106
+ Style/SlicingWithRange:
107
+ Enabled: true
108
+ Style/SwapValues: # (new in 1.1)
109
+ Enabled: true
@@ -7,23 +7,24 @@ module YARD
7
7
  module Plugin
8
8
  # Handles Rails's route documentations
9
9
  class Routes
10
- # rubocop:disable Metrics/AbcSize
11
- # rubocop:disable Metrics/MethodLength
12
10
  def initialize
13
11
  puts '[rails-plugin] Analyzing Routes...'
14
12
  @routes = load_routes.collect do |route|
15
- next if route[:path] =~ '/rails/info/properties|^/assets'
13
+ next if route.path.spec.to_s =~ %r{/rails/*|^/assets|^/cable}
16
14
 
17
15
  reqs = route.requirements.dup
18
16
 
19
- return { name: route.name.to_s,
20
- verb: route.verb.to_s,
21
- path: route.path.spec.to_s,
22
- action: reqs[:action],
23
- controller: get_controller(reqs),
24
- rack_app: get_rack_app(route),
25
- constraints: get_constraints(reqs) }
17
+ next if reqs.blank?
18
+
19
+ { name: route.name.to_s,
20
+ verb: route.verb.to_s,
21
+ path: route.path.spec.to_s,
22
+ action: reqs[:action],
23
+ controller: get_controller(reqs),
24
+ rack_app: get_rack_app(route),
25
+ constraints: get_constraints(reqs) }
26
26
  end
27
+ @routes.compact!
27
28
  end
28
29
 
29
30
  def generate_routes_description_file(filename)
@@ -39,73 +40,74 @@ module YARD
39
40
  <th>Endpoint</th>
40
41
  <th>Destination</th>
41
42
  </tr>
42
- <% i = 0;
43
- @routes.each do |r|
44
- odd_or_even = (i.even? ? 'even' : 'odd')
45
- destination = if r[:rack_app]
46
- "<pre>#{r[:rack_app].inspect} #{r[:constraints]}</pre>"
47
- else
48
- "{#{r[:controller]} #{r[:controller]}}##{r[:action]} #{r[:constraints]}"
49
- end
50
- endpoint = r[:path].gsub(/(:|\*)\w+/) do |m|
51
- "<span style='font-family: monospace; color: green'>#{m}</span>"
52
- end
53
- i += 1
43
+ <% @routes.each_with_index do |r, i|
44
+ next if r == nil
54
45
  %>
55
- <tr class='#{odd_or_even}'>
56
- <td><%= r[:name]%></td>
57
- <td><%= r[:verb]%></td>
58
- <td><%= endpoint%></td>
59
- <td><%= destination%></td>
60
- </tr>"
46
+ <tr class='<%=(i.even? ? 'even' : 'odd')%>'>
47
+ <td><%= r[:name] %></td>
48
+ <td><%= r[:verb] %></td>
49
+ <td><%= r[:path].gsub(/(:|\*)\w+/) do |m|
50
+ "<span style='font-family: monospace; color: green'>#{m}</span>"
51
+ end %></td>
52
+ <td><%= r[:rack_app].present? ? "<pre>#{r[:rack_app].inspect} #{r[:constraints]}</pre>" :
53
+ "{#{r[:controller]} #{r[:controller]}}##{r[:action]} #{r[:constraints]}" %></td>
54
+ </tr>
61
55
  <% end %>
62
56
  </table>
63
57
  </body>
64
- </html>').gsub(/^ /, '')
58
+ </html>).gsub(/^\s+/, '')
65
59
  erb = ERB.new(template, trim_mode: '%<>')
66
60
 
67
- File.write(File.join(Dir.pwd, filename), erb.result)
61
+ b = binding
62
+
63
+ File.write(
64
+ File.join(Dir.pwd, filename),
65
+ erb.result(b)
66
+ )
68
67
  end
69
- # rubocop:enable Metrics/MethodLength
70
68
 
71
69
  def enrich_controllers
72
70
  @routes.each do |r|
73
71
  next unless r[:controller]
74
72
 
75
73
  node = YARD::Registry.resolve(nil, r[:controller], true)
74
+ next if node.nil?
75
+
76
76
  (node[:routes] ||= []) << r
77
77
 
78
78
  next unless r[:action]
79
79
 
80
80
  node = YARD::Registry.resolve(nil, "#{r[:controller]}##{r[:action]}", true)
81
+ next if node.nil?
82
+
81
83
  (node[:routes] ||= []) << r
82
84
  end
83
85
  end
84
- end
85
86
 
86
- private
87
+ private
87
88
 
88
- def load_routes
89
- ::Rails.application.reload_routes!
90
- ::Rails.application.routes.routes
91
- end
89
+ def load_routes
90
+ ::Rails.application.reload_routes!
91
+ ::Rails.application.routes.routes
92
+ end
92
93
 
93
- def get_controller(reqs)
94
- return unless reqs[:controller]
94
+ def get_controller(reqs)
95
+ return unless reqs[:controller]
95
96
 
96
- "#{reqs[:controller].upcase.gsub('_', '').gsub('/', '::')}_Controller"
97
- end
97
+ "#{reqs[:controller].camelize}Controller"
98
+ end
98
99
 
99
- def get_constraints(reqs)
100
- return unless reqs.except(:controller, :action).present?
100
+ def get_constraints(reqs)
101
+ return if reqs.except(:controller, :action).blank?
101
102
 
102
- reqs.except(:controller, :action).inspect
103
- end
103
+ reqs.except(:controller, :action).inspect
104
+ end
104
105
 
105
- def get_rack_app(route)
106
- return unless route.app.is_a?('ActionDispatch::Routing')
106
+ def get_rack_app(route)
107
+ return unless route.app.is_a?(ActionDispatch::Routing)
107
108
 
108
- route.app.inspect
109
+ route.app.inspect
110
+ end
109
111
  end
110
112
  end
111
113
  end
@@ -3,7 +3,7 @@
3
3
  module YARD
4
4
  module Rails
5
5
  module Plugin
6
- VERSION = '0.0.3'
6
+ VERSION = '0.1.0'
7
7
  end
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yard-rails_plugin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Nagy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-05-21 00:00:00.000000000 Z
11
+ date: 2024-05-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: yard
@@ -68,6 +68,7 @@ files:
68
68
  - ".github/workflows/gem-push.yml"
69
69
  - ".github/workflows/ruby.yml"
70
70
  - ".gitignore"
71
+ - ".rubocop.yml"
71
72
  - ".ruby-gemset"
72
73
  - ".ruby-version"
73
74
  - Gemfile
@@ -85,7 +86,7 @@ files:
85
86
  - templates/default/method_details/html/params.erb
86
87
  - templates/default/method_details/html/routes.erb
87
88
  - templates/default/method_details/setup.rb
88
- - yard-rails-plugin.gemspec
89
+ - yard-rails_plugin.gemspec
89
90
  homepage: https://github.com/Meter-reader/yard-rails_plugin
90
91
  licenses:
91
92
  - MIT