1. 10 Feb, 2022 1 commit
  2. 01 Feb, 2022 1 commit
  3. 31 Jan, 2022 1 commit
  4. 14 Jun, 2021 1 commit
    • `get_loaded_model_by_path` is supposed to be nil-safe (#883) · e4f761c6
      Junichi Sato authored
      This commit partially reverts #801, which by declaring conditional return
      has turned `get_loaded_model_by_path` to a less safe method that can
      return nil when its the condition is not met.
      
      Apparently the very same condition has been brought to `annotate_model_file`
      by #774, which seems to cover the "bug" insisted in #801 as well.
      
      On the other hand #801 has brought an inconvenient behaviour as well:
      whenever a non-activerecord model file is found, `get_loaded_model_by_path`
      returns nil, which leads to raising `BadModelFileError` and ends up
      printing a bunch of "Unable to annotate ..." messages.
      
      Now it seems tests added by #801 are running right and I do not find
      a problem restoring the previous behaviour and turn it nil-safe again.
  5. 10 May, 2021 1 commit
  6. 03 Jan, 2021 1 commit
  7. 18 May, 2020 2 commits
  8. 17 May, 2020 1 commit
  9. 09 May, 2020 1 commit
  10. 08 May, 2020 1 commit
    • Adding option to skip loading models from subdirectories (#767) · 508d06a8
      ethanbresler authored
      Currently, the models annotator automatically attempts to find a class with a matching name at the bottom of project's directory tree before going up into specific engine's models.  This causes issues with models that share names with classes in other engines or lower classes in the project's directory.   This PR adds the option to skip attempts to load classes from lower directories and just uses the model's file path directly. 
      
      #674 
  11. 06 Apr, 2020 2 commits
  12. 05 Apr, 2020 5 commits
    • Add methods to AnnotateRoutes::HeaderGenerator and refactor methods (#792) · ce7f22df
      Shu Fujita authored
      cf. #790 
      
      In order to refactor `AnnoateRoutes`, I added methods to `AnnotateRoutes::HeaderGenerator` and refactor methods.
      
      I will add `AnnotateRoutes::AnnotationProcessor` and `AnnotateRoutes::RemovalProcessor` in next PR.
    • Fix output for multiline column comments (#779) · 214da4f6
      Troy Rosenberg authored
      Closes #778 
      
      If a column comment includes the newline character, the newline character
      would be "printed" into the annotation block resulting in a line break
      and an uncommented line.
      
      For example, for the following table:
      
      ```
      create_table "users", force: :cascade do |t|
        t.string "name", comment: "This is a comment.\nWith two lines!"
        t.datetime "created_at", precision: 6, null: false
        t.datetime "updated_at", precision: 6, null: false
      end
      ```
      
      annotating the model with the `--with-comment` flag will result in:
      
      ```
      \# == Schema Information
      \#
      \# Table name: users
      \#
      \#  id                                       :bigint           not null, primary key
      \#  name(This is a comment.
      With two lines!) :string
      \#  created_at                               :datetime         not null
      \#  updated_at                               :datetime         not null
      \#
      ```
      
      This uncommented line would result in invalid Ruby and cause the file to
      no longer be valid.
      
      This fix replaces the newline character with an escaped version, so the
      output will look more like:
      
      ```
      \# == Schema Information
      \#
      \# Table name: users
      \#
      \#  id                                       :bigint           not null, primary key
      \#  name(This is a comment.\nWith two lines!):string
      \#  created_at                               :datetime         not null
      \#  updated_at                               :datetime         not null
      \#
      ```
    • Reactors AnnotateModels.get_schema_info (#791) · da1e6052
      Troy Rosenberg authored
      This is a bit of a cheat of a refactoring that simply extracts the logic for collecting a column's attributes out of `get_schema_info` and into its own method (`get_attributes`).
      
      I found that in PRs like #779 that the Rubocop ABC limit was being exceeded:
      
      ```
      lib/annotate/annotate_models.rb:235:5: C: Metrics/AbcSize: Assignment Branch Condition size for get_schema_info is too high. [145/145]
          def get_schema_info(klass, header, options = {}) ...
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      ```
      
      Hopefully, this should break this up and reduce the complexity of the method.
      
      There are opportunities to go further, but I thought this could be a good place to start. 
      
      I would be open and interested in discussing further refactoring opportunities if it would make sense (maybe creating some new classes to encapsulate some of this logic). 
    • Refactor AnnotateRoutes by adding AnnotateRoutes::HeaderGenerator (#790) · d89ddefa
      Shu Fujita authored
      I noticed that `AnnotateRoutes` can be more maintainable by refactoring.
      
      I am planning to refactor `AnnotateRoutes` in this order.
      *   separate logic of `AnnotateRoutes` into `AnnotateRoutes::HeaderGenerator`.
      *   add methods to `AnnotateRoutes::HeaderGenerator` and refactor methods.
      *   add `AnnotateRoutes::AnnotationProcessor` and `AnnotateRoutes::RemovalProcessor`
      
      The final goal of this refactoring is as follows.
      * https://github.com/nard-tech/annotate_models/blob/feature/refactor_annotate_routes/processors/lib/annotate/annotate_routes.rb
      * https://github.com/nard-tech/annotate_models/tree/feature/refactor_annotate_routes/processors/lib/annotate/annotate_routes
      
      So in the first I added `AnnotateRoutes::HeaderGenerator` in order to separate logic of `AnnotateRoutes` in this PR.
      
      When refactor of `AnnotateRoutes` is finished, I would like to refactor `AnnotateModels` in a like way.
    • Fix "undefined method `<'" error message (#774) · d9392d9e
      Erik Kessler authored
      ## Problem
      
      I have some files in the "models" directory that are not true a `Class`. For example, a [`dry-types`](https://dry-rb.org/gems/dry-types/1.2/sum/) sum type:
      
      ```ruby
      # app/models/foo.rb
      Foo = Types::String | Types::Integer
      ```
      
      This results in the following line when I annotate.
      
      ```
      Unable to annotate app/models/foo.rb: undefined method `<' for #<Dry::Struct::Sum:0x00007ff2dd262988>
      ```
      
      Not a blocking issue but somewhat annoying nonetheless.
      
      ## Solution
      
      When annotating a file, check that the file's object is a `Class` to ensure it has the interface we expect.
  13. 09 Mar, 2020 1 commit
  14. 08 Mar, 2020 2 commits
  15. 22 Feb, 2020 1 commit
  16. 20 Feb, 2020 1 commit
  17. 17 Feb, 2020 1 commit
  18. 13 Feb, 2020 1 commit
  19. 27 Jan, 2020 2 commits
  20. 24 Jan, 2020 1 commit
    • Support YARD notation (#724) · 06255470
      tvallois authored
      The scope of this pull request is to allow annotate_models to generate models documentation using YARD. This is the first step, I'll add more features later.
  21. 22 Jan, 2020 1 commit
  22. 20 Jan, 2020 3 commits
    • Refactor AnnotateRoutes.rewrite_contents (#734) · d4948432
      Shu Fujita authored
      I moved `puts` from `AnnotateRoutes.rewrite_contents` to `.do_annotations` and `.remove_annotations`.
    • Remove AnnotateRoutes.rewrite_contents_with_header (#730) · db8b0999
      Shu Fujita authored
      I removed `AnnotateRoutes.rewrite_contents_with_header` because the logic of `AnnotateRoutes.rewrite_contents_with_header` is as same as `.rewrite_contents`.
    • Add columns managed by Globalize gem (#602) · d894fa29
      Peter Gundel authored
      * Add columns managed by Globalize gem
      
      Globalize hooks into the model and removes the translated columns
      from the `klass.columns`. This commit checks if globalize is
      hooked into the model and adds the necessary columns to the
      annotation array.
      
      * Disable Rubocop Metrics/BlockLength for spec files
      
      RSpec spec files can contain long blocks easily because
      of the outher describe methods. So this rule makes not too much
      sense for these files.
  23. 19 Jan, 2020 3 commits
  24. 18 Jan, 2020 2 commits
    • Refactor AnnotateModels::Helpers (#723) · 1c5deb09
      Shu Fujita authored
      I refactored two methods in AnnotateModels::Helpers for readability.
    • Refactor AnnotateRoutes.routes_file_exist? (#716) · 9a8db1b7
      Shu Fujita authored
      I refactored `AnnotateRoutes.routes_exists?` and methods using this.
      The points are as follows.
      
      *   Removing `puts` in `AnnotateRoutes.routes_exists?`
      *   Using `File.exist?` instead of `File.exists?` because `File.exists?` is deprecated
      *   Renaming `AnnotateRoutes.routes_exists?` to `AnnotateRoutes.routes_file_exists?` in order to make the name of method more explanatory
  25. 16 Jan, 2020 3 commits