fat_model_finder 0.1.0
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 +7 -0
- data/.rubocop.yml +16 -0
- data/Gemfile +18 -0
- data/Gemfile.lock +62 -0
- data/LICENSE.txt +21 -0
- data/README.md +39 -0
- data/Rakefile +16 -0
- data/fat_model_finder.gemspec +40 -0
- data/lib/fat_model_finder/file_data.rb +97 -0
- data/lib/fat_model_finder/file_data_presenter.rb +60 -0
- data/lib/fat_model_finder/version.rb +5 -0
- data/lib/fat_model_finder.rb +110 -0
- data/sig/fat_model_finder.rbs +4 -0
- metadata +142 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b9a30d1580e0dc9d1966d74185b29372007beea368312f00fdd087eaf392d811
|
4
|
+
data.tar.gz: 986451dcaa07049fc205e6b03b024a9a6b0911be5db516d6a631598e0a309fc5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5ab672193131ada1a0c5517b2d20b197244e53b0f387c66fd63390cb23f7764f9629ada620a5f0f5f461c9aad853d1dc629cfc87da61fdf21e489b24c5e0e507
|
7
|
+
data.tar.gz: 8f4928672bb948f089f69abb7f96e38a8b6197d6578f662e4f73ed44c849326ef389cc9f4762558d3b461ac75712b41462977abeb441b4817c52725809b5ff8b
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.6
|
3
|
+
|
4
|
+
Style/StringLiterals:
|
5
|
+
Enabled: true
|
6
|
+
EnforcedStyle: double_quotes
|
7
|
+
|
8
|
+
Style/StringLiteralsInInterpolation:
|
9
|
+
Enabled: true
|
10
|
+
EnforcedStyle: double_quotes
|
11
|
+
|
12
|
+
Layout/LineLength:
|
13
|
+
Max: 120
|
14
|
+
|
15
|
+
Metrics/MethodLength:
|
16
|
+
Max: 20
|
data/Gemfile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
# Specify your gem's dependencies in fat_model_finder.gemspec
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
gem "rake", "~> 13.0"
|
9
|
+
|
10
|
+
gem "minitest", "~> 5.0"
|
11
|
+
|
12
|
+
gem "rubocop", "~> 1.21"
|
13
|
+
|
14
|
+
gem 'thor'
|
15
|
+
|
16
|
+
gem 'colorize'
|
17
|
+
|
18
|
+
gem 'pry', require: false
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
fat_model_finder (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
ast (2.4.3)
|
10
|
+
coderay (1.1.3)
|
11
|
+
colorize (1.1.0)
|
12
|
+
json (2.13.2)
|
13
|
+
language_server-protocol (3.17.0.5)
|
14
|
+
lint_roller (1.1.0)
|
15
|
+
method_source (1.1.0)
|
16
|
+
minitest (5.25.5)
|
17
|
+
parallel (1.27.0)
|
18
|
+
parser (3.3.9.0)
|
19
|
+
ast (~> 2.4.1)
|
20
|
+
racc
|
21
|
+
prism (1.4.0)
|
22
|
+
pry (0.15.2)
|
23
|
+
coderay (~> 1.1)
|
24
|
+
method_source (~> 1.0)
|
25
|
+
racc (1.8.1)
|
26
|
+
rainbow (3.1.1)
|
27
|
+
rake (13.3.0)
|
28
|
+
regexp_parser (2.11.2)
|
29
|
+
rubocop (1.80.2)
|
30
|
+
json (~> 2.3)
|
31
|
+
language_server-protocol (~> 3.17.0.2)
|
32
|
+
lint_roller (~> 1.1.0)
|
33
|
+
parallel (~> 1.10)
|
34
|
+
parser (>= 3.3.0.2)
|
35
|
+
rainbow (>= 2.2.2, < 4.0)
|
36
|
+
regexp_parser (>= 2.9.3, < 3.0)
|
37
|
+
rubocop-ast (>= 1.46.0, < 2.0)
|
38
|
+
ruby-progressbar (~> 1.7)
|
39
|
+
unicode-display_width (>= 2.4.0, < 4.0)
|
40
|
+
rubocop-ast (1.46.0)
|
41
|
+
parser (>= 3.3.7.2)
|
42
|
+
prism (~> 1.4)
|
43
|
+
ruby-progressbar (1.13.0)
|
44
|
+
thor (1.4.0)
|
45
|
+
unicode-display_width (3.2.0)
|
46
|
+
unicode-emoji (~> 4.1)
|
47
|
+
unicode-emoji (4.1.0)
|
48
|
+
|
49
|
+
PLATFORMS
|
50
|
+
arm64-darwin-22
|
51
|
+
|
52
|
+
DEPENDENCIES
|
53
|
+
colorize
|
54
|
+
fat_model_finder!
|
55
|
+
minitest (~> 5.0)
|
56
|
+
pry
|
57
|
+
rake (~> 13.0)
|
58
|
+
rubocop (~> 1.21)
|
59
|
+
thor
|
60
|
+
|
61
|
+
BUNDLED WITH
|
62
|
+
2.4.10
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2025 Max Normand
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# FatModelFinder
|
2
|
+
|
3
|
+
Whats the only kind of Model a Ruby Developer can get?
|
4
|
+
|
5
|
+
A Fat one...
|
6
|
+
|
7
|
+
FatModelFinder is a CLI tool designed to help developers identify "fat models" in their Rails applications. It scans the `/app/models` directory, analyzes each model file, and determines whether the model is "fat" based on conditions defined in this gem.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
To install the gem and add it to your application's Gemfile, execute:
|
12
|
+
|
13
|
+
$ bundle add fat_model_finder
|
14
|
+
|
15
|
+
If Bundler is not being used to manage dependencies, install the gem by executing:
|
16
|
+
|
17
|
+
$ gem install fat_model_finder
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
After installing the gem, you can use the CLI tool to scan your Rails application's models. Navigate to the root directory of your Rails application and run:
|
22
|
+
|
23
|
+
1. To scan the models and save the fat model data into a JSON file named `file_data`:
|
24
|
+
|
25
|
+
```bash
|
26
|
+
$ bin/fat_model_finder scan
|
27
|
+
```
|
28
|
+
|
29
|
+
2. To display the fat models based on the saved JSON data:
|
30
|
+
|
31
|
+
```bash
|
32
|
+
$ bin/fat_model_finder show_fat_models
|
33
|
+
```
|
34
|
+
|
35
|
+
The `scan` command analyzes the models in the `/app/models` directory and saves the results in a JSON file. The `show_fat_models` command parses the JSON file and outputs the fat model data to the user.
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "bundler/gem_tasks"
|
4
|
+
require "rake/testtask"
|
5
|
+
|
6
|
+
Rake::TestTask.new(:test) do |t|
|
7
|
+
t.libs << "test"
|
8
|
+
t.libs << "lib"
|
9
|
+
t.test_files = FileList["test/**/test_*.rb"]
|
10
|
+
end
|
11
|
+
|
12
|
+
require "rubocop/rake_task"
|
13
|
+
|
14
|
+
RuboCop::RakeTask.new
|
15
|
+
|
16
|
+
task default: %i[test rubocop]
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/fat_model_finder/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "fat_model_finder"
|
7
|
+
spec.version = FatModelFinder::VERSION
|
8
|
+
spec.authors = ["Max Normand"]
|
9
|
+
spec.email = ["maxnormand97@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = "Working on a new app? Want to find Fat Models, use ME"
|
12
|
+
spec.description = "A CLI tool that scans the `/app/models` directory in a Rails application to identify 'fat models' based on conditions defined in this gem."
|
13
|
+
spec.homepage = "https://github.com/maxnormand97"
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.required_ruby_version = ">= 2.6.0"
|
16
|
+
|
17
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
18
|
+
spec.metadata["source_code_uri"] = "https://github.com/maxnormand97/fat_model_finder"
|
19
|
+
|
20
|
+
# Specify which files should be added to the gem when it is released.
|
21
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
22
|
+
spec.files = Dir.chdir(__dir__) do
|
23
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
24
|
+
(File.expand_path(f) == __FILE__) || f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor])
|
25
|
+
end
|
26
|
+
end
|
27
|
+
spec.bindir = "exe"
|
28
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
29
|
+
spec.require_paths = ["lib"]
|
30
|
+
|
31
|
+
# Runtime dependencies
|
32
|
+
spec.add_dependency "thor"
|
33
|
+
spec.add_dependency "colorize"
|
34
|
+
|
35
|
+
# Development dependencies
|
36
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
37
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
38
|
+
spec.add_development_dependency "rubocop", "~> 1.21"
|
39
|
+
spec.add_development_dependency "pry"
|
40
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module FatModelFinder
|
4
|
+
# Class to store attributes of file data, later to be parsed to JSON file for storage
|
5
|
+
class FileData
|
6
|
+
# TODO: we can have a method that overrides these rules and is configurable by the user later. These can just be
|
7
|
+
# set as the default values...
|
8
|
+
METHOD_THRESHOLD = 10
|
9
|
+
CALLBACK_THRESHOLD = 5
|
10
|
+
VALIDATION_THRESHOLD = 5
|
11
|
+
ASSOCIATION_THRESHOLD = 5
|
12
|
+
LINE_COUNT_THRESHOLD = 300
|
13
|
+
|
14
|
+
attr_accessor :line_count, :file_name, :file_size, :file_extension, :last_modified, :word_count, :char_count,
|
15
|
+
:is_empty, :file, :method_count, :callback_count, :association_count, :validation_count, :fat,
|
16
|
+
:fat_model_data
|
17
|
+
|
18
|
+
def initialize(file:)
|
19
|
+
@file = file
|
20
|
+
@method_count = nil
|
21
|
+
@callback_count = nil
|
22
|
+
@association_count = nil
|
23
|
+
@validation_count = nil
|
24
|
+
@fat = false
|
25
|
+
@fat_model_data = {}
|
26
|
+
end
|
27
|
+
|
28
|
+
def set_base_attributes
|
29
|
+
@line_count = File.foreach(@file).count
|
30
|
+
@file_name = File.basename(@file)
|
31
|
+
@file_size = File.size(@file)
|
32
|
+
@file_extension = File.extname(@file)
|
33
|
+
@last_modified = File.mtime(@file)
|
34
|
+
@word_count = File.read(@file).split.size
|
35
|
+
@char_count = File.read(@file).length
|
36
|
+
@is_empty = File.zero?(@file)
|
37
|
+
end
|
38
|
+
|
39
|
+
# Convert the object to a hash for JSON serialization
|
40
|
+
def to_h
|
41
|
+
{
|
42
|
+
file_name: @file_name,
|
43
|
+
file_size: @file_size,
|
44
|
+
file_extension: @file_extension,
|
45
|
+
last_modified: @last_modified,
|
46
|
+
line_count: @line_count,
|
47
|
+
word_count: @word_count,
|
48
|
+
char_count: @char_count,
|
49
|
+
is_empty: @is_empty,
|
50
|
+
method_count: @method_count,
|
51
|
+
callback_count: @callback_count,
|
52
|
+
association_count: @association_count,
|
53
|
+
validation_count: @validation_count,
|
54
|
+
fat: @fat,
|
55
|
+
fat_model_data: @fat_model_data
|
56
|
+
}
|
57
|
+
end
|
58
|
+
|
59
|
+
def count_methods
|
60
|
+
file_content = File.read(@file)
|
61
|
+
@method_count = file_content.scan(/^\s*def\s+/).size
|
62
|
+
end
|
63
|
+
|
64
|
+
def count_callbacks
|
65
|
+
file_content = File.read(@file)
|
66
|
+
# Match Active Record callbacks like before_save, after_create, etc.
|
67
|
+
@callback_count = file_content.scan(/^\s*(before_|after_)\w+/).size
|
68
|
+
end
|
69
|
+
|
70
|
+
def count_associations
|
71
|
+
file_content = File.read(@file)
|
72
|
+
# Match Active Record associations like has_many, belongs_to, etc.
|
73
|
+
@association_count = file_content.scan(/^\s*(has_many|has_one|belongs_to|has_and_belongs_to_many)/).size
|
74
|
+
end
|
75
|
+
|
76
|
+
def count_validations
|
77
|
+
file_content = File.read(@file)
|
78
|
+
# Match both `validates` and `validate` for validations
|
79
|
+
@validation_count = file_content.scan(/^\s*(validates|validate)\b/).size
|
80
|
+
end
|
81
|
+
|
82
|
+
def calculate_if_fat_model
|
83
|
+
@fat_model_data = {
|
84
|
+
method_count_high: @method_count.to_i > METHOD_THRESHOLD,
|
85
|
+
callback_count_high: @callback_count.to_i > CALLBACK_THRESHOLD,
|
86
|
+
association_count_high: @association_count.to_i > ASSOCIATION_THRESHOLD,
|
87
|
+
validation_count_high: @validation_count.to_i > VALIDATION_THRESHOLD,
|
88
|
+
line_count_high: @line_count.to_i > LINE_COUNT_THRESHOLD
|
89
|
+
}
|
90
|
+
|
91
|
+
# A model is considered fat if greater than or eq to 2 of the conditions are true OR the line count is huge
|
92
|
+
@fat = @fat_model_data.values.count(true) >= 2 || @fat_model_data[:line_count_high]
|
93
|
+
end
|
94
|
+
|
95
|
+
# TODO: find the longest method...
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module FatModelFinder
|
4
|
+
# Presentation helper methods to output fat model data
|
5
|
+
# rubocop:disable Layout/LineLength
|
6
|
+
class FileDataPresenter
|
7
|
+
# rubocop:disable Metrics/AbcSize
|
8
|
+
def self.display(file_data:)
|
9
|
+
puts "File Name: #{file_data.file_name.colorize(:green)}"
|
10
|
+
puts "File Size: #{file_data.file_size} bytes".colorize(:green)
|
11
|
+
puts "File Extension: #{file_data.file_extension.colorize(:green)}"
|
12
|
+
puts "Last Modified: #{file_data.last_modified.to_s.colorize(:green)}"
|
13
|
+
|
14
|
+
puts "Line Count: #{colorize_threshold(file_data.line_count, FatModelFinder::FileData::LINE_COUNT_THRESHOLD)}"
|
15
|
+
puts "Word Count: #{file_data.word_count.to_s.colorize(:green)}"
|
16
|
+
puts "Character Count: #{file_data.char_count.to_s.colorize(:green)}"
|
17
|
+
puts "Is Empty: #{file_data.is_empty ? "Yes".colorize(:red) : "No".colorize(:green)}"
|
18
|
+
|
19
|
+
puts "Method Count: #{colorize_threshold(file_data.method_count, FatModelFinder::FileData::METHOD_THRESHOLD)}"
|
20
|
+
puts "Callback Count: #{colorize_threshold(file_data.callback_count, FatModelFinder::FileData::CALLBACK_THRESHOLD)}"
|
21
|
+
puts "Association Count: #{colorize_threshold(file_data.association_count, FatModelFinder::FileData::ASSOCIATION_THRESHOLD)}"
|
22
|
+
puts "Validation Count: #{colorize_threshold(file_data.validation_count, FatModelFinder::FileData::VALIDATION_THRESHOLD)}"
|
23
|
+
puts "\n"
|
24
|
+
end
|
25
|
+
# rubocop:enable Metrics/AbcSize
|
26
|
+
|
27
|
+
def self.present_fat_model(json_data:)
|
28
|
+
file_name = json_data["file_name"]
|
29
|
+
fat_model_data = json_data["fat_model_data"] || {}
|
30
|
+
|
31
|
+
file_name_message = "The model in file '#{file_name.colorize(:red)}' is considered fat due to the following issues:"
|
32
|
+
|
33
|
+
breakdown = fat_model_data.select { |_key, value| value == true }
|
34
|
+
breakdown_message = breakdown.map { |key, _| "- #{key.to_s.gsub("_", " ").capitalize}".colorize(:red) }.join("\n")
|
35
|
+
|
36
|
+
puts "#{file_name_message}\n#{breakdown_message}\n\n"
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.display_tips
|
40
|
+
tips = <<~TIPS
|
41
|
+
To address these issues:
|
42
|
+
- Reduce the number of methods by moving business logic to service objects or concerns.
|
43
|
+
- Minimize callbacks by using them sparingly and considering alternative patterns.
|
44
|
+
- Simplify associations by ensuring they are necessary and not overly complex.
|
45
|
+
- Break down validations into smaller, reusable components if possible.
|
46
|
+
- If the line count is high, split the model into smaller, more focused classes.
|
47
|
+
|
48
|
+
Remember, the goal is to keep your models focused and maintainable.
|
49
|
+
TIPS
|
50
|
+
|
51
|
+
puts tips
|
52
|
+
end
|
53
|
+
|
54
|
+
# Flag fat model conditions that have passed
|
55
|
+
def self.colorize_threshold(value, threshold)
|
56
|
+
value.to_i > threshold ? value.to_s.colorize(:red) + " - (LIMIT EXCEEDED)".colorize(:red) : value.to_s.colorize(:green)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
# rubocop:enable Layout/LineLength
|
60
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "thor"
|
4
|
+
require "json"
|
5
|
+
require "colorize"
|
6
|
+
require_relative "fat_model_finder/version"
|
7
|
+
require_relative "fat_model_finder/file_data"
|
8
|
+
require_relative "fat_model_finder/file_data_presenter"
|
9
|
+
|
10
|
+
module FatModelFinder
|
11
|
+
class Error < StandardError; end
|
12
|
+
|
13
|
+
# Interface for the program to the CLI
|
14
|
+
class CLI < Thor
|
15
|
+
DATA_FILE = "file_data.json"
|
16
|
+
|
17
|
+
# rubocop:disable Metrics/BlockLength
|
18
|
+
no_commands do
|
19
|
+
def load_file_data
|
20
|
+
if File.exist?(DATA_FILE)
|
21
|
+
file_content = File.read(DATA_FILE)
|
22
|
+
file_content.empty? ? [] : JSON.parse(file_content)
|
23
|
+
else
|
24
|
+
[]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def purge_file_data
|
29
|
+
File.write("file_data.json", "[]") if File.exist?("file_data.json")
|
30
|
+
end
|
31
|
+
|
32
|
+
def save_file_data(data)
|
33
|
+
# Clear the file data by overwriting with an empty array
|
34
|
+
File.write(DATA_FILE, JSON.dump([])) if File.exist?(DATA_FILE)
|
35
|
+
|
36
|
+
File.write(DATA_FILE, JSON.dump(data))
|
37
|
+
puts "Updated file data saved to #{DATA_FILE}"
|
38
|
+
end
|
39
|
+
|
40
|
+
def directory_exists?(directory)
|
41
|
+
unless Dir.exist?(directory)
|
42
|
+
puts "Directory not found: #{directory}"
|
43
|
+
return false
|
44
|
+
end
|
45
|
+
true
|
46
|
+
end
|
47
|
+
|
48
|
+
def process_file(file, all_file_data)
|
49
|
+
return if all_file_data.any? { |entry| entry["file"] == file }
|
50
|
+
|
51
|
+
puts "#{file} - Adding new file"
|
52
|
+
file_data = create_file_data(file)
|
53
|
+
FileDataPresenter.display(file_data: file_data)
|
54
|
+
all_file_data << file_data.to_h
|
55
|
+
end
|
56
|
+
|
57
|
+
def create_file_data(file)
|
58
|
+
create_file_data = FileData.new(file: file)
|
59
|
+
create_file_data.set_base_attributes
|
60
|
+
create_file_data.count_methods
|
61
|
+
create_file_data.count_callbacks
|
62
|
+
create_file_data.count_associations
|
63
|
+
create_file_data.count_validations
|
64
|
+
create_file_data.calculate_if_fat_model
|
65
|
+
create_file_data
|
66
|
+
end
|
67
|
+
end
|
68
|
+
# rubocop:enable Metrics/BlockLength
|
69
|
+
|
70
|
+
# Command: Scan a directory
|
71
|
+
desc "scan DIRECTORY", "Scan a directory in a Rails app and save file data to a JSON file"
|
72
|
+
def scan(directory = "app/models")
|
73
|
+
puts "Scanning directory: #{directory}"
|
74
|
+
return unless directory_exists?(directory)
|
75
|
+
|
76
|
+
purge_file_data
|
77
|
+
|
78
|
+
all_file_data = load_file_data
|
79
|
+
files = Dir.glob("#{directory}/**/*")
|
80
|
+
|
81
|
+
files.each do |file|
|
82
|
+
next unless File.file?(file) # Skip directories
|
83
|
+
|
84
|
+
process_file(file, all_file_data)
|
85
|
+
end
|
86
|
+
|
87
|
+
save_file_data(all_file_data)
|
88
|
+
end
|
89
|
+
|
90
|
+
# Command: Show stored file data
|
91
|
+
desc "show_fat_models", "Output details based on file_data JSON file"
|
92
|
+
def show_fat_models
|
93
|
+
all_file_data = load_file_data
|
94
|
+
puts "No data found. Run 'scan' first." if all_file_data.empty?
|
95
|
+
|
96
|
+
fat_models = all_file_data.select { |record| record["fat"] == true }
|
97
|
+
|
98
|
+
if !fat_models.empty?
|
99
|
+
puts "Your Fat Models are..."
|
100
|
+
fat_models.each do |fat_model|
|
101
|
+
FileDataPresenter.present_fat_model(json_data: fat_model)
|
102
|
+
end
|
103
|
+
|
104
|
+
FileDataPresenter.display_tips
|
105
|
+
else
|
106
|
+
puts "Nothing to worry about you have no Fat Models!"
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
metadata
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fat_model_finder
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Max Normand
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2025-09-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: thor
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: colorize
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '13.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '13.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitest
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '5.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '5.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.21'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.21'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: A CLI tool that scans the `/app/models` directory in a Rails application
|
98
|
+
to identify 'fat models' based on conditions defined in this gem.
|
99
|
+
email:
|
100
|
+
- maxnormand97@gmail.com
|
101
|
+
executables: []
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- ".rubocop.yml"
|
106
|
+
- Gemfile
|
107
|
+
- Gemfile.lock
|
108
|
+
- LICENSE.txt
|
109
|
+
- README.md
|
110
|
+
- Rakefile
|
111
|
+
- fat_model_finder.gemspec
|
112
|
+
- lib/fat_model_finder.rb
|
113
|
+
- lib/fat_model_finder/file_data.rb
|
114
|
+
- lib/fat_model_finder/file_data_presenter.rb
|
115
|
+
- lib/fat_model_finder/version.rb
|
116
|
+
- sig/fat_model_finder.rbs
|
117
|
+
homepage: https://github.com/maxnormand97
|
118
|
+
licenses:
|
119
|
+
- MIT
|
120
|
+
metadata:
|
121
|
+
homepage_uri: https://github.com/maxnormand97
|
122
|
+
source_code_uri: https://github.com/maxnormand97/fat_model_finder
|
123
|
+
post_install_message:
|
124
|
+
rdoc_options: []
|
125
|
+
require_paths:
|
126
|
+
- lib
|
127
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 2.6.0
|
132
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
133
|
+
requirements:
|
134
|
+
- - ">="
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '0'
|
137
|
+
requirements: []
|
138
|
+
rubygems_version: 3.4.10
|
139
|
+
signing_key:
|
140
|
+
specification_version: 4
|
141
|
+
summary: Working on a new app? Want to find Fat Models, use ME
|
142
|
+
test_files: []
|