From 4baa4e92f631f7543a8739503bf342d6d8c03c97 Mon Sep 17 00:00:00 2001 From: Baron Bloomer Date: Tue, 4 Oct 2022 15:13:32 +0100 Subject: [PATCH 01/11] [ctran/annotate_models#969] Add support for Rails autoloader collapsed directories Signed-off-by: Baron Bloomer --- lib/annotate/annotate_models.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/annotate/annotate_models.rb b/lib/annotate/annotate_models.rb index fc503839..027c69a6 100644 --- a/lib/annotate/annotate_models.rb +++ b/lib/annotate/annotate_models.rb @@ -611,6 +611,15 @@ def get_loaded_model(model_path, file) $LOAD_PATH.map(&:to_s) .select { |path| absolute_file.include?(path) } .map { |path| absolute_file.sub(path, '').sub(/\.rb$/, '').sub(/^\//, '') } + + # Handle Rails apps with collapsed model paths + model_paths = model_paths + .select do |model_path| + defined?(Rails) && + Rails.autoloaders.main.collapse_dirs.any? && + Rails.autoloaders.main.collapse_dirs.select { |path| path.match(model_path) } + end.map { |model_path| model_path.sub(/\/models/, '') } + model_paths .map { |path| get_loaded_model_by_path(path) } .find { |loaded_model| !loaded_model.nil? } From 67cc1109dc361c1b0881390773922bb6486cb38d Mon Sep 17 00:00:00 2001 From: Baron Bloomer Date: Wed, 5 Oct 2022 13:57:54 +0100 Subject: [PATCH 02/11] Add spec Signed-off-by: Baron Bloomer --- lib/annotate/annotate_models.rb | 10 ++++---- spec/lib/annotate/annotate_models_spec.rb | 31 +++++++++++++++++++++++ 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/lib/annotate/annotate_models.rb b/lib/annotate/annotate_models.rb index 027c69a6..715598c1 100644 --- a/lib/annotate/annotate_models.rb +++ b/lib/annotate/annotate_models.rb @@ -614,11 +614,11 @@ def get_loaded_model(model_path, file) # Handle Rails apps with collapsed model paths model_paths = model_paths - .select do |model_path| - defined?(Rails) && - Rails.autoloaders.main.collapse_dirs.any? && - Rails.autoloaders.main.collapse_dirs.select { |path| path.match(model_path) } - end.map { |model_path| model_path.sub(/\/models/, '') } + .select do |mpath| + defined?(Rails) && + Rails.autoloaders.main.collapse_dirs.any? && + Rails.autoloaders.main.collapse_dirs.select { |path| path.match(mpath) } + end.map { |mpath| mpath.sub(/\/models/, '') } model_paths .map { |path| get_loaded_model_by_path(path) } diff --git a/spec/lib/annotate/annotate_models_spec.rb b/spec/lib/annotate/annotate_models_spec.rb index f712b1ad..67a43396 100644 --- a/spec/lib/annotate/annotate_models_spec.rb +++ b/spec/lib/annotate/annotate_models_spec.rb @@ -1892,6 +1892,37 @@ class FooInsideBar < ActiveRecord::Base expect(klass.name).to eq('Bar::FooInsideBar') end end + + context 'when class Bar::Foo is defined in Rails collapsed directory' do + before do + Rails = double('Rails') + # rubocop:disable RSpec/MessageChain + allow(Rails).to receive_message_chain(:autoloaders, :main, :collapse_dirs) { Set.new(["bar/models"]) } + # rubocop:enable RSpec/MessageChain + $LOAD_PATH.unshift(dir) + end + + let :dir do + AnnotateModels.model_dir[0] + end + + let :filename do + 'bar/models/foo.rb' + end + + let :file_content do + <<~EOS + module Bar + class Foo < ActiveRecord::Base + end + end + EOS + end + + it 'works' do + expect(klass.name).to eql('Bar::Foo') + end + end end context 'when class is defined inside module and class name is not capitalized normally' do From 2c30f232edf38ee7e199751185088aa046f2a8a5 Mon Sep 17 00:00:00 2001 From: Cuong Tran Date: Thu, 13 Oct 2022 02:25:13 +0000 Subject: [PATCH 03/11] Attempt to set up Github for ease of development --- .envrc | 6 + .github/workflows/ci.yml | 2 +- .gitignore | 8 +- .gitpod.Dockerfile | 11 ++ .gitpod.yml | 20 ++ .idea/misc.xml | 6 + .idea/modules.xml | 8 + .idea/vcs.xml | 6 + .idea/workspace.xml | 98 +++++++++ .rbenv-gemsets | 1 - .ruby-version | 1 + Gemfile | 4 +- Gemfile.lock | 231 ++++++++++++++++++++++ annotate_models.iml | 108 ++++++++++ devbox.json | 12 ++ spec/lib/annotate/annotate_models_spec.rb | 4 +- 16 files changed, 514 insertions(+), 12 deletions(-) create mode 100644 .envrc create mode 100644 .gitpod.Dockerfile create mode 100644 .gitpod.yml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 .idea/workspace.xml delete mode 100644 .rbenv-gemsets create mode 100644 .ruby-version create mode 100644 Gemfile.lock create mode 100644 annotate_models.iml create mode 100644 devbox.json diff --git a/.envrc b/.envrc new file mode 100644 index 00000000..fe464f42 --- /dev/null +++ b/.envrc @@ -0,0 +1,6 @@ +use_devbox() { + watch_file devbox.json + eval $(devbox shell --print-env) +} + +# use devbox diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7f907097..1ac95c88 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,7 +14,7 @@ jobs: strategy: fail-fast: false matrix: - ruby: ['2.7'] + ruby: ['2.7.6'] steps: - name: Checkout diff --git a/.gitignore b/.gitignore index bd5cc0e0..cee04563 100644 --- a/.gitignore +++ b/.gitignore @@ -2,13 +2,7 @@ .DS_Store .bundle .gems -.rbenv-version -.ruby-* -/.idea/ -/.rbx -/.rvmrc -/.yardoc/* -/Gemfile.lock +/out /coverage/* /dist /doc/* diff --git a/.gitpod.Dockerfile b/.gitpod.Dockerfile new file mode 100644 index 00000000..f556d470 --- /dev/null +++ b/.gitpod.Dockerfile @@ -0,0 +1,11 @@ +FROM gitpod/workspace-full +USER gitpod + +# Install Ruby version 2.7.6 and set it as default +RUN _ruby_version=ruby-2.7.6 \ + && printf "rvm_gems_path=/home/gitpod/.rvm\n" > ~/.rvmrc \ + && bash -lc "rvm reinstall ${_ruby_version} && \ + rvm use ${_ruby_version} --default" \ + && printf "rvm_gems_path=/workspace/.rvm" > ~/.rvmrc \ + && printf "{ rvm use \$(rvm current); } >/dev/null 2>&1\n" >> "$HOME/.bashrc.d/70-ruby" + diff --git a/.gitpod.yml b/.gitpod.yml new file mode 100644 index 00000000..76f9bdd9 --- /dev/null +++ b/.gitpod.yml @@ -0,0 +1,20 @@ +image: + file: .gitpod.Dockerfile + +github: + prebuilds: + develop: true + # enable for pull requests coming from this repo (defaults to true) + pullRequests: true + + # add a "Review in Gitpod" button as a comment to pull requests (defaults to true) + addComment: true + + # add a "Review in Gitpod" button to pull requests (defaults to false) + addBadge: true + + # add a label once the prebuild is ready to pull requests (defaults to false) + addLabel: prebuilt-in-gitpod + +tasks: + - init: bundle install diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 00000000..19f20a0a --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 00000000..be4c0242 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 00000000..35eb1ddf --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 00000000..90b77e51 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,98 @@ + + + + + + + + + + + + + + + { + "keyToString": { + "RunOnceActivity.OpenProjectViewOnStart": "true", + "RunOnceActivity.ShowReadmeOnStart": "true", + "WebServerToolWindowFactoryState": "false", + "node.js.detected.package.eslint": "true", + "node.js.detected.package.tslint": "true", + "node.js.selected.package.eslint": "(autodetect)", + "node.js.selected.package.tslint": "(autodetect)", + "project.structure.last.edited": "Modules", + "project.structure.proportion": "0.0", + "project.structure.side.proportion": "0.2", + "ruby.rails.projectView.checked": "true", + "vue.rearranger.settings.migration": "true" + } +} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1671885743351 + + + + + + + + + + + + \ No newline at end of file diff --git a/.rbenv-gemsets b/.rbenv-gemsets deleted file mode 100644 index a9606b74..00000000 --- a/.rbenv-gemsets +++ /dev/null @@ -1 +0,0 @@ -.gems diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 00000000..49cdd668 --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +2.7.6 diff --git a/Gemfile b/Gemfile index 0998ee0d..f7e44b04 100644 --- a/Gemfile +++ b/Gemfile @@ -1,9 +1,9 @@ source 'https://rubygems.org' -ruby '>= 2.4.0' +ruby '>= 2.7.6' gem 'activerecord', '>= 4.2.5', '< 6', require: false -gem 'rake', require: false +gem 'rake', '>= 13.0.6' group :development do gem 'bump' diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 00000000..66de42c3 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,231 @@ +GEM + remote: https://rubygems.org/ + specs: + activemodel (5.2.8.1) + activesupport (= 5.2.8.1) + activerecord (5.2.8.1) + activemodel (= 5.2.8.1) + activesupport (= 5.2.8.1) + arel (>= 9.0) + activesupport (5.2.8.1) + concurrent-ruby (~> 1.0, >= 1.0.2) + i18n (>= 0.7, < 2) + minitest (~> 5.1) + tzinfo (~> 1.1) + addressable (2.8.1) + public_suffix (>= 2.0.2, < 6.0) + arel (9.0.0) + ast (2.4.2) + bump (0.10.0) + byebug (11.1.3) + childprocess (4.1.0) + codeclimate-test-reporter (1.0.7) + simplecov + coderay (1.1.3) + concurrent-ruby (1.1.10) + coveralls (0.8.23) + json (>= 1.8, < 3) + simplecov (~> 0.16.1) + term-ansicolor (~> 1.3) + thor (>= 0.19.4, < 2.0) + tins (~> 1.6) + diff-lcs (1.5.0) + docile (1.4.0) + faraday (1.10.2) + faraday-em_http (~> 1.0) + faraday-em_synchrony (~> 1.0) + faraday-excon (~> 1.1) + faraday-httpclient (~> 1.0) + faraday-multipart (~> 1.0) + faraday-net_http (~> 1.0) + faraday-net_http_persistent (~> 1.0) + faraday-patron (~> 1.0) + faraday-rack (~> 1.0) + faraday-retry (~> 1.0) + ruby2_keywords (>= 0.0.4) + faraday-em_http (1.0.0) + faraday-em_synchrony (1.0.0) + faraday-excon (1.1.0) + faraday-httpclient (1.0.1) + faraday-multipart (1.0.4) + multipart-post (~> 2) + faraday-net_http (1.0.1) + faraday-net_http_persistent (1.2.0) + faraday-patron (1.0.0) + faraday-rack (1.0.0) + faraday-retry (1.0.3) + faraday_middleware (1.2.0) + faraday (~> 1.0) + ffi (1.15.5) + files (0.4.0) + formatador (1.1.0) + gh (0.18.0) + activesupport (~> 5.0) + addressable (~> 2.4) + faraday (~> 1.0) + faraday_middleware (~> 1.0) + multi_json (~> 1.0) + net-http-persistent (~> 2.9) + net-http-pipeline + git (1.13.0) + addressable (~> 2.8) + rchardet (~> 1.8) + guard (2.18.0) + formatador (>= 0.2.4) + listen (>= 2.7, < 4.0) + lumberjack (>= 1.0.12, < 2.0) + nenv (~> 0.1) + notiffany (~> 0.0) + pry (>= 0.13.0) + shellany (~> 0.0) + thor (>= 0.18.1) + guard-compat (1.2.1) + guard-rspec (4.7.3) + guard (~> 2.1) + guard-compat (~> 1.1) + rspec (>= 2.99.0, < 4.0) + highline (2.0.3) + i18n (1.12.0) + concurrent-ruby (~> 1.0) + iniparse (1.5.0) + json (2.6.3) + json_pure (2.6.3) + launchy (2.4.3) + addressable (~> 2.3) + listen (3.7.1) + rb-fsevent (~> 0.10, >= 0.10.3) + rb-inotify (~> 0.9, >= 0.9.10) + lumberjack (1.2.8) + method_source (1.0.0) + mg (0.0.8) + rake + minitest (5.16.3) + multi_json (1.15.0) + multipart-post (2.2.3) + nenv (0.3.0) + net-http-persistent (2.9.4) + net-http-pipeline (1.0.1) + notiffany (0.1.3) + nenv (~> 0.1) + shellany (~> 0.0) + overcommit (0.59.1) + childprocess (>= 0.6.3, < 5) + iniparse (~> 1.4) + rexml (~> 3.2) + parallel (1.22.1) + parser (3.1.3.0) + ast (~> 2.4.1) + pry (0.14.1) + coderay (~> 1.1) + method_source (~> 1.0) + pry-byebug (3.10.1) + byebug (~> 11.0) + pry (>= 0.13, < 0.15) + public_suffix (5.0.1) + pusher-client (0.6.2) + json + websocket (~> 1.0) + rainbow (3.1.1) + rake (13.0.6) + rb-fsevent (0.11.2) + rb-inotify (0.10.1) + ffi (~> 1.0) + rchardet (1.8.0) + regexp_parser (2.6.1) + rexml (3.2.5) + rspec (3.12.0) + rspec-core (~> 3.12.0) + rspec-expectations (~> 3.12.0) + rspec-mocks (~> 3.12.0) + rspec-core (3.12.0) + rspec-support (~> 3.12.0) + rspec-expectations (3.12.1) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.12.0) + rspec-mocks (3.12.1) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.12.0) + rspec-support (3.12.0) + rubocop (1.12.1) + parallel (~> 1.10) + parser (>= 3.0.0.0) + rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 1.8, < 3.0) + rexml + rubocop-ast (>= 1.2.0, < 2.0) + ruby-progressbar (~> 1.7) + unicode-display_width (>= 1.4.0, < 3.0) + rubocop-ast (1.24.0) + parser (>= 3.1.1.0) + rubocop-rake (0.6.0) + rubocop (~> 1.0) + rubocop-rspec (2.2.0) + rubocop (~> 1.0) + rubocop-ast (>= 1.1.0) + ruby-progressbar (1.11.0) + ruby2_keywords (0.0.5) + ruby_dep (1.5.0) + shellany (0.0.1) + simplecov (0.16.1) + docile (~> 1.1) + json (>= 1.8, < 3) + simplecov-html (~> 0.10.0) + simplecov-html (0.10.2) + sync (0.5.0) + term-ansicolor (1.7.1) + tins (~> 1.0) + terminal-notifier-guard (1.7.0) + thor (1.2.1) + thread_safe (0.3.6) + tins (1.32.1) + sync + travis (1.11.1) + faraday (~> 1.0) + faraday_middleware (~> 1.0) + gh (~> 0.13) + highline (~> 2.0) + json_pure (~> 2.3) + launchy (~> 2.1, < 2.5.0) + pusher-client (~> 0.4) + tzinfo (1.2.10) + thread_safe (~> 0.1) + unicode-display_width (2.3.0) + webrick (1.7.0) + websocket (1.2.9) + yard (0.9.28) + webrick (~> 1.7.0) + +PLATFORMS + arm64-darwin-21 + arm64-darwin-22 + x86_64-linux + +DEPENDENCIES + activerecord (>= 4.2.5, < 6) + bump + byebug + codeclimate-test-reporter + coveralls + files + git + guard-rspec + mg + overcommit + pry + pry-byebug + rake (>= 13.0.6) + rspec + rubocop (~> 1.12.0) + rubocop-rake + rubocop-rspec (~> 2.2.0) + ruby_dep (= 1.5.0) + simplecov + terminal-notifier-guard + travis + yard + +RUBY VERSION + ruby 2.7.6p219 + +BUNDLED WITH + 2.4.1 diff --git a/annotate_models.iml b/annotate_models.iml new file mode 100644 index 00000000..7a2f51e5 --- /dev/null +++ b/annotate_models.iml @@ -0,0 +1,108 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/devbox.json b/devbox.json new file mode 100644 index 00000000..14d2b499 --- /dev/null +++ b/devbox.json @@ -0,0 +1,12 @@ +{ + "packages": [ + "ruby", + "bundler" + ], + "shell": { + "init_hook": "bundle install" + }, + "nixpkgs": { + "commit": "52e3e80afff4b16ccb7c52e9f0f5220552f03d04" + } +} \ No newline at end of file diff --git a/spec/lib/annotate/annotate_models_spec.rb b/spec/lib/annotate/annotate_models_spec.rb index f712b1ad..1efd4022 100644 --- a/spec/lib/annotate/annotate_models_spec.rb +++ b/spec/lib/annotate/annotate_models_spec.rb @@ -2146,7 +2146,9 @@ class Foo < ActiveRecord::Base let :file_content_2 do <<-EOS - class Bar::Foo < ActiveRecord::Base + module Bar + class Foo < ActiveRecord::Base + end end EOS end From e7875ace866dd7a220bc6a3def5d3f86ec6790d9 Mon Sep 17 00:00:00 2001 From: Ben Jacobs Date: Mon, 30 Jan 2023 07:46:34 -0700 Subject: [PATCH 04/11] Add position_in_additional_file_patterns to options and parser --- lib/annotate/annotate_models.rb | 1 + lib/annotate/constants.rb | 2 +- lib/annotate/parser.rb | 10 +- .../templates/auto_annotate_models.rake | 91 ++++++++++--------- lib/tasks/annotate_models.rake | 1 + spec/lib/annotate/parser_spec.rb | 16 ++++ 6 files changed, 74 insertions(+), 47 deletions(-) diff --git a/lib/annotate/annotate_models.rb b/lib/annotate/annotate_models.rb index fc503839..644589ea 100644 --- a/lib/annotate/annotate_models.rb +++ b/lib/annotate/annotate_models.rb @@ -463,6 +463,7 @@ def matched_types(options) # :position_in_fixture:: where to place the annotated section in fixture file # :position_in_factory:: where to place the annotated section in factory file # :position_in_serializer:: where to place the annotated section in serializer file + # :position_in_additional_file_patterns:: where to place the annotated section in files that match additional patterns # :exclude_tests:: whether to skip modification of test/spec files # :exclude_fixtures:: whether to skip modification of fixture files # :exclude_factories:: whether to skip modification of factory files diff --git a/lib/annotate/constants.rb b/lib/annotate/constants.rb index cd2148f3..9a78cb37 100644 --- a/lib/annotate/constants.rb +++ b/lib/annotate/constants.rb @@ -8,7 +8,7 @@ module Constants POSITION_OPTIONS = [ :position_in_routes, :position_in_class, :position_in_test, :position_in_fixture, :position_in_factory, :position, - :position_in_serializer + :position_in_serializer, :position_in_additional_file_patterns ].freeze FLAG_OPTIONS = [ diff --git a/lib/annotate/parser.rb b/lib/annotate/parser.rb index cb27b8b5..66f3537e 100644 --- a/lib/annotate/parser.rb +++ b/lib/annotate/parser.rb @@ -15,7 +15,7 @@ def self.parse(args, env = {}) }.freeze 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 + FILE_TYPE_POSITIONS = %w[position_in_class position_in_factory position_in_fixture position_in_test position_in_routes position_in_serializer position_in_additional_file_patterns].freeze EXCLUSION_LIST = %w[tests fixtures factories serializers].freeze FORMAT_TYPES = %w[bare rdoc yard markdown].freeze @@ -124,6 +124,14 @@ def add_options_to_parser(option_parser) # rubocop:disable Metrics/MethodLength has_set_position['position_in_serializer'] = true end + option_parser.on('--pa', + '--position-in-additional-file-patterns [before|top|after|bottom]', + ANNOTATION_POSITIONS, + 'Place the annotations at the top (before) or the bottom (after) of files that match additional patterns') do |position_in_additional_file_patterns| + env['position_in_additional_file_patterns'] = position_in_additional_file_patterns + has_set_position['position_in_additional_file_patterns'] = true + end + option_parser.on('--w', '--wrapper STR', 'Wrap annotation with the text passed as parameter.', diff --git a/lib/generators/annotate/templates/auto_annotate_models.rake b/lib/generators/annotate/templates/auto_annotate_models.rake index 1f355249..3dfed2d4 100644 --- a/lib/generators/annotate/templates/auto_annotate_models.rake +++ b/lib/generators/annotate/templates/auto_annotate_models.rake @@ -7,51 +7,52 @@ if Rails.env.development? # You can override any of these by setting an environment variable of the # same name. Annotate.set_defaults( - 'active_admin' => 'false', - 'additional_file_patterns' => [], - 'routes' => 'false', - 'models' => 'true', - 'position_in_routes' => 'before', - 'position_in_class' => 'before', - 'position_in_test' => 'before', - 'position_in_fixture' => 'before', - 'position_in_factory' => 'before', - 'position_in_serializer' => 'before', - 'show_foreign_keys' => 'true', - 'show_complete_foreign_keys' => 'false', - 'show_indexes' => 'true', - 'simple_indexes' => 'false', - 'model_dir' => 'app/models', - 'root_dir' => '', - 'include_version' => 'false', - 'require' => '', - 'exclude_tests' => 'false', - 'exclude_fixtures' => 'false', - 'exclude_factories' => 'false', - 'exclude_serializers' => 'false', - 'exclude_scaffolds' => 'true', - 'exclude_controllers' => 'true', - 'exclude_helpers' => 'true', - 'exclude_sti_subclasses' => 'false', - 'ignore_model_sub_dir' => 'false', - 'ignore_columns' => nil, - 'ignore_routes' => nil, - 'ignore_unknown_models' => 'false', - 'hide_limit_column_types' => '<%= AnnotateModels::NO_LIMIT_COL_TYPES.join(",") %>', - 'hide_default_column_types' => '<%= AnnotateModels::NO_DEFAULT_COL_TYPES.join(",") %>', - 'skip_on_db_migrate' => 'false', - 'format_bare' => 'true', - 'format_rdoc' => 'false', - 'format_yard' => 'false', - 'format_markdown' => 'false', - 'sort' => 'false', - 'force' => 'false', - 'frozen' => 'false', - 'classified_sort' => 'true', - 'trace' => 'false', - 'wrapper_open' => nil, - 'wrapper_close' => nil, - 'with_comment' => 'true' + 'active_admin' => 'false', + 'additional_file_patterns' => [], + 'routes' => 'false', + 'models' => 'true', + 'position_in_routes' => 'before', + 'position_in_class' => 'before', + 'position_in_test' => 'before', + 'position_in_fixture' => 'before', + 'position_in_factory' => 'before', + 'position_in_serializer' => 'before', + 'position_in_additional_file_patterns' => 'before', + 'show_foreign_keys' => 'true', + 'show_complete_foreign_keys' => 'false', + 'show_indexes' => 'true', + 'simple_indexes' => 'false', + 'model_dir' => 'app/models', + 'root_dir' => '', + 'include_version' => 'false', + 'require' => '', + 'exclude_tests' => 'false', + 'exclude_fixtures' => 'false', + 'exclude_factories' => 'false', + 'exclude_serializers' => 'false', + 'exclude_scaffolds' => 'true', + 'exclude_controllers' => 'true', + 'exclude_helpers' => 'true', + 'exclude_sti_subclasses' => 'false', + 'ignore_model_sub_dir' => 'false', + 'ignore_columns' => nil, + 'ignore_routes' => nil, + 'ignore_unknown_models' => 'false', + 'hide_limit_column_types' => '<%= AnnotateModels::NO_LIMIT_COL_TYPES.join(",") %>', + 'hide_default_column_types' => '<%= AnnotateModels::NO_DEFAULT_COL_TYPES.join(",") %>', + 'skip_on_db_migrate' => 'false', + 'format_bare' => 'true', + 'format_rdoc' => 'false', + 'format_yard' => 'false', + 'format_markdown' => 'false', + 'sort' => 'false', + 'force' => 'false', + 'frozen' => 'false', + 'classified_sort' => 'true', + 'trace' => 'false', + 'wrapper_open' => nil, + 'wrapper_close' => nil, + 'with_comment' => 'true' ) end diff --git a/lib/tasks/annotate_models.rake b/lib/tasks/annotate_models.rake index 76d8cfe6..23935bf9 100644 --- a/lib/tasks/annotate_models.rake +++ b/lib/tasks/annotate_models.rake @@ -18,6 +18,7 @@ task annotate_models: :environment do options[:position_in_factory] = Annotate::Helpers.fallback(ENV['position_in_factory'], ENV['position']) options[:position_in_test] = Annotate::Helpers.fallback(ENV['position_in_test'], ENV['position']) options[:position_in_serializer] = Annotate::Helpers.fallback(ENV['position_in_serializer'], ENV['position']) + options[:position_in_additional_file_patterns] = Annotate::Helpers.fallback(ENV['position_in_additional_file_patterns'], ENV['position']) options[:show_foreign_keys] = Annotate::Helpers.true?(ENV['show_foreign_keys']) options[:show_complete_foreign_keys] = Annotate::Helpers.true?(ENV['show_complete_foreign_keys']) options[:show_indexes] = Annotate::Helpers.true?(ENV['show_indexes']) diff --git a/spec/lib/annotate/parser_spec.rb b/spec/lib/annotate/parser_spec.rb index 176e453e..e32c76d2 100644 --- a/spec/lib/annotate/parser_spec.rb +++ b/spec/lib/annotate/parser_spec.rb @@ -174,6 +174,22 @@ module Annotate # rubocop:disable Metrics/ModuleLength end end + %w[--pa --position-in-additional-file-patterns].each do |option| + describe option do + let(:env_key) { 'position_in_additional_file_patterns' } + + 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' } From 57b92fe9790cf3cf4a1e04d794b41b3c3eec6ef3 Mon Sep 17 00:00:00 2001 From: Guillermo Guerrero Date: Fri, 12 May 2023 17:27:37 +0200 Subject: [PATCH 05/11] decide when run rake or rails routes. --- README.md | 4 ++-- lib/annotate/annotate_routes.rb | 2 +- lib/annotate/annotate_routes/header_generator.rb | 3 ++- lib/annotate/parser.rb | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index abf325ff..85a89921 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ when using `SpatialAdapter`, `PostgisAdapter` or `PostGISAdapter`: # path :geometry line_string, 4326 ``` -Also, if you pass the `-r` option, it'll annotate `routes.rb` with the output of `rake routes`. +Also, if you pass the `-r` option, it'll annotate `routes.rb` with the output of `rake/rails routes`. ## Upgrading to 3.X and annotate models not working? @@ -217,7 +217,7 @@ you can do so with a simple environment variable, instead of editing the If --w option is used, the same text will be used as opening and closing --wo, --wrapper-open STR Annotation wrapper opening. --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/rails routes' --models Annotate ActiveRecord models -a, --active-admin Annotate active_admin models -v, --version Show the current version of this gem diff --git a/lib/annotate/annotate_routes.rb b/lib/annotate/annotate_routes.rb index c9a2218a..56c6a342 100644 --- a/lib/annotate/annotate_routes.rb +++ b/lib/annotate/annotate_routes.rb @@ -4,7 +4,7 @@ # # # -# Prepends the output of "rake routes" to the top of your routes.rb file. +# Prepends the output of "rake/rails routes" to the top of your routes.rb file. # Yes, it's simple but I'm thick and often need a reminder of what my routes # mean. # diff --git a/lib/annotate/annotate_routes/header_generator.rb b/lib/annotate/annotate_routes/header_generator.rb index b1c93acf..069c3a68 100644 --- a/lib/annotate/annotate_routes/header_generator.rb +++ b/lib/annotate/annotate_routes/header_generator.rb @@ -16,7 +16,8 @@ def generate(options = {}) private def routes_map(options) - result = `rake routes`.chomp("\n").split(/\n/, -1) + command = Rails.version.first.to_i > 5 ? `rails routes` : `rake routes` + result = command.chomp("\n").split(/\n/, -1) # In old versions of Rake, the first line of output was the cwd. Not so # much in newer ones. We ditch that line if it exists, and if not, we diff --git a/lib/annotate/parser.rb b/lib/annotate/parser.rb index 3f5ebdb0..5feaad3c 100644 --- a/lib/annotate/parser.rb +++ b/lib/annotate/parser.rb @@ -145,7 +145,7 @@ def add_options_to_parser(option_parser) # rubocop:disable Metrics/MethodLength, option_parser.on('-r', '--routes', - "Annotate routes.rb with the output of 'rake routes'") do + "Annotate routes.rb with the output of 'rake/rails routes'") do env['routes'] = 'true' end From 6720020e7f23d0326235df54c348d0758ee16a15 Mon Sep 17 00:00:00 2001 From: Guillermo Guerrero Date: Fri, 12 May 2023 17:38:20 +0200 Subject: [PATCH 06/11] require activerecord. --- lib/annotate/annotate_routes/header_generator.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/annotate/annotate_routes/header_generator.rb b/lib/annotate/annotate_routes/header_generator.rb index 069c3a68..94665151 100644 --- a/lib/annotate/annotate_routes/header_generator.rb +++ b/lib/annotate/annotate_routes/header_generator.rb @@ -1,3 +1,4 @@ +require 'active_record' require_relative './helpers' module AnnotateRoutes @@ -16,7 +17,7 @@ def generate(options = {}) private def routes_map(options) - command = Rails.version.first.to_i > 5 ? `rails routes` : `rake routes` + command = ActiveRecord.version.to_s.first.to_i > 5 ? `rails routes` : `rake routes` result = command.chomp("\n").split(/\n/, -1) # In old versions of Rake, the first line of output was the cwd. Not so From 550b6f76398361a8b90631f7c488d1a91b522310 Mon Sep 17 00:00:00 2001 From: Peter Goldstein Date: Fri, 31 Mar 2023 10:21:42 -0400 Subject: [PATCH 07/11] Add Ruby 3.0, 3.1, and 3.2 to CI Removes obsolete and unused gems. Replaces use of unmaintained files gem to allow running under Ruby 3.2. --- .github/workflows/ci.yml | 2 +- Gemfile | 7 +------ spec/lib/annotate/annotate_models_spec.rb | 22 +++++++++------------- 3 files changed, 11 insertions(+), 20 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7f907097..d0c3ee90 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,7 +14,7 @@ jobs: strategy: fail-fast: false matrix: - ruby: ['2.7'] + ruby: ['2.7', '3.0', '3.1', '3.2'] steps: - name: Checkout diff --git a/Gemfile b/Gemfile index 0998ee0d..e32ee095 100644 --- a/Gemfile +++ b/Gemfile @@ -2,13 +2,12 @@ source 'https://rubygems.org' ruby '>= 2.4.0' -gem 'activerecord', '>= 4.2.5', '< 6', require: false +gem 'activerecord', '>= 4.2.5', '< 8', require: false gem 'rake', require: false group :development do gem 'bump' gem 'mg', require: false - gem 'travis', require: false platforms :mri, :mingw do gem 'yard', require: false end @@ -25,11 +24,8 @@ group :development, :test do gem 'simplecov', require: false gem 'terminal-notifier-guard', require: false - gem 'codeclimate-test-reporter' - gem 'coveralls' gem 'overcommit' - gem 'ruby_dep', '1.5.0' platforms :mri, :mingw do gem 'pry', require: false @@ -38,6 +34,5 @@ group :development, :test do end group :test do - gem 'files', require: false gem 'git', require: false end diff --git a/spec/lib/annotate/annotate_models_spec.rb b/spec/lib/annotate/annotate_models_spec.rb index 09647461..72919cc0 100644 --- a/spec/lib/annotate/annotate_models_spec.rb +++ b/spec/lib/annotate/annotate_models_spec.rb @@ -3,7 +3,6 @@ require 'annotate/annotate_models' require 'annotate/active_record_patch' require 'active_support/core_ext/string' -require 'files' require 'tmpdir' describe AnnotateModels do @@ -2014,18 +2013,15 @@ def mock_column(name, type, options = {}) context 'when `model_dir` is valid' do let(:model_dir) do - Files do - file 'foo.rb' - dir 'bar' do - file 'baz.rb' - dir 'qux' do - file 'quux.rb' - end - end - dir 'concerns' do - file 'corge.rb' - end - end + dir = Dir.mktmpdir + FileUtils.touch(File.join(dir, 'foo.rb')) + FileUtils.mkdir_p(File.join(dir, 'bar')) + FileUtils.touch(File.join(dir, 'bar', 'baz.rb')) + FileUtils.mkdir_p(File.join(dir, 'bar', 'qux')) + FileUtils.touch(File.join(dir, 'bar', 'qux', 'quux.rb')) + FileUtils.mkdir_p(File.join(dir, 'concerns')) + FileUtils.touch(File.join(dir, 'concerns', 'corge.rb')) + dir end context 'when the model files are not specified' do From ed0ad8cf88ed5618577107205b8fa9b35e3f6bf2 Mon Sep 17 00:00:00 2001 From: Peter Goldstein Date: Fri, 31 Mar 2023 13:08:17 -0400 Subject: [PATCH 08/11] Upgrade rubocop and address lints --- .rubocop.yml | 3 + Gemfile | 5 +- annotate.gemspec | 5 +- bin/annotate | 2 +- lib/annotate.rb | 6 +- lib/annotate/annotate_models.rb | 12 +-- .../annotate_routes/header_generator.rb | 6 +- lib/annotate/helpers.rb | 6 +- lib/tasks/annotate_models.rake | 76 +++++++++---------- lib/tasks/annotate_routes.rake | 12 +-- spec/lib/annotate/annotate_models_spec.rb | 16 ++-- spec/lib/annotate/helpers_spec.rb | 12 +-- spec/lib/annotate/parser_spec.rb | 4 +- 13 files changed, 83 insertions(+), 82 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 4d06aa98..d1e88755 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -13,6 +13,9 @@ AllCops: - 'spec/integration/**/*' NewCops: enable +Lint/FormatParameterMismatch: + Enabled: false + Metrics/BlockLength: Exclude: - 'spec/**/*.rb' diff --git a/Gemfile b/Gemfile index e32ee095..b9187d16 100644 --- a/Gemfile +++ b/Gemfile @@ -18,13 +18,12 @@ group :development, :test do gem 'guard-rspec', require: false gem 'rspec', require: false - gem 'rubocop', '~> 1.12.0', require: false + gem 'rubocop', '~> 1.48.0', require: false gem 'rubocop-rake', require: false - gem 'rubocop-rspec', '~> 2.2.0', require: false + gem 'rubocop-rspec', '~> 2.19.0', require: false gem 'simplecov', require: false gem 'terminal-notifier-guard', require: false - gem 'overcommit' platforms :mri, :mingw do diff --git a/annotate.gemspec b/annotate.gemspec index 43b2ac99..8eb20eb7 100644 --- a/annotate.gemspec +++ b/annotate.gemspec @@ -18,15 +18,14 @@ Gem::Specification.new do |s| s.homepage = 'https://github.com/ctran/annotate_models' s.licenses = ['Ruby'] s.require_paths = ['lib'] - s.rubygems_version = '2.1.11' 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.add_runtime_dependency(%q, '>= 10.4', '< 14.0') s.add_runtime_dependency(%q, ['>= 3.2', '< 8.0']) s.metadata = { "bug_tracker_uri" => "https://github.com/ctran/annotate_models/issues/", - "source_code_uri" => "https://github.com/ctran/annotate_models.git" + "source_code_uri" => "https://github.com/ctran/annotate_models.git", + 'rubygems_mfa_required' => 'true' } end diff --git a/bin/annotate b/bin/annotate index feb0c042..59643481 100755 --- a/bin/annotate +++ b/bin/annotate @@ -24,7 +24,7 @@ options_result = Annotate::Parser.parse(ARGV) exit if options_result[:exit] options = Annotate.setup_options( - is_rake: ENV['is_rake'] && !ENV['is_rake'].empty? + is_rake: ENV.fetch('is_rake', nil) && !ENV['is_rake'].empty? ) Annotate.eager_load(options) if Annotate::Helpers.include_models? diff --git a/lib/annotate.rb b/lib/annotate.rb index 7c54e9ea..27941758 100644 --- a/lib/annotate.rb +++ b/lib/annotate.rb @@ -44,13 +44,13 @@ def self.set_defaults(options = {}) # def self.setup_options(options = {}) Constants::POSITION_OPTIONS.each do |key| - options[key] = Annotate::Helpers.fallback(ENV[key.to_s], ENV['position'], 'before') + options[key] = Annotate::Helpers.fallback(ENV.fetch(key.to_s, nil), ENV.fetch('position', nil), 'before') end Constants::FLAG_OPTIONS.each do |key| - options[key] = Annotate::Helpers.true?(ENV[key.to_s]) + options[key] = Annotate::Helpers.true?(ENV.fetch(key.to_s, nil)) end Constants::OTHER_OPTIONS.each do |key| - options[key] = !ENV[key.to_s].blank? ? ENV[key.to_s] : nil + options[key] = !ENV[key.to_s].blank? ? ENV.fetch(key.to_s, nil) : nil end Constants::PATH_OPTIONS.each do |key| options[key] = !ENV[key.to_s].blank? ? ENV[key.to_s].split(',') : [] diff --git a/lib/annotate/annotate_models.rb b/lib/annotate/annotate_models.rb index dc2901a3..fb4dc1b2 100644 --- a/lib/annotate/annotate_models.rb +++ b/lib/annotate/annotate_models.rb @@ -155,7 +155,7 @@ def get_schema_info(klass, header, options = {}) # rubocop:disable Metrics/Metho with_comments_column = with_comments_column?(klass, options) # Precalculate Values - cols_meta = cols.map do |col| + cols_meta = cols.to_h do |col| col_comment = with_comments || with_comments_column ? col.comment&.gsub(/\n/, "\\n") : nil col_type = get_col_type(col) attrs = get_attributes(col, col_type, klass, options) @@ -166,7 +166,7 @@ def get_schema_info(klass, header, options = {}) # rubocop:disable Metrics/Metho end simple_formatted_attrs = attrs.join(", ") [col.name, { col_type: col_type, attrs: attrs, col_name: col_name, simple_formatted_attrs: simple_formatted_attrs, col_comment: col_comment }] - end.to_h + end # Output annotation bare_max_attrs_length = cols_meta.map { |_, m| m[:simple_formatted_attrs].length }.max @@ -179,15 +179,15 @@ def get_schema_info(klass, header, options = {}) # rubocop:disable Metrics/Metho col_comment = cols_meta[col.name][:col_comment] if options[:format_rdoc] - info << sprintf("# %-#{max_size}.#{max_size}s%s", "*#{col_name}*::", attrs.unshift(col_type).join(", ")).rstrip + "\n" + info << (sprintf("# %-#{max_size}.#{max_size}s%s", "*#{col_name}*::", attrs.unshift(col_type).join(", ")).rstrip + "\n") elsif options[:format_yard] - info << sprintf("# @!attribute #{col_name}") + "\n" + info << (sprintf("# @!attribute #{col_name}") + "\n") ruby_class = col.respond_to?(:array) && col.array ? "Array<#{map_col_type_to_ruby_classes(col_type)}>": map_col_type_to_ruby_classes(col_type) - info << sprintf("# @return [#{ruby_class}]") + "\n" + info << (sprintf("# @return [#{ruby_class}]") + "\n") elsif options[:format_markdown] name_remainder = max_size - col_name.length - non_ascii_length(col_name) type_remainder = (md_type_allowance - 2) - col_type.length - info << (sprintf("# **`%s`**%#{name_remainder}s | `%s`%#{type_remainder}s | `%s`", col_name, " ", col_type, " ", attrs.join(", ").rstrip)).gsub('``', ' ').rstrip + "\n" + info << ((sprintf("# **`%s`**%#{name_remainder}s | `%s`%#{type_remainder}s | `%s`", col_name, " ", col_type, " ", attrs.join(", ").rstrip)).gsub('``', ' ').rstrip + "\n") elsif with_comments_column info << format_default(col_name, max_size, col_type, bare_type_allowance, simple_formatted_attrs, bare_max_attrs_length, col_comment) else diff --git a/lib/annotate/annotate_routes/header_generator.rb b/lib/annotate/annotate_routes/header_generator.rb index b1c93acf..677e698b 100644 --- a/lib/annotate/annotate_routes/header_generator.rb +++ b/lib/annotate/annotate_routes/header_generator.rb @@ -29,7 +29,7 @@ def routes_map(options) # Skip routes which match given regex # Note: it matches the complete line (route_name, path, controller/action) if regexp_for_ignoring_routes - result.reject { |line| line =~ regexp_for_ignoring_routes } + result.grep_v(regexp_for_ignoring_routes) else result end @@ -53,9 +53,9 @@ def generate out << comment(options[:wrapper_open]) if options[:wrapper_open] - out << comment(markdown? ? PREFIX_MD : PREFIX) + timestamp_if_required + out << (comment(markdown? ? PREFIX_MD : PREFIX) + timestamp_if_required) out << comment - return out if contents_without_magic_comments.size.zero? + return out if contents_without_magic_comments.empty? maxs = [HEADER_ROW.map(&:size)] + contents_without_magic_comments[1..-1].map { |line| line.split.map(&:size) } diff --git a/lib/annotate/helpers.rb b/lib/annotate/helpers.rb index 70568579..b65b4674 100644 --- a/lib/annotate/helpers.rb +++ b/lib/annotate/helpers.rb @@ -3,15 +3,15 @@ module Annotate class Helpers class << self def skip_on_migration? - ENV['ANNOTATE_SKIP_ON_DB_MIGRATE'] =~ Constants::TRUE_RE || ENV['skip_on_db_migrate'] =~ Constants::TRUE_RE + ENV.fetch('ANNOTATE_SKIP_ON_DB_MIGRATE', nil) =~ Constants::TRUE_RE || ENV.fetch('skip_on_db_migrate', nil) =~ Constants::TRUE_RE end def include_routes? - ENV['routes'] =~ Constants::TRUE_RE + ENV.fetch('routes', nil) =~ Constants::TRUE_RE end def include_models? - ENV['models'] =~ Constants::TRUE_RE + ENV.fetch('models', nil) =~ Constants::TRUE_RE end def true?(val) diff --git a/lib/tasks/annotate_models.rake b/lib/tasks/annotate_models.rake index 776f97ba..385afddf 100644 --- a/lib/tasks/annotate_models.rake +++ b/lib/tasks/annotate_models.rake @@ -11,48 +11,48 @@ task annotate_models: :environment do require "#{annotate_lib}/annotate/active_record_patch" options = {is_rake: true} - ENV['position'] = options[:position] = Annotate::Helpers.fallback(ENV['position'], 'before') + ENV['position'] = options[:position] = Annotate::Helpers.fallback(ENV.fetch('position', nil), 'before') options[:additional_file_patterns] = ENV['additional_file_patterns'] ? ENV['additional_file_patterns'].split(',') : [] - options[:position_in_class] = Annotate::Helpers.fallback(ENV['position_in_class'], ENV['position']) - options[:position_in_fixture] = Annotate::Helpers.fallback(ENV['position_in_fixture'], ENV['position']) - options[:position_in_factory] = Annotate::Helpers.fallback(ENV['position_in_factory'], ENV['position']) - options[:position_in_test] = Annotate::Helpers.fallback(ENV['position_in_test'], ENV['position']) - options[:position_in_serializer] = Annotate::Helpers.fallback(ENV['position_in_serializer'], ENV['position']) - options[:show_check_constraints] = Annotate::Helpers.true?(ENV['show_check_constraints']) - options[:show_foreign_keys] = Annotate::Helpers.true?(ENV['show_foreign_keys']) - options[:show_complete_foreign_keys] = Annotate::Helpers.true?(ENV['show_complete_foreign_keys']) - options[:show_indexes] = Annotate::Helpers.true?(ENV['show_indexes']) - options[:simple_indexes] = Annotate::Helpers.true?(ENV['simple_indexes']) + options[:position_in_class] = Annotate::Helpers.fallback(ENV.fetch('position_in_class', nil), ENV.fetch('position', nil)) + options[:position_in_fixture] = Annotate::Helpers.fallback(ENV.fetch('position_in_fixture', nil), ENV.fetch('position', nil)) + options[:position_in_factory] = Annotate::Helpers.fallback(ENV.fetch('position_in_factory', nil), ENV.fetch('position', nil)) + options[:position_in_test] = Annotate::Helpers.fallback(ENV.fetch('position_in_test', nil), ENV.fetch('position', nil)) + options[:position_in_serializer] = Annotate::Helpers.fallback(ENV.fetch('position_in_serializer', nil), ENV.fetch('position', nil)) + options[:show_check_constraints] = Annotate::Helpers.true?(ENV.fetch('show_check_constraints', nil)) + options[:show_foreign_keys] = Annotate::Helpers.true?(ENV.fetch('show_foreign_keys', nil)) + options[:show_complete_foreign_keys] = Annotate::Helpers.true?(ENV.fetch('show_complete_foreign_keys', nil)) + options[:show_indexes] = Annotate::Helpers.true?(ENV.fetch('show_indexes', nil)) + options[:simple_indexes] = Annotate::Helpers.true?(ENV.fetch('simple_indexes', nil)) options[:model_dir] = ENV['model_dir'] ? ENV['model_dir'].split(',') : ['app/models'] - options[:root_dir] = ENV['root_dir'] - options[:include_version] = Annotate::Helpers.true?(ENV['include_version']) + options[:root_dir] = ENV.fetch('root_dir', nil) + options[:include_version] = Annotate::Helpers.true?(ENV.fetch('include_version', nil)) options[:require] = ENV['require'] ? ENV['require'].split(',') : [] - options[:exclude_tests] = Annotate::Helpers.true?(ENV['exclude_tests']) - options[:exclude_factories] = Annotate::Helpers.true?(ENV['exclude_factories']) - options[:exclude_fixtures] = Annotate::Helpers.true?(ENV['exclude_fixtures']) - options[:exclude_serializers] = Annotate::Helpers.true?(ENV['exclude_serializers']) - options[:exclude_scaffolds] = Annotate::Helpers.true?(ENV['exclude_scaffolds']) + options[:exclude_tests] = Annotate::Helpers.true?(ENV.fetch('exclude_tests', nil)) + options[:exclude_factories] = Annotate::Helpers.true?(ENV.fetch('exclude_factories', nil)) + options[:exclude_fixtures] = Annotate::Helpers.true?(ENV.fetch('exclude_fixtures', nil)) + options[:exclude_serializers] = Annotate::Helpers.true?(ENV.fetch('exclude_serializers', nil)) + options[:exclude_scaffolds] = Annotate::Helpers.true?(ENV.fetch('exclude_scaffolds', nil)) options[:exclude_controllers] = Annotate::Helpers.true?(ENV.fetch('exclude_controllers', 'true')) options[:exclude_helpers] = Annotate::Helpers.true?(ENV.fetch('exclude_helpers', 'true')) - options[:exclude_sti_subclasses] = Annotate::Helpers.true?(ENV['exclude_sti_subclasses']) - options[:ignore_model_sub_dir] = Annotate::Helpers.true?(ENV['ignore_model_sub_dir']) - options[:format_bare] = Annotate::Helpers.true?(ENV['format_bare']) - options[:format_rdoc] = Annotate::Helpers.true?(ENV['format_rdoc']) - options[:format_yard] = Annotate::Helpers.true?(ENV['format_yard']) - options[:format_markdown] = Annotate::Helpers.true?(ENV['format_markdown']) - options[:sort] = Annotate::Helpers.true?(ENV['sort']) - options[:force] = Annotate::Helpers.true?(ENV['force']) - options[:frozen] = Annotate::Helpers.true?(ENV['frozen']) - options[:classified_sort] = Annotate::Helpers.true?(ENV['classified_sort']) - options[:trace] = Annotate::Helpers.true?(ENV['trace']) - options[:wrapper_open] = Annotate::Helpers.fallback(ENV['wrapper_open'], ENV['wrapper']) - options[:wrapper_close] = Annotate::Helpers.fallback(ENV['wrapper_close'], ENV['wrapper']) + options[:exclude_sti_subclasses] = Annotate::Helpers.true?(ENV.fetch('exclude_sti_subclasses', nil)) + options[:ignore_model_sub_dir] = Annotate::Helpers.true?(ENV.fetch('ignore_model_sub_dir', nil)) + options[:format_bare] = Annotate::Helpers.true?(ENV.fetch('format_bare', nil)) + options[:format_rdoc] = Annotate::Helpers.true?(ENV.fetch('format_rdoc', nil)) + options[:format_yard] = Annotate::Helpers.true?(ENV.fetch('format_yard', nil)) + options[:format_markdown] = Annotate::Helpers.true?(ENV.fetch('format_markdown', nil)) + options[:sort] = Annotate::Helpers.true?(ENV.fetch('sort', nil)) + options[:force] = Annotate::Helpers.true?(ENV.fetch('force', nil)) + options[:frozen] = Annotate::Helpers.true?(ENV.fetch('frozen', nil)) + options[:classified_sort] = Annotate::Helpers.true?(ENV.fetch('classified_sort', nil)) + options[:trace] = Annotate::Helpers.true?(ENV.fetch('trace', nil)) + options[:wrapper_open] = Annotate::Helpers.fallback(ENV.fetch('wrapper_open', nil), ENV.fetch('wrapper', nil)) + options[:wrapper_close] = Annotate::Helpers.fallback(ENV.fetch('wrapper_close', nil), ENV.fetch('wrapper', nil)) options[:ignore_columns] = ENV.fetch('ignore_columns', nil) options[:ignore_routes] = ENV.fetch('ignore_routes', nil) - options[:hide_limit_column_types] = Annotate::Helpers.fallback(ENV['hide_limit_column_types'], '') - options[:hide_default_column_types] = Annotate::Helpers.fallback(ENV['hide_default_column_types'], '') - options[:with_comment] = Annotate::Helpers.true?(ENV['with_comment']) - options[:with_comment_column] = Annotate::Helpers.true?(ENV['with_comment_column']) + options[:hide_limit_column_types] = Annotate::Helpers.fallback(ENV.fetch('hide_limit_column_types', nil), '') + options[:hide_default_column_types] = Annotate::Helpers.fallback(ENV.fetch('hide_default_column_types', nil), '') + options[:with_comment] = Annotate::Helpers.true?(ENV.fetch('with_comment', nil)) + options[:with_comment_column] = Annotate::Helpers.true?(ENV.fetch('with_comment_column', nil)) options[:ignore_unknown_models] = Annotate::Helpers.true?(ENV.fetch('ignore_unknown_models', 'false')) AnnotateModels.do_annotations(options) @@ -64,9 +64,9 @@ task remove_annotation: :environment do require "#{annotate_lib}/annotate/active_record_patch" options = {is_rake: true} - options[:model_dir] = ENV['model_dir'] - options[:root_dir] = ENV['root_dir'] + options[:model_dir] = ENV.fetch('model_dir', nil) + options[:root_dir] = ENV.fetch('root_dir', nil) options[:require] = ENV['require'] ? ENV['require'].split(',') : [] - options[:trace] = Annotate::Helpers.true?(ENV['trace']) + options[:trace] = Annotate::Helpers.true?(ENV.fetch('trace', nil)) AnnotateModels.remove_annotations(options) end diff --git a/lib/tasks/annotate_routes.rake b/lib/tasks/annotate_routes.rake index b2832d44..d882803f 100644 --- a/lib/tasks/annotate_routes.rake +++ b/lib/tasks/annotate_routes.rake @@ -10,13 +10,13 @@ task :annotate_routes => :environment do require "#{annotate_lib}/annotate/annotate_routes" options={} - ENV['position'] = options[:position] = Annotate::Helpers.fallback(ENV['position'], 'before') - options[:position_in_routes] = Annotate::Helpers.fallback(ENV['position_in_routes'], ENV['position']) - options[:ignore_routes] = Annotate::Helpers.fallback(ENV['ignore_routes'], nil) + ENV['position'] = options[:position] = Annotate::Helpers.fallback(ENV.fetch('position', nil), 'before') + options[:position_in_routes] = Annotate::Helpers.fallback(ENV.fetch('position_in_routes', nil), ENV.fetch('position', nil)) + options[:ignore_routes] = Annotate::Helpers.fallback(ENV.fetch('ignore_routes', nil), nil) options[:require] = ENV['require'] ? ENV['require'].split(',') : [] - options[:frozen] = Annotate::Helpers.true?(ENV['frozen']) - options[:wrapper_open] = Annotate::Helpers.fallback(ENV['wrapper_open'], ENV['wrapper']) - options[:wrapper_close] = Annotate::Helpers.fallback(ENV['wrapper_close'], ENV['wrapper']) + options[:frozen] = Annotate::Helpers.true?(ENV.fetch('frozen', nil)) + options[:wrapper_open] = Annotate::Helpers.fallback(ENV.fetch('wrapper_open', nil), ENV.fetch('wrapper', nil)) + options[:wrapper_close] = Annotate::Helpers.fallback(ENV.fetch('wrapper_close', nil), ENV.fetch('wrapper', nil)) AnnotateRoutes.do_annotations(options) end diff --git a/spec/lib/annotate/annotate_models_spec.rb b/spec/lib/annotate/annotate_models_spec.rb index 72919cc0..d48c9824 100644 --- a/spec/lib/annotate/annotate_models_spec.rb +++ b/spec/lib/annotate/annotate_models_spec.rb @@ -205,7 +205,7 @@ def mock_column(name, type, options = {}) end it 'sets skip_subdirectory_model_load to true' do - is_expected.to eq(true) + is_expected.to be(true) end end @@ -219,7 +219,7 @@ def mock_column(name, type, options = {}) end it 'sets skip_subdirectory_model_load to false' do - is_expected.to eq(false) + is_expected.to be(false) end end end @@ -1943,7 +1943,7 @@ def mock_column(name, type, options = {}) describe '.set_defaults' do subject do - Annotate::Helpers.true?(ENV['show_complete_foreign_keys']) + Annotate::Helpers.true?(ENV.fetch('show_complete_foreign_keys', nil)) end after :each do @@ -2838,7 +2838,7 @@ class User < ActiveRecord::Base def write_model(file_name, file_content) fname = File.join(@model_dir, file_name) FileUtils.mkdir_p(File.dirname(fname)) - File.open(fname, 'wb') { |f| f.write file_content } + File.binwrite(fname, file_content) [fname, file_content] end @@ -3089,11 +3089,11 @@ class User < ActiveRecord::Base end describe 'frozen option' do - it "should abort without existing annotation when frozen: true " do + it "should abort without existing annotation when frozen: true" do expect { annotate_one_file frozen: true }.to raise_error SystemExit, /user.rb needs to be updated, but annotate was run with `--frozen`./ end - it "should abort with different annotation when frozen: true " do + it "should abort with different annotation when frozen: true" do annotate_one_file another_schema_info = AnnotateModels.get_schema_info(mock_class(:users, :id, [mock_column(:id, :integer)]), '== Schema Info') @schema_info = another_schema_info @@ -3101,7 +3101,7 @@ class User < ActiveRecord::Base expect { annotate_one_file frozen: true }.to raise_error SystemExit, /user.rb needs to be updated, but annotate was run with `--frozen`./ end - it "should NOT abort with same annotation when frozen: true " do + it "should NOT abort with same annotation when frozen: true" do annotate_one_file expect { annotate_one_file frozen: true }.not_to raise_error end @@ -3122,7 +3122,7 @@ class Foo < ActiveRecord::Base; end after { Object.send :remove_const, 'Foo' } it 'skips attempt to annotate if no table exists for model' do - is_expected.to eq nil + is_expected.to be_nil end context 'with a non-class' do diff --git a/spec/lib/annotate/helpers_spec.rb b/spec/lib/annotate/helpers_spec.rb index b8de5df5..49705089 100644 --- a/spec/lib/annotate/helpers_spec.rb +++ b/spec/lib/annotate/helpers_spec.rb @@ -5,7 +5,7 @@ subject { described_class.skip_on_migration? } before do - allow(ENV).to receive(:[]).and_return(nil) + allow(ENV).to receive(:fetch).with(anything, nil).and_return(nil) end it { is_expected.to be_falsy } @@ -15,7 +15,7 @@ let(:env_value) { '1' } before do - allow(ENV).to receive(:[]).with(key).and_return(env_value) + allow(ENV).to receive(:fetch).with(key, nil).and_return(env_value) end it { is_expected.to be_truthy } @@ -26,7 +26,7 @@ let(:env_value) { '1' } before do - allow(ENV).to receive(:[]).with(key).and_return(env_value) + allow(ENV).to receive(:fetch).with(key, nil).and_return(env_value) end it { is_expected.to be_truthy } @@ -37,7 +37,7 @@ subject { described_class.include_routes? } before do - allow(ENV).to receive(:[]).and_return(nil) + allow(ENV).to receive(:fetch).with(anything, nil).and_return(nil) end it { is_expected.to be_falsy } @@ -47,7 +47,7 @@ let(:env_value) { '1' } before do - allow(ENV).to receive(:[]).with(key).and_return(env_value) + allow(ENV).to receive(:fetch).with(key, nil).and_return(env_value) end it { is_expected.to be_truthy } @@ -68,7 +68,7 @@ let(:env_value) { '1' } before do - allow(ENV).to receive(:[]).with(key).and_return(env_value) + allow(ENV).to receive(:fetch).with(key, nil).and_return(env_value) end it { is_expected.to be_truthy } diff --git a/spec/lib/annotate/parser_spec.rb b/spec/lib/annotate/parser_spec.rb index 16084b02..5fb54e58 100644 --- a/spec/lib/annotate/parser_spec.rb +++ b/spec/lib/annotate/parser_spec.rb @@ -72,8 +72,8 @@ module Annotate # rubocop:disable Metrics/ModuleLength options = other_commands + position_command Parser.parse(options) - expect(ENV['position_in_class']).to eq('top') - expect(ENV['position']).to eq('bottom') + expect(ENV.fetch('position_in_class', nil)).to eq('top') + expect(ENV.fetch('position', nil)).to eq('bottom') end end end From ac92cb2a82621c907956d31fa32eec5931e2696e Mon Sep 17 00:00:00 2001 From: petergoldstein Date: Mon, 11 Dec 2023 23:45:46 -0500 Subject: [PATCH 09/11] Update Rubocop to latest and address lints. --- .rubocop.yml | 5 +++++ Gemfile | 4 ++-- lib/annotate/annotate_models.rb | 6 +++--- lib/annotate/annotate_routes.rb | 6 +++--- lib/annotate/annotate_routes/header_generator.rb | 4 ++-- lib/annotate/annotate_routes/helpers.rb | 4 ++-- spec/lib/annotate/helpers_spec.rb | 14 +++++++------- 7 files changed, 24 insertions(+), 19 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index d1e88755..c34d3bee 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -12,6 +12,7 @@ AllCops: - 'tmp/**/*' - 'spec/integration/**/*' NewCops: enable + TargetRubyVersion: 2.7 Lint/FormatParameterMismatch: Enabled: false @@ -19,3 +20,7 @@ Lint/FormatParameterMismatch: Metrics/BlockLength: Exclude: - 'spec/**/*.rb' + +Metrics/ClassLength: + Exclude: + - 'lib/annotate/annotate_models.rb' diff --git a/Gemfile b/Gemfile index b9187d16..90b9f318 100644 --- a/Gemfile +++ b/Gemfile @@ -18,9 +18,9 @@ group :development, :test do gem 'guard-rspec', require: false gem 'rspec', require: false - gem 'rubocop', '~> 1.48.0', require: false + gem 'rubocop', '~> 1.59.0', require: false gem 'rubocop-rake', require: false - gem 'rubocop-rspec', '~> 2.19.0', require: false + gem 'rubocop-rspec', '~> 2.25.0', require: false gem 'simplecov', require: false gem 'terminal-notifier-guard', require: false diff --git a/lib/annotate/annotate_models.rb b/lib/annotate/annotate_models.rb index fb4dc1b2..e929cabc 100644 --- a/lib/annotate/annotate_models.rb +++ b/lib/annotate/annotate_models.rb @@ -39,7 +39,7 @@ module AnnotateModels } }.freeze - MAGIC_COMMENT_MATCHER = Regexp.new(/(^#\s*encoding:.*(?:\n|r\n))|(^# coding:.*(?:\n|\r\n))|(^# -\*- coding:.*(?:\n|\r\n))|(^# -\*- encoding\s?:.*(?:\n|\r\n))|(^#\s*frozen_string_literal:.+(?:\n|\r\n))|(^# -\*- frozen_string_literal\s*:.+-\*-(?:\n|\r\n))/).freeze + MAGIC_COMMENT_MATCHER = /(^#\s*encoding:.*(?:\n|r\n))|(^# coding:.*(?:\n|\r\n))|(^# -\*- coding:.*(?:\n|\r\n))|(^# -\*- encoding\s?:.*(?:\n|\r\n))|(^#\s*frozen_string_literal:.+(?:\n|\r\n))|(^# -\*- frozen_string_literal\s*:.+-\*-(?:\n|\r\n))/.freeze class << self def annotate_pattern(options = {}) @@ -156,7 +156,7 @@ def get_schema_info(klass, header, options = {}) # rubocop:disable Metrics/Metho # Precalculate Values cols_meta = cols.to_h do |col| - col_comment = with_comments || with_comments_column ? col.comment&.gsub(/\n/, "\\n") : nil + col_comment = with_comments || with_comments_column ? col.comment&.gsub("\n", "\\n") : nil col_type = get_col_type(col) attrs = get_attributes(col, col_type, klass, options) col_name = if with_comments && col_comment @@ -694,7 +694,7 @@ def parse_options(options = {}) end def split_model_dir(option_value) - option_value = option_value.is_a?(Array) ? option_value : option_value.split(',') + option_value = option_value.split(',') unless option_value.is_a?(Array) option_value.map(&:strip).reject(&:empty?) end diff --git a/lib/annotate/annotate_routes.rb b/lib/annotate/annotate_routes.rb index c9a2218a..45b9e0c5 100644 --- a/lib/annotate/annotate_routes.rb +++ b/lib/annotate/annotate_routes.rb @@ -18,8 +18,8 @@ # Released under the same license as Ruby. No Support. No Warranty. # -require_relative './annotate_routes/helpers' -require_relative './annotate_routes/header_generator' +require_relative 'annotate_routes/helpers' +require_relative 'annotate_routes/header_generator' module AnnotateRoutes class << self @@ -95,7 +95,7 @@ def rewrite_contents(existing_text, new_text, frozen) def annotate_routes(header, content, header_position, options = {}) magic_comments_map, content = Helpers.extract_magic_comments_from_array(content) if %w(before top).include?(options[:position_in_routes]) - header = header << '' if content.first != '' + header <<= '' if content.first != '' magic_comments_map << '' if magic_comments_map.any? new_content = magic_comments_map + header + content else diff --git a/lib/annotate/annotate_routes/header_generator.rb b/lib/annotate/annotate_routes/header_generator.rb index 677e698b..70593583 100644 --- a/lib/annotate/annotate_routes/header_generator.rb +++ b/lib/annotate/annotate_routes/header_generator.rb @@ -1,4 +1,4 @@ -require_relative './helpers' +require_relative 'helpers' module AnnotateRoutes class HeaderGenerator @@ -16,7 +16,7 @@ def generate(options = {}) private def routes_map(options) - result = `rake routes`.chomp("\n").split(/\n/, -1) + result = `rake routes`.chomp("\n").split("\n", -1) # In old versions of Rake, the first line of output was the cwd. Not so # much in newer ones. We ditch that line if it exists, and if not, we diff --git a/lib/annotate/annotate_routes/helpers.rb b/lib/annotate/annotate_routes/helpers.rb index 1dba65bb..9cf0dc30 100644 --- a/lib/annotate/annotate_routes/helpers.rb +++ b/lib/annotate/annotate_routes/helpers.rb @@ -1,6 +1,6 @@ module AnnotateRoutes module Helpers - MAGIC_COMMENT_MATCHER = Regexp.new(/(^#\s*encoding:.*)|(^# coding:.*)|(^# -\*- coding:.*)|(^# -\*- encoding\s?:.*)|(^#\s*frozen_string_literal:.+)|(^# -\*- frozen_string_literal\s*:.+-\*-)/).freeze + MAGIC_COMMENT_MATCHER = /(^#\s*encoding:.*)|(^# coding:.*)|(^# -\*- coding:.*)|(^# -\*- encoding\s?:.*)|(^#\s*frozen_string_literal:.+)|(^# -\*- frozen_string_literal\s*:.+-\*-)/.freeze class << self # TODO: write the method doc using ruby rdoc formats @@ -15,7 +15,7 @@ def strip_annotations(content) mode = :content header_position = 0 - content.split(/\n/, -1).each_with_index do |line, line_number| + content.split("\n", -1).each_with_index do |line, line_number| if mode == :header && line !~ /\s*#/ mode = :content real_content << line unless line.blank? diff --git a/spec/lib/annotate/helpers_spec.rb b/spec/lib/annotate/helpers_spec.rb index 49705089..c413c3b7 100644 --- a/spec/lib/annotate/helpers_spec.rb +++ b/spec/lib/annotate/helpers_spec.rb @@ -102,20 +102,20 @@ describe '.fallback' do subject { described_class.fallback(*args) } - let(:args) { [arg_1, arg_2] } + let(:args) { [first_arg, second_arg] } - let(:arg_1) { '' } # is considered blank - let(:arg_2) { 'yes' } + let(:first_arg) { '' } # is considered blank + let(:second_arg) { 'yes' } it 'returns the first non-blank argument' do - is_expected.to eq(arg_2) + is_expected.to eq(second_arg) end context 'when the first argument is non-blank' do - let(:arg_1) { 'yes' } - let(:arg_2) { 'no' } + let(:first_arg) { 'yes' } + let(:second_arg) { 'no' } - it { is_expected.to eq(arg_1) } + it { is_expected.to eq(first_arg) } end end From f9d640e5a585ba0bcdd3e756f2cb06e901e5d845 Mon Sep 17 00:00:00 2001 From: Yuji Yaginuma Date: Tue, 16 May 2023 14:26:39 +0900 Subject: [PATCH 10/11] Correctly capture columns that have a multibyte comment Fixes #836. --- lib/annotate/annotate_models.rb | 2 +- spec/lib/annotate/annotate_models_spec.rb | 28 +++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/lib/annotate/annotate_models.rb b/lib/annotate/annotate_models.rb index dc2901a3..06d3c389 100644 --- a/lib/annotate/annotate_models.rb +++ b/lib/annotate/annotate_models.rb @@ -433,7 +433,7 @@ def annotate_one_file(file_name, info_block, position, options = {}) old_header = old_content.match(header_pattern).to_s new_header = info_block.match(header_pattern).to_s - column_pattern = /^#[\t ]+[\w\*\.`]+[\t ]+.+$/ + column_pattern = /^#[\t ]+[^\t ]+[\t ]+.+$/ old_columns = old_header && old_header.scan(column_pattern).sort new_columns = new_header && new_header.scan(column_pattern).sort diff --git a/spec/lib/annotate/annotate_models_spec.rb b/spec/lib/annotate/annotate_models_spec.rb index 09647461..d5c07353 100644 --- a/spec/lib/annotate/annotate_models_spec.rb +++ b/spec/lib/annotate/annotate_models_spec.rb @@ -2922,6 +2922,34 @@ def annotate_one_file(options = {}) expect(File.read(@model_file_name)).to eq("#{@schema_info}#{@file_content}") end end + + context 'of multibyte comments' do + before do + klass = mock_class(:users, + :id, + [ + mock_column(:id, :integer, comment: 'ID'), + ], + [], + []) + @schema_info = AnnotateModels.get_schema_info(klass, '== Schema Info', with_comment: true) + annotate_one_file + end + + it 'should update columns' do + klass = mock_class(:users, + :id, + [ + mock_column(:id, :integer, comment: 'ID'), + mock_column(:active, :boolean, limit: 1, comment: 'ACTIVE'), + ], + [], + []) + @schema_info = AnnotateModels.get_schema_info(klass, '== Schema Info', with_comment: true) + annotate_one_file + expect(File.read(@model_file_name)).to eq("#{@schema_info}#{@file_content}") + end + end end describe 'with existing annotation => :before' do From 5d96dffe8d057743a2478fabbf00e41179b19099 Mon Sep 17 00:00:00 2001 From: Suleyman Musayev Date: Sun, 29 Dec 2024 23:43:51 +0500 Subject: [PATCH 11/11] clean up --- .github/workflows/ci.yml | 14 +- .github/workflows/codeql-analysis.yml | 2 +- .tool-versions | 2 +- Gemfile | 2 +- Gemfile.lock | 261 +++++++++++--------------- annotate.gemspec | 2 +- 6 files changed, 119 insertions(+), 164 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d0c3ee90..540e25d3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,20 +14,26 @@ jobs: strategy: fail-fast: false matrix: - ruby: ['2.7', '3.0', '3.1', '3.2'] + ruby: ['2.7.6'] steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Setup Ruby uses: ruby/setup-ruby@v1 with: ruby-version: ${{ matrix.ruby }} - bundler-cache: true + bundler-cache: false + + - name: Update RubyGems and install dependencies + run: | + gem update --system 3.3.22 + bundle config set --local force_ruby_platform true + bundle install --jobs 4 --retry 3 - name: Run Tests run: bundle exec rspec - name: Rubocop - run: bundle exec rubocop + run: bundle exec rubocop \ No newline at end of file diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 63379645..78223768 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -25,7 +25,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL diff --git a/.tool-versions b/.tool-versions index 9e83a384..33a8789f 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1 +1 @@ -ruby 2.7.3 +ruby 2.7.7 diff --git a/Gemfile b/Gemfile index 9e979e06..4d7cf902 100644 --- a/Gemfile +++ b/Gemfile @@ -2,7 +2,7 @@ source 'https://rubygems.org' ruby '>= 2.7.6' -gem 'activerecord', '>= 4.2.5', '< 8', require: false +gem 'activerecord', '>= 4.2.5', require: false gem 'rake', require: false group :development do diff --git a/Gemfile.lock b/Gemfile.lock index 66de42c3..e4d98dc6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,76 +1,47 @@ GEM remote: https://rubygems.org/ specs: - activemodel (5.2.8.1) - activesupport (= 5.2.8.1) - activerecord (5.2.8.1) - activemodel (= 5.2.8.1) - activesupport (= 5.2.8.1) - arel (>= 9.0) - activesupport (5.2.8.1) + activemodel (7.1.5.1) + activesupport (= 7.1.5.1) + activerecord (7.1.5.1) + activemodel (= 7.1.5.1) + activesupport (= 7.1.5.1) + timeout (>= 0.4.0) + activesupport (7.1.5.1) + base64 + benchmark (>= 0.3) + bigdecimal concurrent-ruby (~> 1.0, >= 1.0.2) - i18n (>= 0.7, < 2) - minitest (~> 5.1) - tzinfo (~> 1.1) - addressable (2.8.1) - public_suffix (>= 2.0.2, < 6.0) - arel (9.0.0) + connection_pool (>= 2.2.5) + drb + i18n (>= 1.6, < 2) + logger (>= 1.4.2) + minitest (>= 5.1) + mutex_m + securerandom (>= 0.3) + tzinfo (~> 2.0) + addressable (2.8.7) + public_suffix (>= 2.0.2, < 7.0) ast (2.4.2) + base64 (0.2.0) + benchmark (0.4.0) + bigdecimal (3.1.9) bump (0.10.0) byebug (11.1.3) - childprocess (4.1.0) - codeclimate-test-reporter (1.0.7) - simplecov + childprocess (5.1.0) + logger (~> 1.5) coderay (1.1.3) - concurrent-ruby (1.1.10) - coveralls (0.8.23) - json (>= 1.8, < 3) - simplecov (~> 0.16.1) - term-ansicolor (~> 1.3) - thor (>= 0.19.4, < 2.0) - tins (~> 1.6) - diff-lcs (1.5.0) - docile (1.4.0) - faraday (1.10.2) - faraday-em_http (~> 1.0) - faraday-em_synchrony (~> 1.0) - faraday-excon (~> 1.1) - faraday-httpclient (~> 1.0) - faraday-multipart (~> 1.0) - faraday-net_http (~> 1.0) - faraday-net_http_persistent (~> 1.0) - faraday-patron (~> 1.0) - faraday-rack (~> 1.0) - faraday-retry (~> 1.0) - ruby2_keywords (>= 0.0.4) - faraday-em_http (1.0.0) - faraday-em_synchrony (1.0.0) - faraday-excon (1.1.0) - faraday-httpclient (1.0.1) - faraday-multipart (1.0.4) - multipart-post (~> 2) - faraday-net_http (1.0.1) - faraday-net_http_persistent (1.2.0) - faraday-patron (1.0.0) - faraday-rack (1.0.0) - faraday-retry (1.0.3) - faraday_middleware (1.2.0) - faraday (~> 1.0) - ffi (1.15.5) - files (0.4.0) + concurrent-ruby (1.3.4) + connection_pool (2.4.1) + diff-lcs (1.5.1) + docile (1.4.1) + drb (2.2.1) + ffi (1.17.0) formatador (1.1.0) - gh (0.18.0) - activesupport (~> 5.0) - addressable (~> 2.4) - faraday (~> 1.0) - faraday_middleware (~> 1.0) - multi_json (~> 1.0) - net-http-persistent (~> 2.9) - net-http-pipeline - git (1.13.0) + git (1.19.1) addressable (~> 2.8) rchardet (~> 1.8) - guard (2.18.0) + guard (2.19.0) formatador (>= 0.2.4) listen (>= 2.7, < 4.0) lumberjack (>= 1.0.12, < 2.0) @@ -84,148 +55,126 @@ GEM guard (~> 2.1) guard-compat (~> 1.1) rspec (>= 2.99.0, < 4.0) - highline (2.0.3) - i18n (1.12.0) + i18n (1.14.6) concurrent-ruby (~> 1.0) iniparse (1.5.0) - json (2.6.3) - json_pure (2.6.3) - launchy (2.4.3) - addressable (~> 2.3) - listen (3.7.1) + json (2.9.1) + language_server-protocol (3.17.0.3) + listen (3.9.0) rb-fsevent (~> 0.10, >= 0.10.3) rb-inotify (~> 0.9, >= 0.9.10) - lumberjack (1.2.8) - method_source (1.0.0) + logger (1.6.4) + lumberjack (1.2.10) + method_source (1.1.0) mg (0.0.8) rake - minitest (5.16.3) - multi_json (1.15.0) - multipart-post (2.2.3) + minitest (5.25.4) + mutex_m (0.3.0) nenv (0.3.0) - net-http-persistent (2.9.4) - net-http-pipeline (1.0.1) notiffany (0.1.3) nenv (~> 0.1) shellany (~> 0.0) - overcommit (0.59.1) - childprocess (>= 0.6.3, < 5) + overcommit (0.64.1) + childprocess (>= 0.6.3, < 6) iniparse (~> 1.4) - rexml (~> 3.2) - parallel (1.22.1) - parser (3.1.3.0) + rexml (>= 3.3.9) + parallel (1.26.3) + parser (3.3.6.0) ast (~> 2.4.1) - pry (0.14.1) + racc + pry (0.15.2) coderay (~> 1.1) method_source (~> 1.0) - pry-byebug (3.10.1) + pry-byebug (3.8.0) byebug (~> 11.0) - pry (>= 0.13, < 0.15) - public_suffix (5.0.1) - pusher-client (0.6.2) - json - websocket (~> 1.0) + pry (~> 0.10) + public_suffix (5.1.1) + racc (1.8.1) rainbow (3.1.1) - rake (13.0.6) + rake (13.2.1) rb-fsevent (0.11.2) - rb-inotify (0.10.1) + rb-inotify (0.11.1) ffi (~> 1.0) rchardet (1.8.0) - regexp_parser (2.6.1) - rexml (3.2.5) - rspec (3.12.0) - rspec-core (~> 3.12.0) - rspec-expectations (~> 3.12.0) - rspec-mocks (~> 3.12.0) - rspec-core (3.12.0) - rspec-support (~> 3.12.0) - rspec-expectations (3.12.1) + regexp_parser (2.10.0) + rexml (3.4.0) + rspec (3.13.0) + rspec-core (~> 3.13.0) + rspec-expectations (~> 3.13.0) + rspec-mocks (~> 3.13.0) + rspec-core (3.13.2) + rspec-support (~> 3.13.0) + rspec-expectations (3.13.3) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.12.0) - rspec-mocks (3.12.1) + rspec-support (~> 3.13.0) + rspec-mocks (3.13.2) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.12.0) - rspec-support (3.12.0) - rubocop (1.12.1) + rspec-support (~> 3.13.0) + rspec-support (3.13.2) + rubocop (1.59.0) + json (~> 2.3) + language_server-protocol (>= 3.17.0) parallel (~> 1.10) - parser (>= 3.0.0.0) + parser (>= 3.2.2.4) rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 1.8, < 3.0) - rexml - rubocop-ast (>= 1.2.0, < 2.0) + rexml (>= 3.2.5, < 4.0) + rubocop-ast (>= 1.30.0, < 2.0) ruby-progressbar (~> 1.7) - unicode-display_width (>= 1.4.0, < 3.0) - rubocop-ast (1.24.0) - parser (>= 3.1.1.0) + unicode-display_width (>= 2.4.0, < 3.0) + rubocop-ast (1.37.0) + parser (>= 3.3.1.0) + rubocop-capybara (2.21.0) + rubocop (~> 1.41) + rubocop-factory_bot (2.26.0) + rubocop (~> 1.41) rubocop-rake (0.6.0) rubocop (~> 1.0) - rubocop-rspec (2.2.0) - rubocop (~> 1.0) - rubocop-ast (>= 1.1.0) - ruby-progressbar (1.11.0) - ruby2_keywords (0.0.5) - ruby_dep (1.5.0) + rubocop-rspec (2.25.0) + rubocop (~> 1.40) + rubocop-capybara (~> 2.17) + rubocop-factory_bot (~> 2.22) + ruby-progressbar (1.13.0) + securerandom (0.3.2) shellany (0.0.1) - simplecov (0.16.1) + simplecov (0.22.0) docile (~> 1.1) - json (>= 1.8, < 3) - simplecov-html (~> 0.10.0) - simplecov-html (0.10.2) - sync (0.5.0) - term-ansicolor (1.7.1) - tins (~> 1.0) + simplecov-html (~> 0.11) + simplecov_json_formatter (~> 0.1) + simplecov-html (0.13.1) + simplecov_json_formatter (0.1.4) terminal-notifier-guard (1.7.0) - thor (1.2.1) - thread_safe (0.3.6) - tins (1.32.1) - sync - travis (1.11.1) - faraday (~> 1.0) - faraday_middleware (~> 1.0) - gh (~> 0.13) - highline (~> 2.0) - json_pure (~> 2.3) - launchy (~> 2.1, < 2.5.0) - pusher-client (~> 0.4) - tzinfo (1.2.10) - thread_safe (~> 0.1) - unicode-display_width (2.3.0) - webrick (1.7.0) - websocket (1.2.9) - yard (0.9.28) - webrick (~> 1.7.0) + thor (1.3.2) + timeout (0.4.3) + tzinfo (2.0.6) + concurrent-ruby (~> 1.0) + unicode-display_width (2.6.0) + yard (0.9.37) PLATFORMS - arm64-darwin-21 - arm64-darwin-22 - x86_64-linux + ruby DEPENDENCIES - activerecord (>= 4.2.5, < 6) + activerecord (>= 4.2.5) bump byebug - codeclimate-test-reporter - coveralls - files git guard-rspec mg overcommit pry pry-byebug - rake (>= 13.0.6) + rake rspec - rubocop (~> 1.12.0) + rubocop (~> 1.59.0) rubocop-rake - rubocop-rspec (~> 2.2.0) - ruby_dep (= 1.5.0) + rubocop-rspec (~> 2.25.0) simplecov terminal-notifier-guard - travis yard RUBY VERSION - ruby 2.7.6p219 + ruby 2.7.7p221 BUNDLED WITH - 2.4.1 + 2.1.4 diff --git a/annotate.gemspec b/annotate.gemspec index 8eb20eb7..f04a0ff4 100644 --- a/annotate.gemspec +++ b/annotate.gemspec @@ -21,7 +21,7 @@ Gem::Specification.new do |s| s.summary = 'Annotates Rails Models, routes, fixtures, and others based on the database schema.' s.add_runtime_dependency(%q, '>= 10.4', '< 14.0') - s.add_runtime_dependency(%q, ['>= 3.2', '< 8.0']) + s.add_runtime_dependency(%q, ['>= 3.2']) s.metadata = { "bug_tracker_uri" => "https://github.com/ctran/annotate_models/issues/",