annotate_model 0.2.0 → 1.0.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 +4 -4
- data/README.md +5 -1
- data/lib/annotate_model/annotator.rb +7 -3
- 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: acaa898d77121490f69c9253e67f0da9788299581ca7baca9a91a02e7dde69d8
|
4
|
+
data.tar.gz: d600bb6a190d68a3aa29b6e3159956b3da07d80bb521ba9feaf65b7e70fb875b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8c7757e023d793050a2e4b0f99b0fbca36e3a8f157213c85a1d3b10d81fe751a8876751a7b851af0347bc007b10909301a1b8d3de7927ebab159fad3842fb236
|
7
|
+
data.tar.gz: 7d38492f6fcdfc8ce390c595eb2c6caf398c501d249eb873df835a57342e5fa0fd462a6b4c6087d2f1544b2139c4bf8c7cceee0e413eb792a925233af57ae478
|
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
AnnotateModel is a lightweight gem to annotate Rails models with database schema information.
|
4
4
|
|
5
|
-
[Gem Version]: https://badge.fury.io/rb/annotate_model.svg?v=
|
5
|
+
[Gem Version]: https://badge.fury.io/rb/annotate_model.svg?v=2
|
6
6
|
[gem-version]: https://rubygems.org/gems/annotate_model
|
7
7
|
|
8
8
|
## Example
|
@@ -15,6 +15,7 @@ Here's an example of the schema information in your model file after annotation:
|
|
15
15
|
# name :string
|
16
16
|
# created_at :datetime not null
|
17
17
|
# updated_at :datetime not null
|
18
|
+
# ==
|
18
19
|
class Product < ApplicationRecord
|
19
20
|
end
|
20
21
|
```
|
@@ -27,10 +28,13 @@ end
|
|
27
28
|
# email :string
|
28
29
|
# created_at :datetime not null
|
29
30
|
# updated_at :datetime not null
|
31
|
+
# ==
|
30
32
|
class Admin::User < ApplicationRecord
|
31
33
|
end
|
32
34
|
```
|
33
35
|
|
36
|
+
The annotation block is re-written each time the command runs. The starting line `# == Schema Information` and the ending line `# ==` should never be changed as they are important for the regex match used to remove existing annotations.
|
37
|
+
|
34
38
|
## Installation
|
35
39
|
|
36
40
|
Add this line to the application's Gemfile:
|
@@ -30,22 +30,26 @@ module AnnotateModel
|
|
30
30
|
def self.annotate_file(file)
|
31
31
|
return :skipped unless AnnotationDecider.new(file).annotate?
|
32
32
|
|
33
|
-
content = File.read(file.to_s)
|
34
|
-
return :skipped if content.include?("# == Schema Information")
|
35
|
-
|
36
33
|
schema_info = fetch_schema_info(file)
|
37
34
|
return :failed unless schema_info
|
38
35
|
|
36
|
+
content = File.read(file.to_s)
|
37
|
+
content = remove_existing_annotation(content)
|
39
38
|
annotated_content = <<~ANNOTATION + content
|
40
39
|
# == Schema Information
|
41
40
|
#
|
42
41
|
#{schema_info}
|
42
|
+
# ==
|
43
43
|
ANNOTATION
|
44
44
|
|
45
45
|
File.write(file.to_s, annotated_content)
|
46
46
|
:run
|
47
47
|
end
|
48
48
|
|
49
|
+
def self.remove_existing_annotation(content)
|
50
|
+
content.sub(/^# == Schema Information\n(#.*\n)*# ==\n/m, '')
|
51
|
+
end
|
52
|
+
|
49
53
|
def self.fetch_schema_info(file)
|
50
54
|
begin
|
51
55
|
columns = ActiveRecord::Base.connection.columns(file.table_name)
|
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.
|
4
|
+
version: 1.0.0
|
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-22 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:
|