annotate_model 0.1.1 → 0.1.2
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 +4 -4
- data/lib/annotate_model/annotator.rb +8 -15
- data/lib/annotate_model/model_file.rb +18 -0
- data/lib/annotate_model/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f530a132985bc423c3f6a32005be46df58acddc550bdd68dce0658010407d4e7
|
4
|
+
data.tar.gz: d57060bbee598d5914359717d716a80ff3b60463993e62fb15ee66d3843cd723
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a0f926c606fbfdf0346a9e7e5f2161cbc1315cddd6c03ba3a2b2b6d2e5962564bd9a7cffb905b9e3a25c56a65bdc35dd45e0442687a481f3e950d861792fd1d
|
7
|
+
data.tar.gz: 44a4d4409f9605ce19972c9a111cded649ccdc7c0c6b0c23c8faf66a7e22d9ad79e6e1fcb1cfcacdd7934d22075046d32aee194746ffaeb18ce5c1790eca951b
|
@@ -12,7 +12,6 @@ module AnnotateModel
|
|
12
12
|
|
13
13
|
def self.process_files(files)
|
14
14
|
run_files = []
|
15
|
-
skipped_files = []
|
16
15
|
failed_files = []
|
17
16
|
|
18
17
|
files.each do |file|
|
@@ -20,18 +19,16 @@ module AnnotateModel
|
|
20
19
|
case result
|
21
20
|
when :run
|
22
21
|
run_files << file
|
23
|
-
when :skipped
|
24
|
-
skipped_files << file
|
25
22
|
when :failed
|
26
23
|
failed_files << file
|
27
24
|
end
|
28
25
|
end
|
29
26
|
|
30
|
-
log_results(run_files,
|
27
|
+
log_results(run_files, failed_files)
|
31
28
|
end
|
32
29
|
|
33
30
|
def self.annotate_file(file)
|
34
|
-
return :
|
31
|
+
return :skipped unless AnnotationDecider.new(file).annotate?
|
35
32
|
|
36
33
|
content = File.read(file.to_s)
|
37
34
|
return :skipped if content.include?("# == Schema Information")
|
@@ -50,12 +47,10 @@ module AnnotateModel
|
|
50
47
|
end
|
51
48
|
|
52
49
|
def self.fetch_schema_info(file)
|
53
|
-
table_name = file.model_name.tableize
|
54
|
-
|
55
50
|
begin
|
56
|
-
columns = ActiveRecord::Base.connection.columns(table_name)
|
51
|
+
columns = ActiveRecord::Base.connection.columns(file.table_name)
|
57
52
|
rescue ActiveRecord::StatementInvalid
|
58
|
-
warn "Could not find table '#{table_name}'"
|
53
|
+
warn "Could not find table '#{file.table_name}'"
|
59
54
|
return
|
60
55
|
end
|
61
56
|
|
@@ -64,15 +59,13 @@ module AnnotateModel
|
|
64
59
|
end.join("\n")
|
65
60
|
end
|
66
61
|
|
67
|
-
def self.log_results(run_files,
|
68
|
-
puts "Annotated files
|
62
|
+
def self.log_results(run_files, failed_files)
|
63
|
+
puts "Annotated files:"
|
69
64
|
run_files.each { |file| puts " - #{file.relative_path}" }
|
70
65
|
|
71
|
-
puts "
|
72
|
-
skipped_files.each { |file| puts " - #{file.relative_path}" }
|
73
|
-
|
74
|
-
puts "Failed files (#{failed_files.size}):"
|
66
|
+
puts "Failed files:"
|
75
67
|
failed_files.each { |file| puts " - #{file.relative_path}" }
|
68
|
+
puts "#{run_files.size} runs, #{failed_files.size} failures"
|
76
69
|
end
|
77
70
|
end
|
78
71
|
end
|
@@ -11,10 +11,28 @@ module AnnotateModel
|
|
11
11
|
@file_path.relative_path_from(Rails.root).to_s
|
12
12
|
end
|
13
13
|
|
14
|
+
# Returns the model name corresponding to the model file path.
|
15
|
+
#
|
16
|
+
# @return [String] the model name corresponding to the model file path.
|
17
|
+
#
|
18
|
+
# @example
|
19
|
+
# For a file path "app/models/admin/user.rb", it returns "Admin::User".
|
20
|
+
# For a file path "app/models/product.rb", it returns "Product".
|
14
21
|
def model_name
|
15
22
|
@file_path.relative_path_from(Rails.root.join('app', 'models')).to_s.sub('.rb', '').camelize
|
16
23
|
end
|
17
24
|
|
25
|
+
# Returns the table name corresponding to the model file path.
|
26
|
+
#
|
27
|
+
# @return [String] the table name corresponding to the model file path.
|
28
|
+
#
|
29
|
+
# @example
|
30
|
+
# For a file path "app/models/admin/user.rb", it returns "admin_users".
|
31
|
+
# For a file path "app/models/product.rb", it returns "products".
|
32
|
+
def table_name
|
33
|
+
@file_path.relative_path_from(Rails.root.join('app', 'models')).to_s.sub('.rb', '').classify.tableize.sub('/', '_')
|
34
|
+
end
|
35
|
+
|
18
36
|
def to_s
|
19
37
|
@file_path.to_s
|
20
38
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: annotate_model
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Taeyang Lee
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-01-
|
11
|
+
date: 2025-01-21 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A lightweight gem to annotate Rails models based on the database schema.
|
14
14
|
email:
|