annotaterb 4.2.0 → 4.3.1

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: 5864a6030a7b4cfbf7751761c07136690ebafe15393d67147789f70319036205
4
- data.tar.gz: a1dc2b99206b342bbd0dbc66795db4156abddfee307acecf6c2c383e8dbe89b1
3
+ metadata.gz: 638be873328bb99a7c5b8196ee15749e0c40e36fc3660204ceec28af42678f09
4
+ data.tar.gz: 0e88670fc1257d20e6282aaf4f510d8b2be29829983dce6c63bcfc4078deb996
5
5
  SHA512:
6
- metadata.gz: b7cbd03e31fdc24f27d23d700773c157eca461078cddcd87739605980d6f5f07887b59f345ef41d91994547d8efbc2b82595e454f9e4619a5fe4e0fb506d29cd
7
- data.tar.gz: f162544608cce0746a92250287ca4a5c7d25d151fe5bfe8bf4d18075834e98ce68939dc8b176dbe97d16f1f039a1a001cbb71066b26280f9fb5e83df763ba158
6
+ metadata.gz: 2142be1d47c96ac81a3ab97cfbb6d852ea952be8a179785b5cf48eadf9eec3e9ceff3588353a2d3efa6efeed071589664776948b96eda8e1df5cd4dd7335d0c6
7
+ data.tar.gz: e6cc12cc6d7110283ba23243cc27f355f594d71fc2f5ce5ee50f535f84bfb2e8e6a440546e86a4e2ffa1f300afd819321bb81968e7a235486605bd219c5284bb
data/CHANGELOG.md CHANGED
@@ -1,12 +1,22 @@
1
1
  # Changelog
2
2
 
3
- ## [Unreleased](https://github.com/drwl/annotaterb/tree/HEAD)
3
+ ## [v4.3.0](https://github.com/drwl/annotaterb/tree/v4.3.0) (2023-06-10)
4
4
 
5
- [Full Changelog](https://github.com/drwl/annotaterb/compare/v4.1.1...HEAD)
5
+ [Full Changelog](https://github.com/drwl/annotaterb/compare/v4.2.0...v4.3.0)
6
+
7
+ **Merged pull requests:**
8
+
9
+ - Bump version to v4.3.0 [\#41](https://github.com/drwl/annotaterb/pull/41) ([drwl](https://github.com/drwl))
10
+ - Add `ANNOTATERB_SKIP_ON_DB_TASKS` ENV var to skip auto annotations [\#40](https://github.com/drwl/annotaterb/pull/40) ([drwl](https://github.com/drwl))
11
+
12
+ ## [v4.2.0](https://github.com/drwl/annotaterb/tree/v4.2.0) (2023-06-02)
13
+
14
+ [Full Changelog](https://github.com/drwl/annotaterb/compare/v4.1.1...v4.2.0)
6
15
 
7
16
  **Merged pull requests:**
8
17
 
9
18
  - Specify `standard` gem version [\#39](https://github.com/drwl/annotaterb/pull/39) ([drwl](https://github.com/drwl))
19
+ - Generate changelog for 4.2 again [\#38](https://github.com/drwl/annotaterb/pull/38) ([drwl](https://github.com/drwl))
10
20
  - Bump version to v4.2.0 [\#37](https://github.com/drwl/annotaterb/pull/37) ([drwl](https://github.com/drwl))
11
21
  - Generate changelog for 4.2 [\#36](https://github.com/drwl/annotaterb/pull/36) ([drwl](https://github.com/drwl))
12
22
  - Improve tests for `ColumnAnnotation::*` [\#35](https://github.com/drwl/annotaterb/pull/35) ([drwl](https://github.com/drwl))
data/README.md CHANGED
@@ -59,6 +59,12 @@ $ bin/rails g annotate_rb:install
59
59
 
60
60
  This will copy a rake task into your Rails project's `lib/tasks` directory that will hook into the Rails project rake tasks, automatically running AnnotateRb after database migration rake tasks.
61
61
 
62
+ To skip the automatic annotation that happens after a db task, pass the environment variable `ANNOTATERB_SKIP_ON_DB_TASKS=1` before your command.
63
+
64
+ ```sh
65
+ $ ANNOTATERB_SKIP_ON_DB_TASKS=1 bin/rails db:migrate
66
+ ```
67
+
62
68
  ## Migrating from the annotate gem
63
69
  Refer to the [migration guide](MIGRATION_GUIDE.md).
64
70
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 4.2.0
1
+ 4.3.1
@@ -21,9 +21,10 @@ module AnnotateRb
21
21
 
22
22
  table_indices = @model.retrieve_indexes_from_table
23
23
  column_indices = table_indices.select { |ind| ind.columns.include?(@column.name) }
24
+ column_defaults = @model.column_defaults
24
25
 
25
- column_attributes = AttributesBuilder.new(@column, @options, is_primary_key, column_indices).build
26
- formatted_column_type = TypeBuilder.new(@column, @options).build
26
+ column_attributes = AttributesBuilder.new(@column, @options, is_primary_key, column_indices, column_defaults).build
27
+ formatted_column_type = TypeBuilder.new(@column, @options, column_defaults).build
27
28
 
28
29
  col_name = if @model.with_comments? && @column.comment
29
30
  "#{@column.name}(#{@column.comment.gsub(/\n/, '\\n')})"
@@ -7,8 +7,8 @@ module AnnotateRb
7
7
  # Don't show default value for these column types
8
8
  NO_DEFAULT_COL_TYPES = %w[json jsonb hstore].freeze
9
9
 
10
- def initialize(column, options, is_primary_key, column_indices)
11
- @column = ColumnWrapper.new(column)
10
+ def initialize(column, options, is_primary_key, column_indices, column_defaults)
11
+ @column = ColumnWrapper.new(column, column_defaults)
12
12
  @options = options
13
13
  @is_primary_key = is_primary_key
14
14
  @column_indices = column_indices
@@ -20,7 +20,7 @@ module AnnotateRb
20
20
  column_type = @column.column_type_string
21
21
  attrs = []
22
22
 
23
- unless @column.default.nil? || hide_default?
23
+ if !@column.raw_default.nil? && !hide_default?
24
24
  schema_default = "default(#{@column.default_string})"
25
25
 
26
26
  attrs << schema_default
@@ -4,18 +4,21 @@ module AnnotateRb
4
4
  module ModelAnnotator
5
5
  module ColumnAnnotation
6
6
  class ColumnWrapper
7
- def initialize(column)
7
+ def initialize(column, column_defaults)
8
8
  @column = column
9
+ @column_defaults = column_defaults
9
10
  end
10
11
 
11
- def default
12
- # Note: Used to be klass.column_defaults[name], where name is the column name.
13
- # Looks to be identical, but keeping note here in case there are differences.
14
- _column_default = @column.default
12
+ def raw_default
13
+ @column.default
14
+ end
15
+
16
+ def default_value
17
+ @column_defaults[@column.name]
15
18
  end
16
19
 
17
20
  def default_string
18
- quote(@column.default)
21
+ quote(default_value)
19
22
  end
20
23
 
21
24
  def type
@@ -8,8 +8,9 @@ module AnnotateRb
8
8
  # Example: show "integer" instead of "integer(4)"
9
9
  NO_LIMIT_COL_TYPES = %w[integer bigint boolean].freeze
10
10
 
11
- def initialize(column, options)
12
- @column = ColumnWrapper.new(column)
11
+ def initialize(column, options, column_defaults)
12
+ # Passing `column_defaults` for posterity, don't actually need it here since it's not used
13
+ @column = ColumnWrapper.new(column, column_defaults)
13
14
  @options = options
14
15
  end
15
16
 
@@ -1,6 +1,7 @@
1
1
  # This rake task was added by annotate_rb gem.
2
2
 
3
- if Rails.env.development?
3
+ # Can set `ANNOTATERB_SKIP_ON_DB_TASKS` to be anything to skip this
4
+ if Rails.env.development? && ENV["ANNOTATERB_SKIP_ON_DB_TASKS"].nil?
4
5
  require "annotate_rb"
5
6
 
6
7
  AnnotateRb::Core.load_rake_tasks
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: annotaterb
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.2.0
4
+ version: 4.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew W. Lee
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-06-02 00:00:00.000000000 Z
11
+ date: 2023-06-15 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Annotates Rails/ActiveRecord Models, routes, fixtures, and others based
14
14
  on the database schema.