dark_finger 0.2.1 → 0.3.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
- SHA256:
3
- metadata.gz: 2f553cbf220a141518443aac11bc359fbac54837b91fbba09abf183fa1dda2cb
4
- data.tar.gz: eacb634ce062545ada20f0a558fb7150f2c3ae807e1ad1100653880b3de5959d
2
+ SHA1:
3
+ metadata.gz: e6c89d85d00daa4de08f8ff85f9beb0e6a5bcd29
4
+ data.tar.gz: e969f72b56a52533992b579bd16944e3da275c85
5
5
  SHA512:
6
- metadata.gz: 18f364c93516c2f54153e0c3f6dab2b9e4a5181fd2efde6a5a6015092073c92658fa4479fb10d7d8b6818d3ac9ff8d087a6f454acbafa79f8eb63903e41101b5
7
- data.tar.gz: 99fc159a3641f0fda730389e5f5467030f865b59e3de7dfd59ac7a8508d62b726bc30acfae3f3885c956c969132dc33bddbc8fe82aa867232ebd3351e15a267b
6
+ metadata.gz: a72344c208f7cf1064a75054a384e8e7a11c1eb02fa8d9835741dbdc30c623b7bb7da614c60ab43122dd3c00155384068ead03b2349b8533c94ead24cc63a521
7
+ data.tar.gz: b9e7340a802adb0e5b2bd05cbe741685859e823f85595ef2688197d91b0deed505f25b6ccafd207712c422617004af644f7f4a807b576c7f92250e1b88b9a4bf
@@ -1,3 +1,3 @@
1
1
  module DarkFinger
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -2,9 +2,13 @@ module RuboCop
2
2
  module Cop
3
3
  module DarkFinger
4
4
  class ActiveModelNodeDecorator < SimpleDelegator
5
- def initialize(node)
6
- super
5
+
6
+ attr_reader :misc_method_names
7
+
8
+ def initialize(node, misc_method_names: [])
9
+ super(node)
7
10
  raise "Cannot decorate nil node" if node.nil?
11
+ @misc_method_names = misc_method_names
8
12
  end
9
13
 
10
14
  def node_type
@@ -22,6 +26,8 @@ module RuboCop
22
26
  ModelStructure::ENUM
23
27
  elsif attributes?
24
28
  ModelStructure::ATTRIBUTES
29
+ elsif misc_method?
30
+ ModelStructure::MISC
25
31
  else
26
32
  nil
27
33
  end
@@ -119,6 +125,10 @@ module RuboCop
119
125
  def attributes?
120
126
  method_name =~ /^attr_/
121
127
  end
128
+
129
+ def misc_method?
130
+ misc_method_names.include?(method_name)
131
+ end
122
132
  end
123
133
 
124
134
  end
@@ -1,10 +1,3 @@
1
- # bundle exec rubocop -d -r ./path/to/this/cop.rb --only DarkFinger/ModelStructure ./app/models/foo.rb
2
- #
3
- # TODO:
4
- #
5
- # * Constructors
6
- # * Handle "Misc" stuff
7
-
8
1
  require File.dirname(__FILE__) + '/active_model_node_decorator'
9
2
 
10
3
  module RuboCop
@@ -16,9 +9,11 @@ module RuboCop
16
9
  CALLBACK = :callback
17
10
  CLASS_METHOD = :class_method
18
11
  CONSTANT = :constant
12
+ CONSTRUCTOR = :constructor
19
13
  ENUM = :enum
20
14
  INCLUDE = :include
21
15
  INSTANCE_METHOD = :instance_method
16
+ MISC = :misc
22
17
  MODULE = :module
23
18
  SCOPE = :scope
24
19
  VALIDATION = :validation
@@ -33,6 +28,8 @@ module RuboCop
33
28
  SCOPE,
34
29
  ATTRIBUTES,
35
30
  CALLBACK,
31
+ MISC,
32
+ CONSTRUCTOR,
36
33
  CLASS_METHOD,
37
34
  INSTANCE_METHOD,
38
35
  ]
@@ -49,17 +46,21 @@ module RuboCop
49
46
  VALIDATION => '# Validations'
50
47
  }
51
48
 
52
- attr_reader :required_order, :required_comments
49
+ DEFAULT_MISC_METHOD_NAMES = []
50
+
51
+ attr_reader :required_order, :required_comments, :misc_method_names
53
52
 
54
- def initialize(*args, required_order: nil, required_comments: nil, **_)
53
+ def initialize(*args, required_order: nil, required_comments: nil, misc_method_names: nil, **_)
55
54
  super
56
55
  @class_elements_seen = []
57
56
  @required_order = required_order || cop_config['required_order'] || DEFAULT_REQUIRED_ORDER
58
57
  @required_comments = required_comments || cop_config['required_comments'] || DEFAULT_REQUIRED_COMMENTS
58
+ @misc_method_names = misc_method_names || cop_config['misc_method_names'] || DEFAULT_MISC_METHOD_NAMES
59
59
 
60
- # symbolize order/comments
60
+ # symbolize configs
61
61
  @required_order.map!(&:to_sym)
62
62
  @required_comments = Hash[ @required_comments.map {|k,v| [k.to_sym, v]} ]
63
+ @misc_method_names.map!(&:to_sym)
63
64
  end
64
65
 
65
66
  def on_send(node)
@@ -75,7 +76,12 @@ module RuboCop
75
76
  end
76
77
 
77
78
  def on_def(node)
78
- process_node(node, seen_element: INSTANCE_METHOD)
79
+ seen_element = if node.method_name == :initialize
80
+ CONSTRUCTOR
81
+ else
82
+ INSTANCE_METHOD
83
+ end
84
+ process_node(node, seen_element: seen_element)
79
85
  end
80
86
 
81
87
  def on_defs(node)
@@ -89,7 +95,7 @@ module RuboCop
89
95
  def process_node(node, seen_element: nil)
90
96
  return if @order_violation_reported
91
97
 
92
- node = ActiveModelNodeDecorator.new(node)
98
+ node = ActiveModelNodeDecorator.new(node, misc_method_names: misc_method_names)
93
99
  seen_element ||= node.node_type
94
100
 
95
101
  return unless seen_element
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dark_finger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Professor Wang Matrix PhD
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2018-10-04 00:00:00.000000000 Z
12
+ date: 2018-10-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -123,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
123
123
  version: '0'
124
124
  requirements: []
125
125
  rubyforge_project:
126
- rubygems_version: 2.7.6
126
+ rubygems_version: 2.5.2.1
127
127
  signing_key:
128
128
  specification_version: 4
129
129
  summary: ActiveModel layout cop for Rubocop