dark_finger 0.3.1 → 0.4.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
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: '0962a291b4b5701f5523c84ecbd4865afe91953e5a40ce3c3467a92d31dfba1a'
|
4
|
+
data.tar.gz: b6bbe7abfa4d16caca2ec60a3090435d4498db374ec2e0bd451608ccaa747ee8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5f60cc6dd2325e4a9c758170250b5daadfb3bec991bdeab141cd6fc864d4df4300430d94bffc8bbaac9abf3b4c1e7e7de9c7037f7124f815d2343e6f0b74ac31
|
7
|
+
data.tar.gz: 57732e831e03a50c242bbaf05661879b10781cf30bf389f374e1bca173889c06862a6a17cf40a43b3701806613561cb63bbcc9fe21bed69d20c9c02e6a8698b9
|
Binary file
|
data/README.md
CHANGED
@@ -1,23 +1,68 @@
|
|
1
|
-
|
1
|
+
![Dark Finger](.github/dark_finger.jpg "Dark Finger")
|
2
2
|
|
3
|
-
A Rubocop extension to check the layout of ActiveModel files.
|
4
|
-
check that elements appear together, in the right order, and commented as
|
5
|
-
desired.
|
3
|
+
A Rubocop extension to check the layout of ActiveModel files.
|
6
4
|
|
7
|
-
|
5
|
+
At work we've found that, as our model files grow in size, there are many
|
6
|
+
"macro" methods (scopes, validations, etc) at the top that become messy and
|
7
|
+
inconsistent across files.
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
* callbacks
|
12
|
-
* constants
|
13
|
-
* enums
|
14
|
-
* includes
|
15
|
-
* modules
|
16
|
-
* scopes
|
17
|
-
* validations
|
18
|
-
* class_methods
|
19
|
-
* instance_methods
|
9
|
+
To help keep things orderly over time we wrote ... _**Dark Finger**_. This
|
10
|
+
Cop will issue warnings if the various model elements:
|
20
11
|
|
12
|
+
1. Aren't grouped together
|
13
|
+
2. The groups don't appear in the right order
|
14
|
+
3. The groups aren't commented properly
|
15
|
+
|
16
|
+
This is the kind of model file that we like. Notice how all the model elements
|
17
|
+
are grouped, commented, and ordered (although ordering is not visible from just
|
18
|
+
one file):
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
class Horse < ApplicationRecord
|
22
|
+
## Includes ##
|
23
|
+
include GallopingMagicPowers
|
24
|
+
include LazerEyes
|
25
|
+
|
26
|
+
## Enums ##
|
27
|
+
enum breed: %i[thoroughbred
|
28
|
+
arabian
|
29
|
+
american quarter horse
|
30
|
+
clydesdale
|
31
|
+
mustang]
|
32
|
+
|
33
|
+
## Associations ##
|
34
|
+
has_many :legs
|
35
|
+
belongs_to :brain
|
36
|
+
belongs_to :saddle
|
37
|
+
|
38
|
+
## Validations ##
|
39
|
+
validates_presence_of :breed
|
40
|
+
validates_presence_of :age
|
41
|
+
|
42
|
+
## Scopes ##
|
43
|
+
scope :dead, -> { where(state: 'dead') }
|
44
|
+
scope :alive, -> { where(state: 'alive') }
|
45
|
+
|
46
|
+
## Attributes ##
|
47
|
+
attr_accessor :promote_to_demon_horse
|
48
|
+
|
49
|
+
## Callbacks ##
|
50
|
+
after_save :callbacks_are_evil_you_should_be_ashamed
|
51
|
+
|
52
|
+
## Misc ##
|
53
|
+
serialize :nose_hairs, Array
|
54
|
+
acts_as_taggable
|
55
|
+
|
56
|
+
def self.foobario
|
57
|
+
# foo
|
58
|
+
end
|
59
|
+
|
60
|
+
def gallop_hard
|
61
|
+
# ...
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
```
|
21
66
|
|
22
67
|
## Installation
|
23
68
|
|
@@ -35,23 +80,26 @@ Or install it yourself as:
|
|
35
80
|
|
36
81
|
$ gem install dark_finger
|
37
82
|
|
38
|
-
## Usage
|
83
|
+
## Usage and Configuration
|
39
84
|
|
40
85
|
Install the gem. Then, in your `.rubycop.yml` file, require `dark_finger` and
|
41
86
|
add your desired config.
|
42
87
|
|
43
|
-
For example
|
88
|
+
For example:
|
44
89
|
|
45
|
-
```
|
90
|
+
```yaml
|
46
91
|
# in .rubocop.yml
|
47
92
|
|
48
|
-
|
49
93
|
# this is required
|
50
94
|
require: dark_finger
|
51
95
|
|
52
96
|
DarkFinger/ModelStructure:
|
97
|
+
|
98
|
+
# this is also required
|
53
99
|
Include:
|
54
100
|
- 'app/models/*'
|
101
|
+
|
102
|
+
# specify the order that the model elements must appear in
|
55
103
|
required_order:
|
56
104
|
- module
|
57
105
|
- include
|
@@ -62,21 +110,44 @@ DarkFinger/ModelStructure:
|
|
62
110
|
- scope
|
63
111
|
- attributes
|
64
112
|
- callback
|
113
|
+
- misc
|
114
|
+
- constructor
|
65
115
|
- class_method
|
66
116
|
- instance_method
|
67
|
-
required_comments:
|
68
|
-
association: '# Relationships'
|
69
|
-
attribute: '# Attributes'
|
70
|
-
callback: '# Callbacks'
|
71
|
-
constant: '# Constants'
|
72
|
-
enum: '# Enums'
|
73
|
-
include: '# Includes'
|
74
|
-
module: '# Modules'
|
75
|
-
scope: '# Scopes'
|
76
|
-
validation: '# Validations'
|
77
117
|
|
118
|
+
# specify the comments that must appear above each group of model elements
|
119
|
+
required_comments:
|
120
|
+
association: '## Relationships ##'
|
121
|
+
attribute: '## Attributes ##'
|
122
|
+
callback: '## Callbacks ##'
|
123
|
+
constant: '## Constants ##'
|
124
|
+
enum: '## Enums ##'
|
125
|
+
include: '## Includes ##'
|
126
|
+
module: '## Modules ##'
|
127
|
+
scope: '## Scopes ##'
|
128
|
+
validation: '## Validations ##'
|
78
129
|
```
|
79
130
|
|
131
|
+
Supported model elements:
|
132
|
+
|
133
|
+
|
134
|
+
| Config key | Description (when not obvious) |
|
135
|
+
|-----------------|--------------------------------------------|
|
136
|
+
| association | |
|
137
|
+
| attribute | `attr_reader` and friends |
|
138
|
+
| callback | `after_save` et al. |
|
139
|
+
| class_method | |
|
140
|
+
| constant | |
|
141
|
+
| constructor | |
|
142
|
+
| enum | |
|
143
|
+
| include | |
|
144
|
+
| instance_method | |
|
145
|
+
| misc | This is a configurable set of method calls |
|
146
|
+
| module | Any `module Foo; ...; end` declarations |
|
147
|
+
| scope | Any `scope` or `default_scope` calls |
|
148
|
+
| validation | |
|
149
|
+
|
150
|
+
|
80
151
|
## License
|
81
152
|
|
82
153
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/lib/dark_finger/version.rb
CHANGED
@@ -114,10 +114,16 @@ module RuboCop
|
|
114
114
|
|
115
115
|
def process_node(node, seen_element: nil)
|
116
116
|
return if @order_violation_reported
|
117
|
+
return if @seen_private_declaration
|
117
118
|
|
118
119
|
node = ActiveModelNodeDecorator.new(node, misc_method_names: misc_method_names)
|
119
|
-
seen_element ||= node.node_type
|
120
120
|
|
121
|
+
if node.private_declaration?
|
122
|
+
@seen_private_declaration = true
|
123
|
+
return
|
124
|
+
end
|
125
|
+
|
126
|
+
seen_element ||= node.node_type
|
121
127
|
return unless seen_element
|
122
128
|
|
123
129
|
return if node.ignore_due_to_nesting?
|
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.
|
4
|
+
version: 0.4.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-
|
12
|
+
date: 2018-10-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -89,6 +89,7 @@ executables: []
|
|
89
89
|
extensions: []
|
90
90
|
extra_rdoc_files: []
|
91
91
|
files:
|
92
|
+
- ".github/dark_finger.jpg"
|
92
93
|
- ".gitignore"
|
93
94
|
- ".rspec"
|
94
95
|
- ".travis.yml"
|
@@ -123,7 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
123
124
|
version: '0'
|
124
125
|
requirements: []
|
125
126
|
rubyforge_project:
|
126
|
-
rubygems_version: 2.
|
127
|
+
rubygems_version: 2.7.6
|
127
128
|
signing_key:
|
128
129
|
specification_version: 4
|
129
130
|
summary: ActiveModel layout cop for Rubocop
|