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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f530a132985bc423c3f6a32005be46df58acddc550bdd68dce0658010407d4e7
4
- data.tar.gz: d57060bbee598d5914359717d716a80ff3b60463993e62fb15ee66d3843cd723
3
+ metadata.gz: 702f03dcd1fc38f6e6d05d4f9c49b0c13f8491629f0c6999c1176ee2e51042a9
4
+ data.tar.gz: 6b12bfc2604b2fe1947f44bf4f489605c12ab54afd9f6bf3321b69c588ce2a08
5
5
  SHA512:
6
- metadata.gz: 6a0f926c606fbfdf0346a9e7e5f2161cbc1315cddd6c03ba3a2b2b6d2e5962564bd9a7cffb905b9e3a25c56a65bdc35dd45e0442687a481f3e950d861792fd1d
7
- data.tar.gz: 44a4d4409f9605ce19972c9a111cded649ccdc7c0c6b0c23c8faf66a7e22d9ad79e6e1fcb1cfcacdd7934d22075046d32aee194746ffaeb18ce5c1790eca951b
6
+ metadata.gz: 74b2b1467ac782f82d9c94ad0f8c0a3d82f713161990b38c9f1eec7a3fa23e34f97883c2659822dca343c693ae466a4db0a591ec08cf61f7bd940e4fbe494dc7
7
+ data.tar.gz: 14542f117a30d48faa47e79df28c971b01be998fffc0db4bd7d40d6f9b2d5be9c5d1d360fa6710382af8baa53e49ae17a5869454b52695b999cdca18060942bf
data/README.md CHANGED
@@ -1,7 +1,10 @@
1
- # AnnotateModel [![Gem Version](https://badge.fury.io/rb/annotate_model.svg)](https://badge.fury.io/rb/annotate_model)
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 --all`
54
+ `bundle exec annotate_model`
40
55
 
41
56
  To annotate specific models, run:
42
57
 
43
- `bundle exec annotate_model [model_name1] [model_name2] ...`
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),
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AnnotateModel
4
- VERSION = "0.1.2"
4
+ VERSION = "0.2.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: annotate_model
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Taeyang Lee