Commit 2949cd43 by Andrew W. Lee

Merge branch 'release/3.0.3'

parents 111640d0 a3793cdc
template: |
## What's Changed
$CHANGES
name: CI
on:
pull_request:
branches:
- '*'
push:
branches:
- '*'
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
ruby:
- 2.3.x
- 2.4.x
- 2.6.x
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Setup Ruby
uses: actions/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
- name: Bundle
run: |
gem update --system
gem update bundler
bundle install --jobs 4 --retry 3
- name: Test
run: bundle exec rubocop && bundle exec rspec
name: Release
on:
push:
tags:
- 'release/v*'
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Setup Ruby
uses: actions/setup-ruby@v1
with:
ruby-version: 2.6.x
- name: Bundle
run: |
gem update --system
gem update bundler
bundle install --jobs 4 --retry 3
- name: Publish to GPR
run: |
mkdir -p $HOME/.gem
touch $HOME/.gem/credentials
chmod 0600 $HOME/.gem/credentials
printf -- "---\n:github: Bearer ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
gem build *.gemspec
gem push --KEY github --host https://rubygems.pkg.github.com/${OWNER} *.gem
env:
GEM_HOST_API_KEY: ${{ secrets.GPR_AUTH_TOKEN }}
OWNER: ctran
# This configuration was generated by # This configuration was generated by
# `rubocop --auto-gen-config` # `rubocop --auto-gen-config`
# on 2019-06-16 12:01:03 -0700 using RuboCop version 0.68.1. # on 2019-09-02 16:23:56 -0700 using RuboCop version 0.68.1.
# The point is for the user to remove these configuration records # The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base. # one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new # Note that changes in the inspected code, or installation of new
...@@ -49,9 +49,9 @@ Gemspec/RequiredRubyVersion: ...@@ -49,9 +49,9 @@ Gemspec/RequiredRubyVersion:
# Cop supports --auto-correct. # Cop supports --auto-correct.
Layout/AlignArray: Layout/AlignArray:
Exclude: Exclude:
- 'spec/annotate/annotate_models_spec.rb' - 'spec/lib/annotate/annotate_models_spec.rb'
# Offense count: 104 # Offense count: 107
# Cop supports --auto-correct. # Cop supports --auto-correct.
# Configuration parameters: EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle. # Configuration parameters: EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle.
# SupportedHashRocketStyles: key, separator, table # SupportedHashRocketStyles: key, separator, table
...@@ -60,11 +60,11 @@ Layout/AlignArray: ...@@ -60,11 +60,11 @@ Layout/AlignArray:
Layout/AlignHash: Layout/AlignHash:
Exclude: Exclude:
- 'lib/generators/annotate/templates/auto_annotate_models.rake' - 'lib/generators/annotate/templates/auto_annotate_models.rake'
- 'spec/annotate/annotate_models_spec.rb'
- 'spec/integration/rails_2.3_with_bundler/config/initializers/unified_initializer.rb' - 'spec/integration/rails_2.3_with_bundler/config/initializers/unified_initializer.rb'
- 'spec/integration/rails_4.1.1/lib/tasks/auto_annotate_models.rake' - 'spec/integration/rails_4.1.1/lib/tasks/auto_annotate_models.rake'
- 'spec/integration/rails_4.2.0/lib/tasks/auto_annotate_models.rake' - 'spec/integration/rails_4.2.0/lib/tasks/auto_annotate_models.rake'
- 'spec/integration/standalone/config/init.rb' - 'spec/integration/standalone/config/init.rb'
- 'spec/lib/annotate/annotate_models_spec.rb'
# Offense count: 1 # Offense count: 1
# Cop supports --auto-correct. # Cop supports --auto-correct.
...@@ -78,7 +78,6 @@ Layout/BlockAlignment: ...@@ -78,7 +78,6 @@ Layout/BlockAlignment:
# Cop supports --auto-correct. # Cop supports --auto-correct.
Layout/ClosingHeredocIndentation: Layout/ClosingHeredocIndentation:
Exclude: Exclude:
- 'spec/annotate/annotate_models_spec.rb'
- 'spec/integration/rails_2.3_with_bundler.rb' - 'spec/integration/rails_2.3_with_bundler.rb'
- 'spec/integration/rails_3.2.2.rb' - 'spec/integration/rails_3.2.2.rb'
- 'spec/integration/rails_3.2.8.rb' - 'spec/integration/rails_3.2.8.rb'
...@@ -86,8 +85,9 @@ Layout/ClosingHeredocIndentation: ...@@ -86,8 +85,9 @@ Layout/ClosingHeredocIndentation:
- 'spec/integration/rails_3.2_custom_inflections.rb' - 'spec/integration/rails_3.2_custom_inflections.rb'
- 'spec/integration/rails_3.2_with_asset_pipeline.rb' - 'spec/integration/rails_3.2_with_asset_pipeline.rb'
- 'spec/integration/standalone.rb' - 'spec/integration/standalone.rb'
- 'spec/lib/annotate/annotate_models_spec.rb'
# Offense count: 14 # Offense count: 13
# Cop supports --auto-correct. # Cop supports --auto-correct.
Layout/EmptyLineAfterGuardClause: Layout/EmptyLineAfterGuardClause:
Exclude: Exclude:
...@@ -102,7 +102,6 @@ Layout/EmptyLineAfterGuardClause: ...@@ -102,7 +102,6 @@ Layout/EmptyLineAfterGuardClause:
Layout/EmptyLineAfterMagicComment: Layout/EmptyLineAfterMagicComment:
Exclude: Exclude:
- 'annotate.gemspec' - 'annotate.gemspec'
- 'spec/annotate/annotate_models_spec.rb'
- 'spec/integration/rails_3.2.2/db/schema.rb' - 'spec/integration/rails_3.2.2/db/schema.rb'
- 'spec/integration/rails_3.2.8/db/schema.rb' - 'spec/integration/rails_3.2.8/db/schema.rb'
- 'spec/integration/rails_3.2_autoloading_factory_girl/db/schema.rb' - 'spec/integration/rails_3.2_autoloading_factory_girl/db/schema.rb'
...@@ -111,6 +110,7 @@ Layout/EmptyLineAfterMagicComment: ...@@ -111,6 +110,7 @@ Layout/EmptyLineAfterMagicComment:
- 'spec/integration/rails_4.1.1/db/schema.rb' - 'spec/integration/rails_4.1.1/db/schema.rb'
- 'spec/integration/rails_4.2.0/db/schema.rb' - 'spec/integration/rails_4.2.0/db/schema.rb'
- 'spec/integration/standalone/db/schema.rb' - 'spec/integration/standalone/db/schema.rb'
- 'spec/lib/annotate/annotate_models_spec.rb'
# Offense count: 2 # Offense count: 2
# Cop supports --auto-correct. # Cop supports --auto-correct.
...@@ -129,7 +129,7 @@ Layout/EmptyLinesAroundAccessModifier: ...@@ -129,7 +129,7 @@ Layout/EmptyLinesAroundAccessModifier:
# Cop supports --auto-correct. # Cop supports --auto-correct.
Layout/EmptyLinesAroundArguments: Layout/EmptyLinesAroundArguments:
Exclude: Exclude:
- 'spec/annotate/annotate_routes_spec.rb' - 'spec/lib/annotate/annotate_routes_spec.rb'
# Offense count: 6 # Offense count: 6
# Cop supports --auto-correct. # Cop supports --auto-correct.
...@@ -179,7 +179,6 @@ Layout/IndentFirstHashElement: ...@@ -179,7 +179,6 @@ Layout/IndentFirstHashElement:
# SupportedStyles: auto_detection, squiggly, active_support, powerpack, unindent # SupportedStyles: auto_detection, squiggly, active_support, powerpack, unindent
Layout/IndentHeredoc: Layout/IndentHeredoc:
Exclude: Exclude:
- 'spec/annotate/annotate_models_spec.rb'
- 'spec/integration/integration_spec.rb' - 'spec/integration/integration_spec.rb'
- 'spec/integration/rails_2.3_with_bundler.rb' - 'spec/integration/rails_2.3_with_bundler.rb'
- 'spec/integration/rails_3.2.2.rb' - 'spec/integration/rails_3.2.2.rb'
...@@ -188,6 +187,7 @@ Layout/IndentHeredoc: ...@@ -188,6 +187,7 @@ Layout/IndentHeredoc:
- 'spec/integration/rails_3.2_custom_inflections.rb' - 'spec/integration/rails_3.2_custom_inflections.rb'
- 'spec/integration/rails_3.2_with_asset_pipeline.rb' - 'spec/integration/rails_3.2_with_asset_pipeline.rb'
- 'spec/integration/standalone.rb' - 'spec/integration/standalone.rb'
- 'spec/lib/annotate/annotate_models_spec.rb'
# Offense count: 1 # Offense count: 1
# Cop supports --auto-correct. # Cop supports --auto-correct.
...@@ -214,7 +214,7 @@ Layout/IndentationWidth: ...@@ -214,7 +214,7 @@ Layout/IndentationWidth:
# SupportedStyles: aligned, indented, indented_relative_to_receiver # SupportedStyles: aligned, indented, indented_relative_to_receiver
Layout/MultilineMethodCallIndentation: Layout/MultilineMethodCallIndentation:
Exclude: Exclude:
- 'spec/annotate/annotate_routes_spec.rb' - 'spec/lib/annotate/annotate_routes_spec.rb'
# Offense count: 5 # Offense count: 5
# Cop supports --auto-correct. # Cop supports --auto-correct.
...@@ -339,8 +339,8 @@ Layout/TrailingBlankLines: ...@@ -339,8 +339,8 @@ Layout/TrailingBlankLines:
# Configuration parameters: AllowInHeredoc. # Configuration parameters: AllowInHeredoc.
Layout/TrailingWhitespace: Layout/TrailingWhitespace:
Exclude: Exclude:
- 'spec/annotate/annotate_routes_spec.rb'
- 'spec/integration/rails_2.3_with_bundler/db/schema.rb' - 'spec/integration/rails_2.3_with_bundler/db/schema.rb'
- 'spec/lib/annotate/annotate_routes_spec.rb'
# Offense count: 3 # Offense count: 3
# Configuration parameters: AllowSafeAssignment. # Configuration parameters: AllowSafeAssignment.
...@@ -349,12 +349,6 @@ Lint/AssignmentInCondition: ...@@ -349,12 +349,6 @@ Lint/AssignmentInCondition:
- 'lib/annotate/annotate_models.rb' - 'lib/annotate/annotate_models.rb'
- 'spec/integration/rails_2.3_with_bundler/config/boot.rb' - 'spec/integration/rails_2.3_with_bundler/config/boot.rb'
# Offense count: 2
# Cop supports --auto-correct.
Lint/BigDecimalNew:
Exclude:
- 'spec/annotate/annotate_models_spec.rb'
# Offense count: 6 # Offense count: 6
# Cop supports --auto-correct. # Cop supports --auto-correct.
Lint/DeprecatedClassMethods: Lint/DeprecatedClassMethods:
...@@ -412,18 +406,11 @@ Lint/ShadowingOuterLocalVariable: ...@@ -412,18 +406,11 @@ Lint/ShadowingOuterLocalVariable:
Exclude: Exclude:
- 'Rakefile' - 'Rakefile'
# Offense count: 7 # Offense count: 20
# Cop supports --auto-correct.
# Configuration parameters: IgnoreEmptyBlocks, AllowUnusedKeywordArguments.
Lint/UnusedBlockArgument:
Exclude:
- 'bin/annotate'
# Offense count: 19
Metrics/AbcSize: Metrics/AbcSize:
Max: 138 Max: 138
# Offense count: 27 # Offense count: 28
# Configuration parameters: CountComments, ExcludedMethods. # Configuration parameters: CountComments, ExcludedMethods.
# ExcludedMethods: refine # ExcludedMethods: refine
Metrics/BlockLength: Metrics/BlockLength:
...@@ -438,7 +425,7 @@ Metrics/BlockNesting: ...@@ -438,7 +425,7 @@ Metrics/BlockNesting:
Metrics/CyclomaticComplexity: Metrics/CyclomaticComplexity:
Max: 36 Max: 36
# Offense count: 29 # Offense count: 30
# Configuration parameters: CountComments, ExcludedMethods. # Configuration parameters: CountComments, ExcludedMethods.
Metrics/MethodLength: Metrics/MethodLength:
Max: 75 Max: 75
...@@ -457,8 +444,8 @@ Naming/AccessorMethodName: ...@@ -457,8 +444,8 @@ Naming/AccessorMethodName:
# Blacklist: (?-mix:(^|\s)(EO[A-Z]{1}|END)(\s|$)) # Blacklist: (?-mix:(^|\s)(EO[A-Z]{1}|END)(\s|$))
Naming/HeredocDelimiterNaming: Naming/HeredocDelimiterNaming:
Exclude: Exclude:
- 'spec/annotate/annotate_models_spec.rb' - 'spec/lib/annotate/annotate_models_spec.rb'
- 'spec/annotate/annotate_routes_spec.rb' - 'spec/lib/annotate/annotate_routes_spec.rb'
# Offense count: 2 # Offense count: 2
# Configuration parameters: EnforcedStyleForLeadingUnderscores. # Configuration parameters: EnforcedStyleForLeadingUnderscores.
...@@ -533,14 +520,6 @@ Style/ClassVars: ...@@ -533,14 +520,6 @@ Style/ClassVars:
# Offense count: 1 # Offense count: 1
# Cop supports --auto-correct. # Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SingleLineConditionsOnly, IncludeTernaryExpressions.
# SupportedStyles: assign_to_condition, assign_inside_condition
Style/ConditionalAssignment:
Exclude:
- 'bin/annotate'
# Offense count: 1
# Cop supports --auto-correct.
Style/Dir: Style/Dir:
Exclude: Exclude:
- 'bin/annotate' - 'bin/annotate'
...@@ -562,7 +541,6 @@ Style/Documentation: ...@@ -562,7 +541,6 @@ Style/Documentation:
Style/Encoding: Style/Encoding:
Exclude: Exclude:
- 'annotate.gemspec' - 'annotate.gemspec'
- 'spec/annotate/annotate_models_spec.rb'
- 'spec/integration/rails_3.2.2/db/schema.rb' - 'spec/integration/rails_3.2.2/db/schema.rb'
- 'spec/integration/rails_3.2.8/db/schema.rb' - 'spec/integration/rails_3.2.8/db/schema.rb'
- 'spec/integration/rails_3.2_autoloading_factory_girl/db/schema.rb' - 'spec/integration/rails_3.2_autoloading_factory_girl/db/schema.rb'
...@@ -571,6 +549,7 @@ Style/Encoding: ...@@ -571,6 +549,7 @@ Style/Encoding:
- 'spec/integration/rails_4.1.1/db/schema.rb' - 'spec/integration/rails_4.1.1/db/schema.rb'
- 'spec/integration/rails_4.2.0/db/schema.rb' - 'spec/integration/rails_4.2.0/db/schema.rb'
- 'spec/integration/standalone/db/schema.rb' - 'spec/integration/standalone/db/schema.rb'
- 'spec/lib/annotate/annotate_models_spec.rb'
# Offense count: 48 # Offense count: 48
# Cop supports --auto-correct. # Cop supports --auto-correct.
...@@ -593,7 +572,7 @@ Style/FormatStringToken: ...@@ -593,7 +572,7 @@ Style/FormatStringToken:
Exclude: Exclude:
- 'lib/annotate/annotate_models.rb' - 'lib/annotate/annotate_models.rb'
# Offense count: 184 # Offense count: 186
# Cop supports --auto-correct. # Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle. # Configuration parameters: EnforcedStyle.
# SupportedStyles: when_needed, always, never # SupportedStyles: when_needed, always, never
...@@ -690,17 +669,15 @@ Style/NumericPredicate: ...@@ -690,17 +669,15 @@ Style/NumericPredicate:
- 'lib/annotate.rb' - 'lib/annotate.rb'
- 'lib/annotate/annotate_models.rb' - 'lib/annotate/annotate_models.rb'
# Offense count: 24 # Offense count: 20
# Cop supports --auto-correct. # Cop supports --auto-correct.
# Configuration parameters: PreferredDelimiters. # Configuration parameters: PreferredDelimiters.
Style/PercentLiteralDelimiters: Style/PercentLiteralDelimiters:
Exclude: Exclude:
- 'annotate.gemspec' - 'annotate.gemspec'
- 'bin/annotate'
- 'lib/annotate/annotate_models.rb' - 'lib/annotate/annotate_models.rb'
- 'lib/annotate/annotate_routes.rb' - 'lib/annotate/annotate_routes.rb'
- 'lib/tasks/annotate_models_migrate.rake' - 'lib/tasks/annotate_models_migrate.rake'
- 'spec/annotate/annotate_models_spec.rb'
- 'spec/integration/rails_3.2.2/config/application.rb' - 'spec/integration/rails_3.2.2/config/application.rb'
- 'spec/integration/rails_3.2.8/config/application.rb' - 'spec/integration/rails_3.2.8/config/application.rb'
- 'spec/integration/rails_3.2_autoloading_factory_girl/config/application.rb' - 'spec/integration/rails_3.2_autoloading_factory_girl/config/application.rb'
...@@ -708,8 +685,9 @@ Style/PercentLiteralDelimiters: ...@@ -708,8 +685,9 @@ Style/PercentLiteralDelimiters:
- 'spec/integration/rails_3.2_with_asset_pipeline/config/application.rb' - 'spec/integration/rails_3.2_with_asset_pipeline/config/application.rb'
- 'spec/integration/rails_4.1.1/app/models/task.rb' - 'spec/integration/rails_4.1.1/app/models/task.rb'
- 'spec/integration/rails_4.2.0/app/models/task.rb' - 'spec/integration/rails_4.2.0/app/models/task.rb'
- 'spec/lib/annotate/annotate_models_spec.rb'
- 'spec/lib/tasks/annotate_models_migrate_spec.rb'
- 'spec/spec_helper.rb' - 'spec/spec_helper.rb'
- 'spec/tasks/annotate_models_migrate_spec.rb'
# Offense count: 1 # Offense count: 1
# Cop supports --auto-correct. # Cop supports --auto-correct.
...@@ -730,7 +708,7 @@ Style/RaiseArgs: ...@@ -730,7 +708,7 @@ Style/RaiseArgs:
Style/RedundantBegin: Style/RedundantBegin:
Exclude: Exclude:
- 'lib/annotate/annotate_models.rb' - 'lib/annotate/annotate_models.rb'
- 'spec/annotate/annotate_models_spec.rb' - 'spec/lib/annotate/annotate_models_spec.rb'
# Offense count: 1 # Offense count: 1
# Cop supports --auto-correct. # Cop supports --auto-correct.
...@@ -784,12 +762,11 @@ Style/SafeNavigation: ...@@ -784,12 +762,11 @@ Style/SafeNavigation:
Exclude: Exclude:
- 'lib/annotate/annotate_models.rb' - 'lib/annotate/annotate_models.rb'
# Offense count: 2 # Offense count: 1
# Cop supports --auto-correct. # Cop supports --auto-correct.
# Configuration parameters: AllowAsExpressionSeparator. # Configuration parameters: AllowAsExpressionSeparator.
Style/Semicolon: Style/Semicolon:
Exclude: Exclude:
- 'bin/annotate'
- 'spec/integration/rails_2.3_with_bundler/config/initializers/unified_initializer.rb' - 'spec/integration/rails_2.3_with_bundler/config/initializers/unified_initializer.rb'
# Offense count: 18 # Offense count: 18
...@@ -801,7 +778,7 @@ Style/StderrPuts: ...@@ -801,7 +778,7 @@ Style/StderrPuts:
- 'lib/annotate/annotate_models.rb' - 'lib/annotate/annotate_models.rb'
- 'spec/integration/rails_2.3_with_bundler/config/boot.rb' - 'spec/integration/rails_2.3_with_bundler/config/boot.rb'
# Offense count: 243 # Offense count: 247
# Cop supports --auto-correct. # Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline. # Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline.
# SupportedStyles: single_quotes, double_quotes # SupportedStyles: single_quotes, double_quotes
...@@ -827,7 +804,7 @@ Style/SymbolArray: ...@@ -827,7 +804,7 @@ Style/SymbolArray:
# Cop supports --auto-correct. # Cop supports --auto-correct.
Style/SymbolLiteral: Style/SymbolLiteral:
Exclude: Exclude:
- 'spec/annotate/annotate_models_spec.rb' - 'spec/lib/annotate/annotate_models_spec.rb'
# Offense count: 1 # Offense count: 1
# Cop supports --auto-correct. # Cop supports --auto-correct.
...@@ -835,7 +812,7 @@ Style/SymbolLiteral: ...@@ -835,7 +812,7 @@ Style/SymbolLiteral:
# SupportedStylesForMultiline: comma, consistent_comma, no_comma # SupportedStylesForMultiline: comma, consistent_comma, no_comma
Style/TrailingCommaInArrayLiteral: Style/TrailingCommaInArrayLiteral:
Exclude: Exclude:
- 'spec/annotate/annotate_models_spec.rb' - 'spec/lib/annotate/annotate_models_spec.rb'
# Offense count: 2 # Offense count: 2
# Cop supports --auto-correct. # Cop supports --auto-correct.
...@@ -846,12 +823,6 @@ Style/TrailingCommaInHashLiteral: ...@@ -846,12 +823,6 @@ Style/TrailingCommaInHashLiteral:
- 'spec/integration/rails_4.1.1/lib/tasks/auto_annotate_models.rake' - 'spec/integration/rails_4.1.1/lib/tasks/auto_annotate_models.rake'
- 'spec/integration/rails_4.2.0/lib/tasks/auto_annotate_models.rake' - 'spec/integration/rails_4.2.0/lib/tasks/auto_annotate_models.rake'
# Offense count: 2
# Cop supports --auto-correct.
Style/UnneededInterpolation:
Exclude:
- 'bin/annotate'
# Offense count: 4 # Offense count: 4
# Cop supports --auto-correct. # Cop supports --auto-correct.
Style/UnneededPercentQ: Style/UnneededPercentQ:
...@@ -859,7 +830,7 @@ Style/UnneededPercentQ: ...@@ -859,7 +830,7 @@ Style/UnneededPercentQ:
- 'annotate.gemspec' - 'annotate.gemspec'
- 'spec/integration/rails_2.3_with_bundler/config/boot.rb' - 'spec/integration/rails_2.3_with_bundler/config/boot.rb'
# Offense count: 431 # Offense count: 465
# Cop supports --auto-correct. # Cop supports --auto-correct.
# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. # Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https # URISchemes: http, https
......
...@@ -3,12 +3,9 @@ language: ruby ...@@ -3,12 +3,9 @@ language: ruby
rvm: rvm:
- 2.2.10 - 2.2.10
- 2.3.8 - 2.3.8
- 2.4.6 - 2.4.7
- 2.5.5 - 2.5.6
- 2.6.0 - 2.6.4
- 2.6.1
- 2.6.2
- 2.6.3
- ruby-head - ruby-head
matrix: matrix:
......
== 3.0.3
* Use a less error-prone way of specifying gem files (#662)
* Update rake requirement from >= 10.4, < 13.0 to >= 10.4, < 14.0 (#659)
* Bump nokogiri from 1.6.6.2 to 1.10.4 in /spec/integration/rails_4.2.0 (#655)
* Defaults annotate models to true (#671)
* Bump loofah from 2.3.0 to 2.3.1 in /spec/integration/rails_4.2.0 (#681)
== 3.0.2
* Fixes `LoadError` due to gemspec not referencing `parser.rb`, issue #657 (#660)
* Changes `--additional_file_patterns` to use dashes `--additional-file-patterns` for consistency (#649)
* Refactor: moving constants into `constants.rb` (#653)
== 3.0.1
* Skipped as an official release, used the 3.0.1 patch for setting up Github Actions (#619)
== 3.0.0
* Added `--models` CLI option fixing issue #563 (#647)
* Added `--additional_file_patterns` option for additional file patterns (#633) (#636) (#637)
* Refactored CLI parser (#646)
* Fixed BigDecimal.new deprecation warning (#634)
* Fixed annotations for columns with long data types (#622)
* Made methods private in AnnotateRoutes (#598)
See https://github.com/ctran/annotate_models/releases/tag/v3.0.0
== 2.7.5 == 2.7.5
See https://github.com/ctran/annotate_models/releases/tag/v2.7.5 See https://github.com/ctran/annotate_models/releases/tag/v2.7.5
......
...@@ -3,10 +3,10 @@ ...@@ -3,10 +3,10 @@
{<img src="https://badge.fury.io/rb/annotate.svg" alt="Gem Version" />}[http://badge.fury.io/rb/annotate] {<img src="https://badge.fury.io/rb/annotate.svg" alt="Gem Version" />}[http://badge.fury.io/rb/annotate]
{<img src="https://img.shields.io/gem/dt/annotate.svg?style=flat" />}[https://rubygems.org/gems/annotate] {<img src="https://img.shields.io/gem/dt/annotate.svg?style=flat" />}[https://rubygems.org/gems/annotate]
{<img src="https://travis-ci.org/ctran/annotate_models.svg?branch=develop" />}[https://travis-ci.org/ctran/annotate_models] {<img src="https://travis-ci.org/ctran/annotate_models.svg?branch=develop" />}[https://travis-ci.org/ctran/annotate_models]
{<img src="https://github.com/ctran/annotate_models/workflows/CI/badge.svg" />}[https://github.com/ctran/annotate_models/actions?workflow=CI]
{<img src="https://coveralls.io/repos/ctran/annotate_models/badge.svg?branch=develop" />}[https://coveralls.io/r/ctran/annotate_models?branch=develop] {<img src="https://coveralls.io/repos/ctran/annotate_models/badge.svg?branch=develop" />}[https://coveralls.io/r/ctran/annotate_models?branch=develop]
{<img src="https://codeclimate.com/github/ctran/annotate_models/badges/gpa.svg" />}[https://codeclimate.com/github/ctran/annotate_models] {<img src="https://codeclimate.com/github/ctran/annotate_models/badges/gpa.svg" />}[https://codeclimate.com/github/ctran/annotate_models]
{<img src="http://inch-ci.org/github/ctran/annotate_models.svg?branch=develop" alt="Inline docs" />}[http://inch-ci.org/github/ctran/annotate_models] {<img src="http://inch-ci.org/github/ctran/annotate_models.svg?branch=develop" alt="Inline docs" />}[http://inch-ci.org/github/ctran/annotate_models]
{<img src="https://gemnasium.com/ctran/annotate_models.png" />}[https://gemnasium.com/ctran/annotate_models]
Add a comment summarizing the current schema to the top or bottom of each of Add a comment summarizing the current schema to the top or bottom of each of
your... your...
...@@ -90,11 +90,11 @@ To annotate all your models, tests, fixtures, and factories: ...@@ -90,11 +90,11 @@ To annotate all your models, tests, fixtures, and factories:
To annotate just your models, tests, and factories: To annotate just your models, tests, and factories:
annotate --exclude fixtures annotate --models --exclude fixtures
To annotate just your models: To annotate just your models:
annotate --exclude tests,fixtures,factories,serializers annotate --models
To annotate routes.rb: To annotate routes.rb:
...@@ -164,6 +164,7 @@ you can do so with a simple environment variable, instead of editing the ...@@ -164,6 +164,7 @@ you can do so with a simple environment variable, instead of editing the
== Options == Options
Usage: annotate [options] [model_file]* Usage: annotate [options] [model_file]*
--additional_file_patterns Additional file paths or globs to annotate, separated by commas (e.g. `/foo/bar/%model_name%/*.rb,/baz/%model_name%.rb`)
-d, --delete Remove annotations from all model files or the routes.rb file -d, --delete Remove annotations from all model files or the routes.rb file
-p [before|top|after|bottom], Place the annotations at the top (before) or the bottom (after) of the model/test/fixture/factory/route/serializer file(s) -p [before|top|after|bottom], Place the annotations at the top (before) or the bottom (after) of the model/test/fixture/factory/route/serializer file(s)
--position --position
...@@ -184,6 +185,7 @@ you can do so with a simple environment variable, instead of editing the ...@@ -184,6 +185,7 @@ you can do so with a simple environment variable, instead of editing the
--wo, --wrapper-open STR Annotation wrapper opening. --wo, --wrapper-open STR Annotation wrapper opening.
--wc, --wrapper-close STR Annotation wrapper closing --wc, --wrapper-close STR Annotation wrapper closing
-r, --routes Annotate routes.rb with the output of 'rake routes' -r, --routes Annotate routes.rb with the output of 'rake routes'
--models Annotate ActiveRecord models
-a, --active-admin Annotate active_admin models -a, --active-admin Annotate active_admin models
-v, --version Show the current version of this gem -v, --version Show the current version of this gem
-m, --show-migration Include the migration version number in the annotation -m, --show-migration Include the migration version number in the annotation
...@@ -206,16 +208,35 @@ you can do so with a simple environment variable, instead of editing the ...@@ -206,16 +208,35 @@ you can do so with a simple environment variable, instead of editing the
--frozen Do not allow to change annotations. Exits non-zero if there are going to be changes to files. --frozen Do not allow to change annotations. Exits non-zero if there are going to be changes to files.
--timestamp Include timestamp in (routes) annotation --timestamp Include timestamp in (routes) annotation
--trace If unable to annotate a file, print the full stack trace, not just the exception message. --trace If unable to annotate a file, print the full stack trace, not just the exception message.
-I, --ignore-columns REGEX don't annotate columns that match a given REGEX (i.e., `annotate -I '^(id|updated_at|created_at)'` -I, --ignore-columns REGEX don't annotate columns that match a given REGEX (e.g. `annotate -I '^(id|updated_at|created_at)'`)
--ignore-routes REGEX don't annotate routes that match a given REGEX (i.e., `annotate -I '(mobile|resque|pghero)'` --ignore-routes REGEX don't annotate routes that match a given REGEX (e.g. `annotate -I '(mobile|resque|pghero)'`)_
--hide-limit-column-types VALUES --hide-limit-column-types VALUES
don't show limit for given column types, separated by commas (i.e., `integer,boolean,text`) don't show limit for given column types, separated by commas (e.g. `integer,boolean,text`)
--hide-default-column-types VALUES --hide-default-column-types VALUES
don't show default for given column types, separated by commas (i.e., `json,jsonb,hstore`) don't show default for given column types, separated by commas (e.g. `json,jsonb,hstore`)
--ignore-unknown-models don't display warnings for bad model files --ignore-unknown-models don't display warnings for bad model files
--with-comment include database comments in model annotations --with-comment include database comments in model annotations
=== Option: +additional_file_patterns+
CLI: +--additional_file_patterns+<br>
Ruby: +:additional_file_patterns+
Provide additional paths for the gem to annotate. These paths can include globs.
It is recommended to use absolute paths. Here are some examples:
- <code>/app/lib/decorates/%MODEL_NAME%/&ast;.rb</code>
- <code>/app/lib/forms/%PLURALIZED_MODEL_NAME%/&ast;&ast;/&ast;.rb</code>
- <code>/app/lib/forms/%TABLE_NAME%/&ast;.rb</code>
The appropriate model will be inferred using the <code>%*%</code> syntax, annotating any matching files.
It works with existing filename resolutions (options for which can be found in the +resolve_filename+ method of
+annotate_models.rb+).
When using in a Rails config, you can use the following:
<code>File.join(Rails.application.root, 'app/lib/forms/%PLURALIZED_MODEL_NAME%/**/*.rb')</code>
== Sorting == Sorting
......
...@@ -14,35 +14,16 @@ Gem::Specification.new do |s| ...@@ -14,35 +14,16 @@ Gem::Specification.new do |s|
s.email = ['alex@stinky.com', 'cuong.tran@gmail.com', 'x@nofxx.com', 'turadg@aleahmad.net', 'jon@cloudability.com'] s.email = ['alex@stinky.com', 'cuong.tran@gmail.com', 'x@nofxx.com', 'turadg@aleahmad.net', 'jon@cloudability.com']
s.executables = ['annotate'] s.executables = ['annotate']
s.extra_rdoc_files = ['README.rdoc', 'CHANGELOG.rdoc', 'TODO.rdoc'] s.extra_rdoc_files = ['README.rdoc', 'CHANGELOG.rdoc', 'TODO.rdoc']
s.files = [ s.files = `git ls-files -z LICENSE.txt *.rdoc *.gemspec bin lib`.split("\x0")
'AUTHORS.rdoc',
'CHANGELOG.rdoc',
'LICENSE.txt',
'README.rdoc',
'TODO.rdoc',
'annotate.gemspec',
'bin/annotate',
'lib/annotate.rb',
'lib/annotate/active_record_patch.rb',
'lib/annotate/annotate_models.rb',
'lib/annotate/annotate_routes.rb',
'lib/annotate/tasks.rb',
'lib/annotate/version.rb',
'lib/generators/annotate/USAGE',
'lib/generators/annotate/install_generator.rb',
'lib/generators/annotate/templates/auto_annotate_models.rake',
'lib/tasks/annotate_models.rake',
'lib/tasks/annotate_routes.rake',
'lib/tasks/annotate_models_migrate.rake'
]
s.homepage = 'http://github.com/ctran/annotate_models' s.homepage = 'http://github.com/ctran/annotate_models'
s.licenses = ['Ruby'] s.licenses = ['Ruby']
s.require_paths = ['lib'] s.require_paths = ['lib']
s.rubyforge_project = 'annotate'
s.rubygems_version = '2.1.11' s.rubygems_version = '2.1.11'
s.summary = 'Annotates Rails Models, routes, fixtures, and others based on the database schema.' s.summary = 'Annotates Rails Models, routes, fixtures, and others based on the database schema.'
s.specification_version = 4 if s.respond_to? :specification_version s.specification_version = 4 if s.respond_to? :specification_version
s.add_runtime_dependency(%q<rake>, ['>= 10.4', '< 13.0']) s.add_runtime_dependency(%q<rake>, '>= 10.4', '< 14.0')
s.add_runtime_dependency(%q<activerecord>, ['>= 3.2', '< 7.0']) s.add_runtime_dependency(%q<activerecord>, ['>= 3.2', '< 7.0'])
s.metadata = { "github_repo" => "ssh://github.com/ctran/annotate_models" }
end end
...@@ -14,203 +14,19 @@ end ...@@ -14,203 +14,19 @@ end
here = File.expand_path(File.dirname __FILE__) here = File.expand_path(File.dirname __FILE__)
$LOAD_PATH << "#{here}/../lib" $LOAD_PATH << "#{here}/../lib"
require 'optparse'
require 'annotate' require 'annotate'
Annotate.bootstrap_rake require 'annotate/parser'
has_set_position = {}
target_action = :do_annotations
positions = %w(before top after bottom)
OptionParser.new do |opts|
opts.banner = 'Usage: annotate [options] [model_file]*'
opts.on('-d', '--delete', 'Remove annotations from all model files or the routes.rb file') do
target_action = :remove_annotations
end
opts.on('-p', '--position [before|top|after|bottom]', positions,
'Place the annotations at the top (before) or the bottom (after) of the model/test/fixture/factory/route/serializer file(s)') do |p|
ENV['position'] = p
%w(position_in_class position_in_factory position_in_fixture position_in_test position_in_routes position_in_serializer).each do |key|
ENV[key] = p unless has_set_position[key]
end
end
opts.on('--pc', '--position-in-class [before|top|after|bottom]', positions,
'Place the annotations at the top (before) or the bottom (after) of the model file') do |p|
ENV['position_in_class'] = p
has_set_position['position_in_class'] = true
end
opts.on('--pf', '--position-in-factory [before|top|after|bottom]', positions,
'Place the annotations at the top (before) or the bottom (after) of any factory files') do |p|
ENV['position_in_factory'] = p
has_set_position['position_in_factory'] = true
end
opts.on('--px', '--position-in-fixture [before|top|after|bottom]', positions,
'Place the annotations at the top (before) or the bottom (after) of any fixture files') do |p|
ENV['position_in_fixture'] = p
has_set_position['position_in_fixture'] = true
end
opts.on('--pt', '--position-in-test [before|top|after|bottom]', positions,
'Place the annotations at the top (before) or the bottom (after) of any test files') do |p|
ENV['position_in_test'] = p
has_set_position['position_in_test'] = true
end
opts.on('--pr', '--position-in-routes [before|top|after|bottom]', positions,
'Place the annotations at the top (before) or the bottom (after) of the routes.rb file') do |p|
ENV['position_in_routes'] = p
has_set_position['position_in_routes'] = true
end
opts.on('--ps', '--position-in-serializer [before|top|after|bottom]', positions,
'Place the annotations at the top (before) or the bottom (after) of the serializer files') do |p|
ENV['position_in_serializer'] = p
has_set_position['position_in_serializer'] = true
end
opts.on('--w', '--wrapper STR', 'Wrap annotation with the text passed as parameter.',
'If --w option is used, the same text will be used as opening and closing') do |p|
ENV['wrapper'] = p
end
opts.on('--wo', '--wrapper-open STR', 'Annotation wrapper opening.') do |p|
ENV['wrapper_open'] = p
end
opts.on('--wc', '--wrapper-close STR', 'Annotation wrapper closing') do |p|
ENV['wrapper_close'] = p
end
opts.on('-r', '--routes', "Annotate routes.rb with the output of 'rake routes'") do
ENV['routes'] = 'true'
end
opts.on('-a', '--active-admin', 'Annotate active_admin models') do
ENV['active_admin'] = 'true'
end
opts.on('-v', '--version', 'Show the current version of this gem') do
puts "annotate v#{Annotate.version}"; exit
end
opts.on('-m', '--show-migration', 'Include the migration version number in the annotation') do
ENV['include_version'] = 'yes'
end
opts.on('-k', '--show-foreign-keys',
"List the table's foreign key constraints in the annotation") do
ENV['show_foreign_keys'] = 'yes'
end
opts.on('--ck', Annotate.bootstrap_rake
'--complete-foreign-keys', 'Complete foreign key names in the annotation') do
ENV['show_foreign_keys'] = 'yes'
ENV['show_complete_foreign_keys'] = 'yes'
end
opts.on('-i', '--show-indexes',
"List the table's database indexes in the annotation") do
ENV['show_indexes'] = 'yes'
end
opts.on('-s', '--simple-indexes',
"Concat the column's related indexes in the annotation") do
ENV['simple_indexes'] = 'yes'
end
opts.on('--model-dir dir',
"Annotate model files stored in dir rather than app/models, separate multiple dirs with commas") do |dir|
ENV['model_dir'] = dir
end
opts.on('--root-dir dir',
"Annotate files stored within root dir projects, separate multiple dirs with commas") do |dir|
ENV['root_dir'] = dir
end
opts.on('--ignore-model-subdirects',
"Ignore subdirectories of the models directory") do |dir|
ENV['ignore_model_sub_dir'] = 'yes'
end
opts.on('--sort',
"Sort columns alphabetically, rather than in creation order") do |dir|
ENV['sort'] = 'yes'
end
opts.on('--classified-sort',
"Sort columns alphabetically, but first goes id, then the rest columns, then the timestamp columns and then the association columns") do |dir|
ENV['classified_sort'] = 'yes'
end
opts.on('-R', '--require path',
"Additional file to require before loading models, may be used multiple times") do |path|
if !ENV['require'].blank?
ENV['require'] = ENV['require'] + ",#{path}"
else
ENV['require'] = path
end
end
opts.on('-e', '--exclude [tests,fixtures,factories,serializers]', Array, "Do not annotate fixtures, test files, factories, and/or serializers") do |exclusions|
exclusions ||= %w(tests fixtures factories)
exclusions.each { |exclusion| ENV["exclude_#{exclusion}"] = 'yes' }
end
opts.on('-f', '--format [bare|rdoc|markdown]', %w(bare rdoc markdown), 'Render Schema Infomation as plain/RDoc/Markdown') do |fmt|
ENV["format_#{fmt}"] = 'yes'
end
opts.on('--force', 'Force new annotations even if there are no changes.') do |force|
ENV['force'] = 'yes'
end
opts.on('--frozen', 'Do not allow to change annotations. Exits non-zero if there are going to be changes to files.') do
ENV['frozen'] = 'yes'
end
opts.on('--timestamp', 'Include timestamp in (routes) annotation') do
ENV['timestamp'] = 'true'
end
opts.on('--trace', 'If unable to annotate a file, print the full stack trace, not just the exception message.') do |value|
ENV['trace'] = 'yes'
end
opts.on('-I', '--ignore-columns REGEX', "don't annotate columns that match a given REGEX (i.e., `annotate -I '^(id|updated_at|created_at)'`") do |regex|
ENV['ignore_columns'] = regex
end
opts.on('--ignore-routes REGEX', "don't annotate routes that match a given REGEX (i.e., `annotate -I '(mobile|resque|pghero)'`") do |regex|
ENV['ignore_routes'] = regex
end
opts.on('--hide-limit-column-types VALUES', "don't show limit for given column types, separated by commas (i.e., `integer,boolean,text`)") do |values|
ENV['hide_limit_column_types'] = "#{values}"
end
opts.on('--hide-default-column-types VALUES', "don't show default for given column types, separated by commas (i.e., `json,jsonb,hstore`)") do |values|
ENV['hide_default_column_types'] = "#{values}"
end
opts.on('--ignore-unknown-models', "don't display warnings for bad model files") do |values| options_result = Annotate::Parser.parse(ARGV)
ENV['ignore_unknown_models'] = 'true'
end
opts.on('--with-comment', "include database comments in model annotations") do |values| exit if options_result[:exit]
ENV['with_comment'] = 'true'
end
end.parse!
options = Annotate.setup_options( options = Annotate.setup_options(
is_rake: ENV['is_rake'] && !ENV['is_rake'].empty? is_rake: ENV['is_rake'] && !ENV['is_rake'].empty?
) )
Annotate.eager_load(options) if Annotate.include_models? Annotate.eager_load(options) if Annotate.include_models?
AnnotateModels.send(target_action, options) if Annotate.include_models? AnnotateModels.send(options_result[:target_action], options) if Annotate.include_models?
AnnotateRoutes.send(target_action, options) if Annotate.include_routes? AnnotateRoutes.send(options_result[:target_action], options) if Annotate.include_routes?
machine:
ruby:
version: 2.2.6
test:
override:
- bundle exec rubocop && bundle exec rspec
...@@ -4,6 +4,7 @@ $LOAD_PATH.unshift(File.dirname(__FILE__)) ...@@ -4,6 +4,7 @@ $LOAD_PATH.unshift(File.dirname(__FILE__))
require 'annotate/version' require 'annotate/version'
require 'annotate/annotate_models' require 'annotate/annotate_models'
require 'annotate/annotate_routes' require 'annotate/annotate_routes'
require 'annotate/constants'
begin begin
# ActiveSupport 3.x... # ActiveSupport 3.x...
...@@ -16,8 +17,6 @@ rescue StandardError ...@@ -16,8 +17,6 @@ rescue StandardError
end end
module Annotate module Annotate
TRUE_RE = /^(true|t|yes|y|1)$/i
## ##
# The set of available options to customize the behavior of Annotate. # The set of available options to customize the behavior of Annotate.
# #
...@@ -36,8 +35,8 @@ module Annotate ...@@ -36,8 +35,8 @@ module Annotate
:exclude_sti_subclasses, :ignore_unknown_models, :with_comment :exclude_sti_subclasses, :ignore_unknown_models, :with_comment
].freeze ].freeze
OTHER_OPTIONS = [ OTHER_OPTIONS = [
:ignore_columns, :skip_on_db_migrate, :wrapper_open, :wrapper_close, :additional_file_patterns, :ignore_columns, :skip_on_db_migrate, :wrapper_open, :wrapper_close,
:wrapper, :routes, :hide_limit_column_types, :hide_default_column_types, :wrapper, :routes, :models, :hide_limit_column_types, :hide_default_column_types,
:ignore_routes, :active_admin :ignore_routes, :active_admin
].freeze ].freeze
PATH_OPTIONS = [ PATH_OPTIONS = [
...@@ -88,6 +87,7 @@ module Annotate ...@@ -88,6 +87,7 @@ module Annotate
options[key] = !ENV[key.to_s].blank? ? ENV[key.to_s].split(',') : [] options[key] = !ENV[key.to_s].blank? ? ENV[key.to_s].split(',') : []
end end
options[:additional_file_patterns] ||= []
options[:model_dir] = ['app/models'] if options[:model_dir].empty? options[:model_dir] = ['app/models'] if options[:model_dir].empty?
options[:wrapper_open] ||= options[:wrapper] options[:wrapper_open] ||= options[:wrapper]
...@@ -106,15 +106,15 @@ module Annotate ...@@ -106,15 +106,15 @@ module Annotate
end end
def self.skip_on_migration? def self.skip_on_migration?
ENV['ANNOTATE_SKIP_ON_DB_MIGRATE'] =~ TRUE_RE || ENV['skip_on_db_migrate'] =~ TRUE_RE ENV['ANNOTATE_SKIP_ON_DB_MIGRATE'] =~ Constants::TRUE_RE || ENV['skip_on_db_migrate'] =~ Constants::TRUE_RE
end end
def self.include_routes? def self.include_routes?
ENV['routes'] =~ TRUE_RE ENV['routes'] =~ Constants::TRUE_RE
end end
def self.include_models? def self.include_models?
ENV['routes'] !~ TRUE_RE ENV['models'] =~ Constants::TRUE_RE
end end
def self.loaded_tasks=(val) def self.loaded_tasks=(val)
...@@ -198,7 +198,7 @@ module Annotate ...@@ -198,7 +198,7 @@ module Annotate
def self.true?(val) def self.true?(val)
return false if val.blank? return false if val.blank?
return false unless val =~ TRUE_RE return false unless val =~ Constants::TRUE_RE
true true
end end
end end
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
require 'bigdecimal' require 'bigdecimal'
module AnnotateModels require 'annotate/constants'
TRUE_RE = /^(true|t|yes|y|1)$/i
module AnnotateModels
# Annotate Models plugin use this header # Annotate Models plugin use this header
COMPAT_PREFIX = '== Schema Info'.freeze COMPAT_PREFIX = '== Schema Info'.freeze
COMPAT_PREFIX_MD = '## Schema Info'.freeze COMPAT_PREFIX_MD = '## Schema Info'.freeze
...@@ -159,13 +159,15 @@ module AnnotateModels ...@@ -159,13 +159,15 @@ module AnnotateModels
] ]
end end
def files_by_pattern(root_directory, pattern_type) def files_by_pattern(root_directory, pattern_type, options)
case pattern_type case pattern_type
when 'test' then test_files(root_directory) when 'test' then test_files(root_directory)
when 'fixture' then fixture_files(root_directory) when 'fixture' then fixture_files(root_directory)
when 'scaffold' then scaffold_files(root_directory) when 'scaffold' then scaffold_files(root_directory)
when 'factory' then factory_files(root_directory) when 'factory' then factory_files(root_directory)
when 'serializer' then serialize_files(root_directory) when 'serializer' then serialize_files(root_directory)
when 'additional_file_patterns'
[options[:additional_file_patterns] || []].flatten
when 'controller' when 'controller'
[File.join(root_directory, CONTROLLER_DIR, "%PLURALIZED_MODEL_NAME%_controller.rb")] [File.join(root_directory, CONTROLLER_DIR, "%PLURALIZED_MODEL_NAME%_controller.rb")]
when 'admin' when 'admin'
...@@ -177,14 +179,20 @@ module AnnotateModels ...@@ -177,14 +179,20 @@ module AnnotateModels
end end
end end
def get_patterns(pattern_types = []) def get_patterns(options, pattern_types = [])
current_patterns = [] current_patterns = []
root_dir.each do |root_directory| root_dir.each do |root_directory|
Array(pattern_types).each do |pattern_type| Array(pattern_types).each do |pattern_type|
current_patterns += files_by_pattern(root_directory, pattern_type) patterns = files_by_pattern(root_directory, pattern_type, options)
current_patterns += if pattern_type.to_sym == :additional_file_patterns
patterns
else
patterns.map { |p| p.sub(/^[\/]*/, '') }
end end
end end
current_patterns.map { |p| p.sub(/^[\/]*/, '') } end
current_patterns
end end
# Simple quoting for the default column value # Simple quoting for the default column value
...@@ -581,8 +589,9 @@ module AnnotateModels ...@@ -581,8 +589,9 @@ module AnnotateModels
end end
def matched_types(options) def matched_types(options)
types = MATCHED_TYPES types = MATCHED_TYPES.dup
types << 'admin' if options[:active_admin] =~ TRUE_RE && !types.include?('admin') types << 'admin' if options[:active_admin] =~ Annotate::Constants::TRUE_RE && !types.include?('admin')
types << 'additional_file_patterns' if options[:additional_file_patterns].present?
types types
end end
...@@ -634,8 +643,11 @@ module AnnotateModels ...@@ -634,8 +643,11 @@ module AnnotateModels
end end
next if options[exclusion_key] next if options[exclusion_key]
get_patterns(key)
get_patterns(options, key)
.map { |f| resolve_filename(f, model_name, table_name) } .map { |f| resolve_filename(f, model_name, table_name) }
.map { |f| expand_glob_into_files(f) }
.flatten
.each do |f| .each do |f|
if annotate_one_file(f, info, position_key, options_with_position(options, position_key)) if annotate_one_file(f, info, position_key, options_with_position(options, position_key))
annotated << f annotated << f
...@@ -793,6 +805,10 @@ module AnnotateModels ...@@ -793,6 +805,10 @@ module AnnotateModels
end end
end end
def expand_glob_into_files(glob)
Dir.glob(glob)
end
def annotate_model_file(annotated, file, header, options) def annotate_model_file(annotated, file, header, options)
begin begin
return false if /#{SKIP_ANNOTATION_PREFIX}.*/ =~ (File.exist?(file) ? File.read(file) : '') return false if /#{SKIP_ANNOTATION_PREFIX}.*/ =~ (File.exist?(file) ? File.read(file) : '')
...@@ -830,7 +846,7 @@ module AnnotateModels ...@@ -830,7 +846,7 @@ module AnnotateModels
model_file_name = file model_file_name = file
deannotated_klass = true if remove_annotation_of_file(model_file_name, options) deannotated_klass = true if remove_annotation_of_file(model_file_name, options)
get_patterns(matched_types(options)) get_patterns(options, matched_types(options))
.map { |f| resolve_filename(f, model_name, table_name) } .map { |f| resolve_filename(f, model_name, table_name) }
.each do |f| .each do |f|
if File.exist?(f) if File.exist?(f)
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
# Yes, it's simple but I'm thick and often need a reminder of what my routes # Yes, it's simple but I'm thick and often need a reminder of what my routes
# mean. # mean.
# #
# Running this task will replace any exising route comment generated by the # Running this task will replace any existing route comment generated by the
# task. Best to back up your routes file before running: # task. Best to back up your routes file before running:
# #
# Author: # Author:
......
module Annotate
module Constants
TRUE_RE = /^(true|t|yes|y|1)$/i.freeze
end
end
require 'optparse'
module Annotate
# Class for handling command line arguments
class Parser # rubocop:disable Metrics/ClassLength
def self.parse(args, env = {})
new(args, env).parse
end
attr_reader :args, :options, :env
ANNOTATION_POSITIONS = %w[before top after bottom].freeze
FILE_TYPE_POSITIONS = %w[position_in_class position_in_factory position_in_fixture position_in_test position_in_routes position_in_serializer].freeze
EXCLUSION_LIST = %w[tests fixtures factories serializers].freeze
FORMAT_TYPES = %w[bare rdoc markdown].freeze
def initialize(args, env)
@args = args
@options = default_options
@env = env
end
def parse
# To split up because right now this method parses and commits
parser.parse!(args)
commit
options
end
private
def commit
env.each_pair do |key, value|
ENV[key] = value
end
end
def parser
OptionParser.new do |option_parser|
add_options_to_parser(option_parser)
end
end
def add_options_to_parser(option_parser) # rubocop:disable Metrics/MethodLength
has_set_position = {}
positions = ANNOTATION_POSITIONS
option_parser.banner = 'Usage: annotate [options] [model_file]*'
option_parser.on('--additional-file-patterns path1,path2,path3', Array, "Additional file paths or globs to annotate, separated by commas (e.g. `/foo/bar/%model_name%/*.rb,/baz/%model_name%.rb`)") do |additional_file_patterns|
ENV['additional_file_patterns'] = additional_file_patterns
end
option_parser.on('-d', '--delete', 'Remove annotations from all model files or the routes.rb file') do
@options[:target_action] = :remove_annotations
end
option_parser.on('-p', '--position [before|top|after|bottom]', positions,
'Place the annotations at the top (before) or the bottom (after) of the model/test/fixture/factory/route/serializer file(s)') do |p|
env['position'] = p
FILE_TYPE_POSITIONS.each do |key|
env[key] = p unless has_set_position[key]
end
end
option_parser.on('--pc', '--position-in-class [before|top|after|bottom]', positions,
'Place the annotations at the top (before) or the bottom (after) of the model file') do |p|
env['position_in_class'] = p
has_set_position['position_in_class'] = true
end
option_parser.on('--pf', '--position-in-factory [before|top|after|bottom]', positions,
'Place the annotations at the top (before) or the bottom (after) of any factory files') do |p|
env['position_in_factory'] = p
has_set_position['position_in_factory'] = true
end
option_parser.on('--px', '--position-in-fixture [before|top|after|bottom]', positions,
'Place the annotations at the top (before) or the bottom (after) of any fixture files') do |p|
env['position_in_fixture'] = p
has_set_position['position_in_fixture'] = true
end
option_parser.on('--pt', '--position-in-test [before|top|after|bottom]', positions,
'Place the annotations at the top (before) or the bottom (after) of any test files') do |p|
env['position_in_test'] = p
has_set_position['position_in_test'] = true
end
option_parser.on('--pr', '--position-in-routes [before|top|after|bottom]', positions,
'Place the annotations at the top (before) or the bottom (after) of the routes.rb file') do |p|
env['position_in_routes'] = p
has_set_position['position_in_routes'] = true
end
option_parser.on('--ps', '--position-in-serializer [before|top|after|bottom]', positions,
'Place the annotations at the top (before) or the bottom (after) of the serializer files') do |p|
env['position_in_serializer'] = p
has_set_position['position_in_serializer'] = true
end
option_parser.on('--w', '--wrapper STR', 'Wrap annotation with the text passed as parameter.',
'If --w option is used, the same text will be used as opening and closing') do |p|
env['wrapper'] = p
end
option_parser.on('--wo', '--wrapper-open STR', 'Annotation wrapper opening.') do |p|
env['wrapper_open'] = p
end
option_parser.on('--wc', '--wrapper-close STR', 'Annotation wrapper closing') do |p|
env['wrapper_close'] = p
end
option_parser.on('-r', '--routes', "Annotate routes.rb with the output of 'rake routes'") do
env['routes'] = 'true'
end
option_parser.on('--models', "Annotate ActiveRecord models") do
env['models'] = 'true'
end
option_parser.on('-a', '--active-admin', 'Annotate active_admin models') do
env['active_admin'] = 'true'
end
option_parser.on('-v', '--version', 'Show the current version of this gem') do
puts "annotate v#{Annotate.version}"
@options[:exit] = true
end
option_parser.on('-m', '--show-migration', 'Include the migration version number in the annotation') do
env['include_version'] = 'yes'
end
option_parser.on('-k', '--show-foreign-keys',
"List the table's foreign key constraints in the annotation") do
env['show_foreign_keys'] = 'yes'
end
option_parser.on('--ck',
'--complete-foreign-keys', 'Complete foreign key names in the annotation') do
env['show_foreign_keys'] = 'yes'
env['show_complete_foreign_keys'] = 'yes'
end
option_parser.on('-i', '--show-indexes',
"List the table's database indexes in the annotation") do
env['show_indexes'] = 'yes'
end
option_parser.on('-s', '--simple-indexes',
"Concat the column's related indexes in the annotation") do
env['simple_indexes'] = 'yes'
end
option_parser.on('--model-dir dir',
"Annotate model files stored in dir rather than app/models, separate multiple dirs with commas") do |dir|
env['model_dir'] = dir
end
option_parser.on('--root-dir dir',
"Annotate files stored within root dir projects, separate multiple dirs with commas") do |dir|
env['root_dir'] = dir
end
option_parser.on('--ignore-model-subdirects',
"Ignore subdirectories of the models directory") do |_dir|
env['ignore_model_sub_dir'] = 'yes'
end
option_parser.on('--sort',
"Sort columns alphabetically, rather than in creation order") do |_dir|
env['sort'] = 'yes'
end
option_parser.on('--classified-sort',
"Sort columns alphabetically, but first goes id, then the rest columns, then the timestamp columns and then the association columns") do |_dir|
env['classified_sort'] = 'yes'
end
option_parser.on('-R', '--require path',
"Additional file to require before loading models, may be used multiple times") do |path|
env['require'] = if !env['require'].blank?
env['require'] + ",#{path}"
else
path
end
end
option_parser.on('-e', '--exclude [tests,fixtures,factories,serializers]', Array, "Do not annotate fixtures, test files, factories, and/or serializers") do |exclusions|
exclusions ||= EXCLUSION_LIST
exclusions.each { |exclusion| env["exclude_#{exclusion}"] = 'yes' }
end
option_parser.on('-f', '--format [bare|rdoc|markdown]', FORMAT_TYPES, 'Render Schema Infomation as plain/RDoc/Markdown') do |fmt|
env["format_#{fmt}"] = 'yes'
end
option_parser.on('--force', 'Force new annotations even if there are no changes.') do |_force|
env['force'] = 'yes'
end
option_parser.on('--frozen', 'Do not allow to change annotations. Exits non-zero if there are going to be changes to files.') do
env['frozen'] = 'yes'
end
option_parser.on('--timestamp', 'Include timestamp in (routes) annotation') do
env['timestamp'] = 'true'
end
option_parser.on('--trace', 'If unable to annotate a file, print the full stack trace, not just the exception message.') do |_value|
env['trace'] = 'yes'
end
option_parser.on('-I', '--ignore-columns REGEX', "don't annotate columns that match a given REGEX (i.e., `annotate -I '^(id|updated_at|created_at)'`") do |regex|
env['ignore_columns'] = regex
end
option_parser.on('--ignore-routes REGEX', "don't annotate routes that match a given REGEX (i.e., `annotate -I '(mobile|resque|pghero)'`") do |regex|
env['ignore_routes'] = regex
end
option_parser.on('--hide-limit-column-types VALUES', "don't show limit for given column types, separated by commas (i.e., `integer,boolean,text`)") do |values|
env['hide_limit_column_types'] = values.to_s
end
option_parser.on('--hide-default-column-types VALUES', "don't show default for given column types, separated by commas (i.e., `json,jsonb,hstore`)") do |values|
env['hide_default_column_types'] = values.to_s
end
option_parser.on('--ignore-unknown-models', "don't display warnings for bad model files") do |_values|
env['ignore_unknown_models'] = 'true'
end
option_parser.on('--with-comment', "include database comments in model annotations") do |_values|
env['with_comment'] = 'true'
end
end
def default_options
{
target_action: :do_annotations,
exit: false
}
end
end
end
module Annotate module Annotate
def self.version def self.version
'2.7.5' '3.0.3'
end end
end end
...@@ -7,7 +7,9 @@ if Rails.env.development? ...@@ -7,7 +7,9 @@ if Rails.env.development?
# You can override any of these by setting an environment variable of the # You can override any of these by setting an environment variable of the
# same name. # same name.
Annotate.set_defaults( Annotate.set_defaults(
'additional_file_patterns' => [],
'routes' => 'false', 'routes' => 'false',
'models' => 'true',
'position_in_routes' => 'before', 'position_in_routes' => 'before',
'position_in_class' => 'before', 'position_in_class' => 'before',
'position_in_test' => 'before', 'position_in_test' => 'before',
......
...@@ -12,6 +12,7 @@ task annotate_models: :environment do ...@@ -12,6 +12,7 @@ task annotate_models: :environment do
options = {is_rake: true} options = {is_rake: true}
ENV['position'] = options[:position] = Annotate.fallback(ENV['position'], 'before') ENV['position'] = options[:position] = Annotate.fallback(ENV['position'], 'before')
options[:additional_file_patterns] = ENV['additional_file_patterns'] ? ENV['additional_file_patterns'].split(',') : []
options[:position_in_class] = Annotate.fallback(ENV['position_in_class'], ENV['position']) options[:position_in_class] = Annotate.fallback(ENV['position_in_class'], ENV['position'])
options[:position_in_fixture] = Annotate.fallback(ENV['position_in_fixture'], ENV['position']) options[:position_in_fixture] = Annotate.fallback(ENV['position_in_fixture'], ENV['position'])
options[:position_in_factory] = Annotate.fallback(ENV['position_in_factory'], ENV['position']) options[:position_in_factory] = Annotate.fallback(ENV['position_in_factory'], ENV['position'])
......
require File.dirname(__FILE__) + '/spec_helper.rb'
describe Annotate do
it 'should have a version' do
expect(Annotate.version).to be_instance_of(String)
end
end
...@@ -2,8 +2,8 @@ PATH ...@@ -2,8 +2,8 @@ PATH
remote: ../../.. remote: ../../..
specs: specs:
annotate (2.6.6) annotate (2.6.6)
activerecord (>= 3.2, <= 4.3) activerecord (>= 3.2, < 7.0)
rake (~> 10.4) rake (>= 10.4, < 14.0)
GEM GEM
remote: https://rubygems.org/ remote: https://rubygems.org/
...@@ -44,7 +44,7 @@ GEM ...@@ -44,7 +44,7 @@ GEM
thread_safe (~> 0.3, >= 0.3.4) thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1) tzinfo (~> 1.1)
arel (6.0.0) arel (6.0.0)
builder (3.2.2) builder (3.2.3)
coffee-rails (4.1.0) coffee-rails (4.1.0)
coffee-script (>= 2.2.0) coffee-script (>= 2.2.0)
railties (>= 4.0.0, < 5.0) railties (>= 4.0.0, < 5.0)
...@@ -52,12 +52,15 @@ GEM ...@@ -52,12 +52,15 @@ GEM
coffee-script-source coffee-script-source
execjs execjs
coffee-script-source (1.9.1) coffee-script-source (1.9.1)
concurrent-ruby (1.1.5)
crass (1.0.5)
erubis (2.7.0) erubis (2.7.0)
execjs (2.4.0) execjs (2.4.0)
globalid (0.3.3) globalid (0.3.3)
activesupport (>= 4.1.0) activesupport (>= 4.1.0)
hike (1.2.3) hike (1.2.3)
i18n (0.7.0) i18n (0.9.5)
concurrent-ruby (~> 1.0)
jbuilder (2.2.11) jbuilder (2.2.11)
activesupport (>= 3.0.0, < 5) activesupport (>= 3.0.0, < 5)
multi_json (~> 1.2) multi_json (~> 1.2)
...@@ -65,18 +68,19 @@ GEM ...@@ -65,18 +68,19 @@ GEM
rails-dom-testing (~> 1.0) rails-dom-testing (~> 1.0)
railties (>= 4.2.0) railties (>= 4.2.0)
thor (>= 0.14, < 2.0) thor (>= 0.14, < 2.0)
json (1.8.2) json (1.8.6)
loofah (2.0.1) loofah (2.3.1)
crass (~> 1.0.2)
nokogiri (>= 1.5.9) nokogiri (>= 1.5.9)
mail (2.6.3) mail (2.6.3)
mime-types (>= 1.16, < 3) mime-types (>= 1.16, < 3)
mime-types (2.4.3) mime-types (2.4.3)
mini_portile (0.6.2) mini_portile2 (2.4.0)
minitest (5.5.1) minitest (5.12.2)
multi_json (1.11.0) multi_json (1.11.0)
nokogiri (1.6.6.2) nokogiri (1.10.5)
mini_portile (~> 0.6.0) mini_portile2 (~> 2.4.0)
rack (1.6.0) rack (1.6.11)
rack-test (0.6.3) rack-test (0.6.3)
rack (>= 1.0) rack (>= 1.0)
rails (4.2.0) rails (4.2.0)
...@@ -92,12 +96,12 @@ GEM ...@@ -92,12 +96,12 @@ GEM
sprockets-rails sprockets-rails
rails-deprecated_sanitizer (1.0.3) rails-deprecated_sanitizer (1.0.3)
activesupport (>= 4.2.0.alpha) activesupport (>= 4.2.0.alpha)
rails-dom-testing (1.0.5) rails-dom-testing (1.0.9)
activesupport (>= 4.2.0.beta, < 5.0) activesupport (>= 4.2.0, < 5.0)
nokogiri (~> 1.6.0) nokogiri (~> 1.6)
rails-deprecated_sanitizer (>= 1.0.1) rails-deprecated_sanitizer (>= 1.0.1)
rails-html-sanitizer (1.0.1) rails-html-sanitizer (1.2.0)
loofah (~> 2.0) loofah (~> 2.2, >= 2.2.2)
rails-observers (0.1.2) rails-observers (0.1.2)
activemodel (~> 4.0) activemodel (~> 4.0)
railties (4.2.0) railties (4.2.0)
...@@ -130,11 +134,11 @@ GEM ...@@ -130,11 +134,11 @@ GEM
sprockets (>= 2.8, < 4.0) sprockets (>= 2.8, < 4.0)
sqlite3 (1.3.10) sqlite3 (1.3.10)
thor (0.19.1) thor (0.19.1)
thread_safe (0.3.4) thread_safe (0.3.6)
tilt (1.4.1) tilt (1.4.1)
turbolinks (2.5.3) turbolinks (2.5.3)
coffee-rails coffee-rails
tzinfo (1.2.2) tzinfo (1.2.5)
thread_safe (~> 0.1) thread_safe (~> 0.1)
uglifier (2.7.1) uglifier (2.7.1)
execjs (>= 0.3.0) execjs (>= 0.3.0)
......
# encoding: utf-8 # encoding: utf-8
require File.dirname(__FILE__) + '/../spec_helper.rb' require_relative '../../spec_helper'
require 'annotate/annotate_models' require 'annotate/annotate_models'
require 'annotate/active_record_patch' require 'annotate/active_record_patch'
require 'active_support/core_ext/string' require 'active_support/core_ext/string'
...@@ -70,8 +70,8 @@ describe AnnotateModels do # rubocop:disable Metrics/BlockLength ...@@ -70,8 +70,8 @@ describe AnnotateModels do # rubocop:disable Metrics/BlockLength
it { expect(AnnotateModels.quote(25)).to eql('25') } it { expect(AnnotateModels.quote(25)).to eql('25') }
it { expect(AnnotateModels.quote(25.6)).to eql('25.6') } it { expect(AnnotateModels.quote(25.6)).to eql('25.6') }
it { expect(AnnotateModels.quote(1e-20)).to eql('1.0e-20') } it { expect(AnnotateModels.quote(1e-20)).to eql('1.0e-20') }
it { expect(AnnotateModels.quote(BigDecimal.new('1.2'))).to eql('1.2') } it { expect(AnnotateModels.quote(BigDecimal('1.2'))).to eql('1.2') }
it { expect(AnnotateModels.quote([BigDecimal.new('1.2')])).to eql(['1.2']) } it { expect(AnnotateModels.quote([BigDecimal('1.2')])).to eql(['1.2']) }
describe '#parse_options' do describe '#parse_options' do
let(:options) do let(:options) do
...@@ -780,6 +780,69 @@ EOS ...@@ -780,6 +780,69 @@ EOS
end end
end end
describe '#files_by_pattern' do
subject { AnnotateModels.files_by_pattern(root_directory, pattern_type, options) }
context 'when pattern_type=additional_file_patterns' do
let(:pattern_type) { 'additional_file_patterns' }
let(:root_directory) { nil }
context 'with additional_file_patterns' do
let(:additional_file_patterns) do
[
'%PLURALIZED_MODEL_NAME%/**/*.rb',
'%PLURALIZED_MODEL_NAME%/*_form'
]
end
let(:options) { { additional_file_patterns: additional_file_patterns } }
it do
expect(subject).to eq(additional_file_patterns)
end
end
context 'without additional_file_patterns' do
let(:options) { {} }
it do
expect(subject).to eq([])
end
end
end
end
describe '#get_patterns' do
subject { AnnotateModels.get_patterns(options, pattern_type) }
context 'when pattern_type=additional_file_patterns' do
let(:pattern_type) { 'additional_file_patterns' }
context 'with additional_file_patterns' do
let(:additional_file_patterns) do
[
'/%PLURALIZED_MODEL_NAME%/**/*.rb',
'/bar/%PLURALIZED_MODEL_NAME%/*_form'
]
end
let(:options) { { additional_file_patterns: additional_file_patterns } }
it do
expect(subject).to eq(additional_file_patterns)
end
end
context 'without additional_file_patterns' do
let(:options) { {} }
it do
expect(subject).to eq([])
end
end
end
end
describe '#get_schema_info with custom options' do describe '#get_schema_info with custom options' do
def self.when_called_with(options = {}) def self.when_called_with(options = {})
expected = options.delete(:returns) expected = options.delete(:returns)
...@@ -1505,6 +1568,24 @@ end ...@@ -1505,6 +1568,24 @@ end
expect(filename). to eq 'test/unit/example_model_test.rb' expect(filename). to eq 'test/unit/example_model_test.rb'
end end
it 'should return the additional glob' do
filename_template = '/foo/bar/%MODEL_NAME%/testing.rb'
model_name = 'example_model'
table_name = 'example_models'
filename = AnnotateModels.resolve_filename(filename_template, model_name, table_name)
expect(filename). to eq '/foo/bar/example_model/testing.rb'
end
it 'should return the additional glob' do
filename_template = '/foo/bar/%PLURALIZED_MODEL_NAME%/testing.rb'
model_name = 'example_model'
table_name = 'example_models'
filename = AnnotateModels.resolve_filename(filename_template, model_name, table_name)
expect(filename). to eq '/foo/bar/example_models/testing.rb'
end
it 'should return the fixture path for a model' do it 'should return the fixture path for a model' do
filename_template = 'test/fixtures/%TABLE_NAME%.yml' filename_template = 'test/fixtures/%TABLE_NAME%.yml'
model_name = 'example_model' model_name = 'example_model'
...@@ -1523,6 +1604,7 @@ end ...@@ -1523,6 +1604,7 @@ end
expect(filename). to eq 'test/fixtures/parent/children.yml' expect(filename). to eq 'test/fixtures/parent/children.yml'
end end
end end
describe 'annotating a file' do describe 'annotating a file' do
before do before do
@model_dir = Dir.mktmpdir('annotate_models') @model_dir = Dir.mktmpdir('annotate_models')
...@@ -1737,7 +1819,7 @@ end ...@@ -1737,7 +1819,7 @@ end
end end
expect(error_output).to include("Unable to annotate #{@model_dir}/user.rb: oops") expect(error_output).to include("Unable to annotate #{@model_dir}/user.rb: oops")
expect(error_output).to include('/spec/annotate/annotate_models_spec.rb:') expect(error_output).to include('/spec/lib/annotate/annotate_models_spec.rb:')
end end
end end
......
require File.dirname(__FILE__) + '/../spec_helper.rb' require_relative '../../spec_helper'
require 'annotate/annotate_routes' require 'annotate/annotate_routes'
describe AnnotateRoutes do describe AnnotateRoutes do
......
require_relative '../../spec_helper'
module Annotate # rubocop:disable Metrics/ModuleLength
describe Parser do # rubocop:disable Metrics/BlockLength
before(:example) do
ENV.clear
end
context 'when given empty args' do
it 'returns an options hash with defaults' do
result = Parser.parse([])
expect(result).to be_a(Hash)
expect(result).to include(target_action: :do_annotations)
end
end
%w[--additional-file-patterns].each do |option|
describe option do
it 'sets array of paths to :additional_file_patterns' do
paths = 'foo/bar,baz'
allow(ENV).to receive(:[]=)
Parser.parse([option, paths])
expect(ENV).to have_received(:[]=).with('additional_file_patterns', ['foo/bar', 'baz'])
end
end
end
%w[-d --delete].each do |option|
describe option do
it 'sets target_action to :remove_annotations' do
result = Parser.parse([option])
expect(result).to include(target_action: :remove_annotations)
end
end
end
%w[-p --position].each do |option|
describe option do
Parser::ANNOTATION_POSITIONS.each do |position|
context "when specifying #{position}" do
it "#{position} position is an option" do
allow(ENV).to receive(:[]=)
Parser.parse([option, position])
expect(Parser::ANNOTATION_POSITIONS).to include(position)
end
it "sets ENV['position'] to be position" do
allow(ENV).to receive(:[]=)
Parser.parse([option, position])
expect(ENV).to have_received(:[]=).with('position', position)
end
it 'sets the value in ENV for the different file types' do
allow(ENV).to receive(:[]=)
Parser.parse([option, position])
Parser::FILE_TYPE_POSITIONS.each do |file_type|
expect(ENV).to have_received(:[]=).with(file_type, position)
end
end
end
end
end
end
context 'when position_in_class is set to top' do
context 'and when position is a different value' do
it 'does not override' do
other_commands = %w[--pc top]
position_command = %w[-p bottom]
options = other_commands + position_command
Parser.parse(options)
expect(ENV['position_in_class']).to eq('top')
expect(ENV['position']).to eq('bottom')
end
end
end
%w[--pc --position-in-class].each do |option|
describe option do
let(:env_key) { 'position_in_class' }
Parser::ANNOTATION_POSITIONS.each do |position|
context "when specifying '#{position}'" do
it "sets the ENV variable to '#{position}'" do
allow(ENV).to receive(:[]=)
Parser.parse([option, position])
expect(ENV).to have_received(:[]=).with(env_key, position)
end
end
end
end
end
%w[--pf --position-in-factory].each do |option|
describe option do
let(:env_key) { 'position_in_factory' }
Parser::ANNOTATION_POSITIONS.each do |position|
context "when specifying #{position}" do
it "sets the ENV variable to #{position}" do
allow(ENV).to receive(:[]=)
Parser.parse([option, position])
expect(ENV).to have_received(:[]=).with(env_key, position)
end
end
end
end
end
%w[--px --position-in-fixture].each do |option|
describe option do
let(:env_key) { 'position_in_fixture' }
Parser::ANNOTATION_POSITIONS.each do |position|
context "when specifying #{position}" do
it "sets the ENV variable to #{position}" do
allow(ENV).to receive(:[]=)
Parser.parse([option, position])
expect(ENV).to have_received(:[]=).with(env_key, position)
end
end
end
end
end
%w[--pt --position-in-test].each do |option|
describe option do
let(:env_key) { 'position_in_test' }
Parser::ANNOTATION_POSITIONS.each do |position|
context "when specifying #{position}" do
it "sets the ENV variable to #{position}" do
allow(ENV).to receive(:[]=)
Parser.parse([option, position])
expect(ENV).to have_received(:[]=).with(env_key, position)
end
end
end
end
end
%w[--pr --position-in-routes].each do |option|
describe option do
let(:env_key) { 'position_in_routes' }
Parser::ANNOTATION_POSITIONS.each do |position|
context "when specifying #{position}" do
it "sets the ENV variable to #{position}" do
allow(ENV).to receive(:[]=)
Parser.parse([option, position])
expect(ENV).to have_received(:[]=).with(env_key, position)
end
end
end
end
end
%w[--ps --position-in-serializer].each do |option|
describe option do
let(:env_key) { 'position_in_serializer' }
Parser::ANNOTATION_POSITIONS.each do |position|
context "when specifying #{position}" do
it "sets the ENV variable to #{position}" do
allow(ENV).to receive(:[]=)
Parser.parse([option, position])
expect(ENV).to have_received(:[]=).with(env_key, position)
end
end
end
end
end
%w[--w --wrapper].each do |option|
describe option do
let(:env_key) { 'wrapper' }
let(:set_value) { 'STR' }
it 'sets the ENV variable' do
expect(ENV).to receive(:[]=).with(env_key, set_value)
Parser.parse([option, set_value])
end
end
end
%w[--wo --wrapper-open].each do |option|
describe option do
let(:env_key) { 'wrapper_open' }
let(:set_value) { 'STR' }
it 'sets the ENV variable' do
expect(ENV).to receive(:[]=).with(env_key, set_value)
Parser.parse([option, set_value])
end
end
end
%w[--wc --wrapper-close].each do |option|
describe option do
let(:env_key) { 'wrapper_close' }
let(:set_value) { 'STR' }
it 'sets the ENV variable' do
expect(ENV).to receive(:[]=).with(env_key, set_value)
Parser.parse([option, set_value])
end
end
end
%w[-r --routes].each do |option|
describe option do
let(:env_key) { 'routes' }
let(:set_value) { 'true' }
it 'sets the ENV variable' do
expect(ENV).to receive(:[]=).with(env_key, set_value)
Parser.parse([option])
end
end
end
%w[--models].each do |option|
describe option do
let(:env_key) { 'models' }
let(:set_value) { 'true' }
it 'sets the ENV variable' do
expect(ENV).to receive(:[]=).with(env_key, set_value)
Parser.parse([option])
end
end
end
%w[-a --active-admin].each do |option|
describe option do
let(:env_key) { 'active_admin' }
let(:set_value) { 'true' }
it 'sets the ENV variable' do
expect(ENV).to receive(:[]=).with(env_key, set_value)
Parser.parse([option])
end
end
end
%w[-v --version].each do |option|
describe option do
it 'sets the ENV variable' do
expect { Parser.parse([option]) }.to output("annotate v#{Annotate.version}\n").to_stdout
expect(Parser.parse([option])).to include(exit: true)
end
end
end
%w[-m --show-migration].each do |option|
describe option do
let(:env_key) { 'include_version' }
let(:set_value) { 'yes' }
it 'sets the ENV variable' do
expect(ENV).to receive(:[]=).with(env_key, set_value)
Parser.parse([option])
end
end
end
%w[-k --show-foreign-keys].each do |option|
describe option do
let(:env_key) { 'show_foreign_keys' }
let(:set_value) { 'yes' }
it 'sets the ENV variable' do
expect(ENV).to receive(:[]=).with(env_key, set_value)
Parser.parse([option])
end
end
end
%w[--ck --complete-foreign-keys].each do |option|
describe option do
it 'sets the ENV variable' do
allow(ENV).to receive(:[]=)
Parser.parse([option])
expect(ENV).to have_received(:[]=).with('show_foreign_keys', 'yes')
expect(ENV).to have_received(:[]=).with('show_complete_foreign_keys', 'yes')
end
end
end
%w[-i --show-indexes].each do |option|
describe option do
let(:env_key) { 'show_indexes' }
let(:set_value) { 'yes' }
it 'sets the ENV variable' do
expect(ENV).to receive(:[]=).with(env_key, set_value)
Parser.parse([option])
end
end
end
%w[-s --simple-indexes].each do |option|
describe option do
let(:env_key) { 'simple_indexes' }
let(:set_value) { 'yes' }
it 'sets the ENV variable' do
expect(ENV).to receive(:[]=).with(env_key, set_value)
Parser.parse([option])
end
end
end
describe '--model-dir' do
let(:option) { '--model-dir' }
let(:env_key) { 'model_dir' }
let(:set_value) { 'some_dir/' }
it 'sets the ENV variable' do
expect(ENV).to receive(:[]=).with(env_key, set_value)
Parser.parse([option, set_value])
end
end
describe '--root-dir' do
let(:option) { '--root-dir' }
let(:env_key) { 'root_dir' }
let(:set_value) { 'some_dir/' }
it 'sets the ENV variable' do
expect(ENV).to receive(:[]=).with(env_key, set_value)
Parser.parse([option, set_value])
end
end
describe '--ignore-model-subdirects' do
let(:option) { '--ignore-model-subdirects' }
let(:env_key) { 'ignore_model_sub_dir' }
let(:set_value) { 'yes' }
it 'sets the ENV variable' do
expect(ENV).to receive(:[]=).with(env_key, set_value)
Parser.parse([option])
end
end
describe '--sort' do
let(:option) { '--sort' }
let(:env_key) { 'sort' }
let(:set_value) { 'yes' }
it 'sets the ENV variable' do
expect(ENV).to receive(:[]=).with(env_key, set_value)
Parser.parse([option])
end
end
describe '--classified-sort' do
let(:option) { '--classified-sort' }
let(:env_key) { 'classified_sort' }
let(:set_value) { 'yes' }
it 'sets the ENV variable' do
expect(ENV).to receive(:[]=).with(env_key, set_value)
Parser.parse([option])
end
end
%w[-R --require].each do |option|
describe option do
let(:env_key) { 'require' }
let(:set_value) { 'another_dir' }
it 'sets the ENV variable' do
expect(ENV).to receive(:[]=).with(env_key, set_value)
Parser.parse([option, set_value])
end
context "when ENV['require'] is already set" do
let(:preset_require_value) { 'some_dir/' }
it "appends the path to ENV['require']" do
env = { 'require' => preset_require_value }
expect(ENV).to receive(:[]=).with(env_key, "#{preset_require_value},#{set_value}")
Parser.parse([option, set_value], env)
end
end
end
end
describe 'Parser::EXCLUSION_LIST' do
it "has 'tests'" do
expect(Parser::EXCLUSION_LIST).to include('tests')
end
it "has 'fixtures'" do
expect(Parser::EXCLUSION_LIST).to include('fixtures')
end
it "has 'factories'" do
expect(Parser::EXCLUSION_LIST).to include('factories')
end
it "has 'serializers'" do
expect(Parser::EXCLUSION_LIST).to include('serializers')
end
end
%w[-e --exclude].each do |option|
describe option do
let(:set_value) { 'yes' }
it "sets the exclusion ENV variables for 'tests', 'fixtures', 'factories', and 'serializers'" do
allow(ENV).to receive(:[]=)
Parser.parse([option])
expect(ENV).to have_received(:[]=).with('exclude_tests', set_value)
expect(ENV).to have_received(:[]=).with('exclude_fixtures', set_value)
expect(ENV).to have_received(:[]=).with('exclude_factories', set_value)
expect(ENV).to have_received(:[]=).with('exclude_serializers', set_value)
end
context 'when a type is passed in' do
let(:exclusions) { "tests" }
it "sets the exclusion ENV variable for 'tests' only" do
expect(ENV).to receive(:[]=).with('exclude_tests', set_value)
Parser.parse([option, exclusions])
end
end
context 'when two types are passed in' do
let(:exclusions) { "tests,fixtures" }
it "sets the exclusion ENV variable for 'tests' and 'fixtures'" do
allow(ENV).to receive(:[]=)
Parser.parse([option, exclusions])
expect(ENV).to have_received(:[]=).with('exclude_tests', set_value)
expect(ENV).to have_received(:[]=).with('exclude_fixtures', set_value)
end
end
end
end
%w[-f --format].each do |option|
describe option do
Parser::FORMAT_TYPES.each do |format_type|
context "when passing in format type '#{format_type}'" do
let(:env_key) { "format_#{format_type}" }
let(:set_value) { 'yes' }
it 'sets the ENV variable' do
expect(ENV).to receive(:[]=).with(env_key, set_value)
Parser.parse([option, format_type])
end
end
end
end
end
describe '--force' do
let(:option) { '--force' }
let(:env_key) { 'force' }
let(:set_value) { 'yes' }
it 'sets the ENV variable' do
expect(ENV).to receive(:[]=).with(env_key, set_value)
Parser.parse([option])
end
end
describe '--frozen' do
let(:option) { '--frozen' }
let(:env_key) { 'frozen' }
let(:set_value) { 'yes' }
it 'sets the ENV variable' do
expect(ENV).to receive(:[]=).with(env_key, set_value)
Parser.parse([option])
end
end
describe '--timestamp' do
let(:option) { '--timestamp' }
let(:env_key) { 'timestamp' }
let(:set_value) { 'true' }
it 'sets the ENV variable' do
expect(ENV).to receive(:[]=).with(env_key, set_value)
Parser.parse([option])
end
end
describe '--trace' do
let(:option) { '--trace' }
let(:env_key) { 'trace' }
let(:set_value) { 'yes' }
it 'sets the ENV variable' do
expect(ENV).to receive(:[]=).with(env_key, set_value)
Parser.parse([option])
end
end
%w[-I --ignore-columns].each do |option|
describe option do
let(:env_key) { 'ignore_columns' }
let(:regex) { '^(id|updated_at|created_at)' }
it 'sets the ENV variable' do
expect(ENV).to receive(:[]=).with(env_key, regex)
Parser.parse([option, regex])
end
end
end
describe '--ignore-routes' do
let(:option) { '--ignore-routes' }
let(:env_key) { 'ignore_routes' }
let(:regex) { '(mobile|resque|pghero)' }
it 'sets the ENV variable' do
expect(ENV).to receive(:[]=).with(env_key, regex)
Parser.parse([option, regex])
end
end
describe '--hide-limit-column-types' do
let(:option) { '--hide-limit-column-types' }
let(:env_key) { 'hide_limit_column_types' }
let(:values) { 'integer,boolean,text' }
it 'sets the ENV variable' do
expect(ENV).to receive(:[]=).with(env_key, values)
Parser.parse([option, values])
end
end
describe '--hide-default-column-types' do
let(:option) { '--hide-default-column-types' }
let(:env_key) { 'hide_default_column_types' }
let(:values) { 'json,jsonb,hstore' }
it 'sets the ENV variable' do
expect(ENV).to receive(:[]=).with(env_key, values)
Parser.parse([option, values])
end
end
describe '--ignore-unknown-models' do
let(:option) { '--ignore-unknown-models' }
let(:env_key) { 'ignore_unknown_models' }
let(:set_value) { 'true' }
it 'sets the ENV variable' do
expect(ENV).to receive(:[]=).with(env_key, set_value)
Parser.parse([option])
end
end
describe '--with-comment' do
let(:option) { '--with-comment' }
let(:env_key) { 'with_comment' }
let(:set_value) { 'true' }
it 'sets the ENV variable' do
expect(ENV).to receive(:[]=).with(env_key, set_value)
Parser.parse([option])
end
end
end
end
require_relative '../spec_helper'
describe Annotate do
describe '.version' do
it 'has version' do
expect(Annotate.version).to be_instance_of(String)
end
end
describe '.skip_on_migration?' do
it "checks ENV for 'ANNOTATE_SKIP_ON_DB_MIGRATE' or 'skip_on_db_migrate'" do
expect(ENV).to receive(:[]).twice
described_class.skip_on_migration?
end
end
describe '.include_routes?' do
it "checks ENV with 'routes'" do
expect(ENV).to receive(:[]).with('routes')
described_class.include_routes?
end
end
describe '.include_models?' do
it "checks ENV with 'models'" do
expect(ENV).to receive(:[]).with('models')
described_class.include_models?
end
end
end
require_relative '../spec_helper' require_relative '../../spec_helper'
describe 'ActiveRecord migration rake task hooks' do describe 'ActiveRecord migration rake task hooks' do
before do before do
......
...@@ -28,6 +28,7 @@ require 'active_support/core_ext/object/blank' ...@@ -28,6 +28,7 @@ require 'active_support/core_ext/object/blank'
require 'active_support/core_ext/class/subclasses' require 'active_support/core_ext/class/subclasses'
require 'active_support/core_ext/string/inflections' require 'active_support/core_ext/string/inflections'
require 'annotate' require 'annotate'
require 'annotate/parser'
require 'byebug' require 'byebug'
module Annotate module Annotate
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment