ducalis 0.5.5 → 0.5.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,24 +4,24 @@ require 'rubocop'
4
4
 
5
5
  module Ducalis
6
6
  class UselessOnly < RuboCop::Cop::Cop
7
- include RuboCop::Cop::DefNode
7
+ OFFENSE = <<-MESSAGE.gsub(/^ +\|/, '').strip
8
+ | Seems like there is no any reason to keep before filter only for one
9
+ | action. Maybe it will be better to inline it?
10
+ |
11
+ | ```ruby
12
+ | before_filter :do_something, only: %i[index]
13
+ | def index; end
14
+ |
15
+ | # to
16
+ |
17
+ | def index
18
+ | do_something
19
+ | end
20
+ | ```
21
+ MESSAGE
22
+
8
23
  FILTERS = %i(before_filter after_filter around_filter
9
24
  before_action after_action around_action).freeze
10
- OFFENSE = %(
11
- Seems like there is no any reason to keep before filter only for one action. \
12
- Maybe it will be better to inline it?
13
-
14
- ```ruby
15
- before_filter :do_something, only: %i[index]
16
- def index; end
17
-
18
- # to
19
-
20
- def index
21
- do_something
22
- end
23
- ```
24
- ).strip
25
25
 
26
26
  def on_class(node)
27
27
  _classdef_node, superclass, _body = *node
@@ -1,8 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'parser/current'
4
- require 'rubocop'
5
4
 
5
+ # This class could be used to dynamically generate documentation from cops spec.
6
+ # It recognizes bad and good examples by signal words like `raises`. Additional
7
+ # information for documentation could be passed by setting `DETAILS` constant.
6
8
  class SpecsProcessor < Parser::AST::Processor
7
9
  attr_reader :cases
8
10
 
@@ -55,6 +57,10 @@ class SpecsProcessor < Parser::AST::Processor
55
57
  end
56
58
 
57
59
  class Documentation
60
+ RED_SQUARE = '![](https://placehold.it/10/f03c15/000000?text=+)'
61
+ GREEN_SQUARE = '![](https://placehold.it/10/2cbe4e/000000?text=+)'
62
+ SIGNAL_WORD = 'raises'
63
+
58
64
  def call
59
65
  Dir['./lib/ducalis/cops/*.rb'].map do |f|
60
66
  present_cop(klass_const_for(f), spec_cases_for(f))
@@ -66,7 +72,7 @@ class Documentation
66
72
  def present_cop(klass, specs)
67
73
  [
68
74
  "## #{klass}\n", # header
69
- klass.const_get(:OFFENSE) # description
75
+ message(klass) # description
70
76
  ] +
71
77
  specs.map do |(it, code)|
72
78
  [
@@ -77,11 +83,14 @@ class Documentation
77
83
  end
78
84
 
79
85
  def color(it)
80
- if it.include?('raises')
81
- '![](https://placehold.it/15/f03c15/000000?text=+)'
82
- else
83
- '![](https://placehold.it/15/2cbe4e/000000?text=+)'
84
- end
86
+ it.include?(SIGNAL_WORD) ? RED_SQUARE : GREEN_SQUARE
87
+ end
88
+
89
+ def message(klass)
90
+ [
91
+ klass.const_get(:OFFENSE),
92
+ *(klass.const_get(:DETAILS) if klass.const_defined?(:DETAILS))
93
+ ].join("\n")
85
94
  end
86
95
 
87
96
  def spec_cases_for(f)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ducalis
4
- VERSION = '0.5.5'
4
+ VERSION = '0.5.6'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ducalis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.5
4
+ version: 0.5.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ignat Zakrevsky
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-03 00:00:00.000000000 Z
11
+ date: 2017-11-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: git