ducalis 0.5.8 → 0.5.9

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 21e653839c1ac51f59d14a84abede1d7f3fc8d95
4
- data.tar.gz: 89f274016015741d35d85b1c664191b41ec05948
3
+ metadata.gz: 9df1822f6834c733ed48f31e1957334cc59b5f42
4
+ data.tar.gz: 34669e5f892a97db37ef4af821e44f144d4a57df
5
5
  SHA512:
6
- metadata.gz: e2ac4461691ba39f23a0e1f5fa7bef701daf5b50cad2c31bec1ced0556899f27923efc0490d37bbcffa00fec3c594015497e6c406d325dc5d40e40d7ff9e2a92
7
- data.tar.gz: 78e397569b05a3859b4ef295298f03cf17ea91746a1791d86f01688712cb9ad0619c46259f2f171cf71a58967275886e9075acc6751a002d8e11af8b0878bc65
6
+ metadata.gz: 8e06ee445e45f02521f7b952ddfea25927dbe5fb4e04c6dad60b00f14dba0dce6f8a885483d5bf0389f05c853b7d7d15b067ab7f52294266fdaf336a08eace69
7
+ data.tar.gz: 93df41092dc3b5bf2f3668f6149fbb51f9ff728d3a67278a9e8b663309da626739d2af6e3bee020b543658755e623bb10214774043faafe94a51b7e3da231d4c
@@ -636,6 +636,11 @@ It's better to add exception class as raise argument. It will make
636
636
  raise "Something went wrong"
637
637
  ```
638
638
 
639
+ ![](https://placehold.it/10/f03c15/000000?text=+) raises when `raise` called without arguments
640
+ ```ruby
641
+ raise
642
+ ```
643
+
639
644
  ![](https://placehold.it/10/2cbe4e/000000?text=+) ignores when `raise` called with exception class
640
645
  ```ruby
641
646
  raise StandardError, "Something went wrong"
@@ -780,6 +785,76 @@ before_save :set_full_name,
780
785
  ```ruby
781
786
  validates :file, if: -> { remote_url.blank? }
782
787
  ```
788
+ ## Ducalis::TooLongWorkers
789
+
790
+ Seems like your worker is doing too much work, consider of moving business
791
+ logic to service object. As rule, workers should have only two responsibilities:
792
+ - __Model materialization__: As async jobs working with serialized attributes
793
+ it's nescessary to cast them into actual objects.
794
+ - __Errors handling__: Rescue errors and figure out what to do with them.
795
+
796
+ ![](https://placehold.it/10/f03c15/000000?text=+) raises for a class with more than 5 lines
797
+ ```ruby
798
+ class TestWorker
799
+ a = 1
800
+ a = 2
801
+ a = 3
802
+ a = 4
803
+ a = 5
804
+ a = 6
805
+ end
806
+ ```
807
+
808
+ ![](https://placehold.it/10/2cbe4e/000000?text=+) ignores non-worker classes
809
+ ```ruby
810
+ class StrangeClass
811
+ a = 1
812
+ a = 2
813
+ a = 3
814
+ a = 4
815
+ a = 5
816
+ a = 6
817
+ end
818
+ ```
819
+
820
+ ![](https://placehold.it/10/2cbe4e/000000?text=+) accepts a class with 5 lines
821
+ ```ruby
822
+ class TestWorker
823
+ a = 1
824
+ a = 2
825
+ a = 3
826
+ a = 4
827
+ a = 5
828
+ end
829
+ ```
830
+
831
+ ![](https://placehold.it/10/2cbe4e/000000?text=+) accepts a class with less than 5 lines
832
+ ```ruby
833
+ class TestWorker
834
+ a = 1
835
+ a = 2
836
+ a = 3
837
+ a = 4
838
+ end
839
+ ```
840
+
841
+ ![](https://placehold.it/10/2cbe4e/000000?text=+) accepts empty classes
842
+ ```ruby
843
+ class TestWorker
844
+ end
845
+ ```
846
+
847
+ ![](https://placehold.it/10/2cbe4e/000000?text=+) also counts commented lines
848
+ ```ruby
849
+ class TestWorker
850
+ a = 1
851
+ #a = 2
852
+ a = 3
853
+ #a = 4
854
+ a = 5
855
+ a = 6
856
+ end
857
+ ```
783
858
  ## Ducalis::UncommentedGem
784
859
 
785
860
  Please, add comment why are you including non-realized gem version for
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ducalis (0.5.8)
4
+ ducalis (0.5.9)
5
5
  git (~> 1.3, >= 1.3.0)
6
6
  policial (= 0.0.4)
7
7
  regexp-examples (~> 1.3, >= 1.3.2)
@@ -2,6 +2,7 @@ AllCops:
2
2
  DisabledByDefault: true
3
3
  TargetRubyVersion: 2.3
4
4
  Exclude:
5
+ - 'db/**/*'
5
6
  - 'node_modules/**/*'
6
7
  - 'vendor/bundle/**/*'
7
8
 
@@ -33,6 +34,10 @@ Ducalis/PossibleTap:
33
34
 
34
35
  Ducalis/ProtectedScopeCop:
35
36
  Enabled: true
37
+ Exclude:
38
+ - 'spec/**/*.rb'
39
+ - 'app/workers/**/*.rb'
40
+ - 'app/mailers/**/*.rb'
36
41
 
37
42
  Ducalis/RegexCop:
38
43
  Enabled: true
@@ -42,6 +47,10 @@ Ducalis/RegexCop:
42
47
  Ducalis/StringsInActiverecords:
43
48
  Enabled: true
44
49
 
50
+ Ducalis/TooLongWorkers:
51
+ Enabled: true
52
+ Max: 25
53
+
45
54
  Ducalis/UselessOnly:
46
55
  Enabled: true
47
56
 
@@ -47,5 +47,6 @@ require 'ducalis/cops/regex_cop'
47
47
  require 'ducalis/cops/rest_only_cop'
48
48
  require 'ducalis/cops/rubocop_disable'
49
49
  require 'ducalis/cops/strings_in_activerecords'
50
+ require 'ducalis/cops/too_long_workers'
50
51
  require 'ducalis/cops/uncommented_gem'
51
52
  require 'ducalis/cops/useless_only'
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rubocop'
4
+
5
+ module Ducalis
6
+ class TooLongWorkers < RuboCop::Cop::Cop
7
+ include RuboCop::Cop::ClassishLength
8
+
9
+ OFFENSE = <<-MESSAGE.gsub(/^ +\|/, '').strip
10
+ | Seems like your worker is doing too much work, consider of moving business
11
+ | logic to service object. As rule, workers should have only two responsibilities:
12
+ | - __Model materialization__: As async jobs working with serialized attributes
13
+ | it's nescessary to cast them into actual objects.
14
+ | - __Errors handling__: Rescue errors and figure out what to do with them.
15
+ MESSAGE
16
+
17
+ WORKERS_SUFFIXES = %w(Worker Job).freeze
18
+
19
+ def on_class(node)
20
+ return unless worker_class?(node)
21
+ check_code_length(node)
22
+ end
23
+
24
+ private
25
+
26
+ def worker_class?(node)
27
+ classdef_node, _superclass, _body = *node
28
+ classdef_node.source.end_with?(*WORKERS_SUFFIXES)
29
+ end
30
+
31
+ def message(length, max_length)
32
+ format("#{OFFENSE} [%d/%d]", length, max_length)
33
+ end
34
+ end
35
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ducalis
4
- VERSION = '0.5.8'
4
+ VERSION = '0.5.9'
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.8
4
+ version: 0.5.9
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-16 00:00:00.000000000 Z
11
+ date: 2017-11-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: git
@@ -146,6 +146,7 @@ files:
146
146
  - lib/ducalis/cops/rest_only_cop.rb
147
147
  - lib/ducalis/cops/rubocop_disable.rb
148
148
  - lib/ducalis/cops/strings_in_activerecords.rb
149
+ - lib/ducalis/cops/too_long_workers.rb
149
150
  - lib/ducalis/cops/uncommented_gem.rb
150
151
  - lib/ducalis/cops/useless_only.rb
151
152
  - lib/ducalis/documentation.rb