annotate_model 0.1.2 → 0.2.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 +26 -3
- data/lib/annotate_model/annotation_decider.rb +8 -0
- data/lib/annotate_model/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 702f03dcd1fc38f6e6d05d4f9c49b0c13f8491629f0c6999c1176ee2e51042a9
|
4
|
+
data.tar.gz: 6b12bfc2604b2fe1947f44bf4f489605c12ab54afd9f6bf3321b69c588ce2a08
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 74b2b1467ac782f82d9c94ad0f8c0a3d82f713161990b38c9f1eec7a3fa23e34f97883c2659822dca343c693ae466a4db0a591ec08cf61f7bd940e4fbe494dc7
|
7
|
+
data.tar.gz: 14542f117a30d48faa47e79df28c971b01be998fffc0db4bd7d40d6f9b2d5be9c5d1d360fa6710382af8baa53e49ae17a5869454b52695b999cdca18060942bf
|
data/README.md
CHANGED
@@ -1,7 +1,10 @@
|
|
1
|
-
# AnnotateModel [![Gem Version]
|
1
|
+
# AnnotateModel [![Gem Version][]][gem-version]
|
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=1
|
6
|
+
[gem-version]: https://rubygems.org/gems/annotate_model
|
7
|
+
|
5
8
|
## Example
|
6
9
|
|
7
10
|
Here's an example of the schema information in your model file after annotation:
|
@@ -16,6 +19,18 @@ class Product < ApplicationRecord
|
|
16
19
|
end
|
17
20
|
```
|
18
21
|
|
22
|
+
```ruby
|
23
|
+
# == Schema Information
|
24
|
+
#
|
25
|
+
# id :integer not null
|
26
|
+
# name :string
|
27
|
+
# email :string
|
28
|
+
# created_at :datetime not null
|
29
|
+
# updated_at :datetime not null
|
30
|
+
class Admin::User < ApplicationRecord
|
31
|
+
end
|
32
|
+
```
|
33
|
+
|
19
34
|
## Installation
|
20
35
|
|
21
36
|
Add this line to the application's Gemfile:
|
@@ -36,11 +51,19 @@ gem install annotate_model
|
|
36
51
|
|
37
52
|
To annotate all models, run:
|
38
53
|
|
39
|
-
`bundle exec annotate_model
|
54
|
+
`bundle exec annotate_model`
|
40
55
|
|
41
56
|
To annotate specific models, run:
|
42
57
|
|
43
|
-
`bundle exec annotate_model
|
58
|
+
`bundle exec annotate_model Product Admin::User`
|
59
|
+
|
60
|
+
## Skipping Annotation
|
61
|
+
|
62
|
+
If you want to skip annotation for a specific model, add the following skip flag to the model file:
|
63
|
+
|
64
|
+
```ruby
|
65
|
+
# == annotate_model:skip
|
66
|
+
```
|
44
67
|
|
45
68
|
## Development
|
46
69
|
|
@@ -2,11 +2,15 @@
|
|
2
2
|
|
3
3
|
module AnnotateModel
|
4
4
|
class AnnotationDecider
|
5
|
+
SKIP_FLAG = "# == annotate_model:skip"
|
6
|
+
|
5
7
|
def initialize(file)
|
6
8
|
@file = file
|
7
9
|
end
|
8
10
|
|
9
11
|
def annotate?
|
12
|
+
return false if skip_flag_present?
|
13
|
+
|
10
14
|
begin
|
11
15
|
klass = @file.model_name.constantize
|
12
16
|
rescue NameError
|
@@ -18,6 +22,10 @@ module AnnotateModel
|
|
18
22
|
|
19
23
|
private
|
20
24
|
|
25
|
+
def skip_flag_present?
|
26
|
+
File.foreach(@file.to_s).any? { |line| line.include?(SKIP_FLAG) }
|
27
|
+
end
|
28
|
+
|
21
29
|
def annotate_conditions(klass)
|
22
30
|
[
|
23
31
|
klass.is_a?(Class),
|