Skip to content

rename to annotate_rb #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
.gems
.rbenv-version
.ruby-*
.tool-versions
.idea/
/.rbx
/.rvmrc
Expand Down
10 changes: 5 additions & 5 deletions MIGRATION_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,17 @@ Additional options that work for annotating models and routes
### Passing options via Environment Variables
Annotate also reads options from ENV. For example, this command line argument `ANNOTATE_SKIP_ON_DB_MIGRATE=1 rake db:migrate` would affect Annotate's behavior.

The reading from ENV / environment variables has **been removed** in favor of reading configuration from `.annotaterb.yml` file in your Rails project root.
The reading from ENV / environment variables has **been removed** in favor of reading configuration from `.annotate_rb.yml` file in your Rails project root.

```yml
# .annotaterb.yml
# .annotate_rb.yml

position: after
```

This change was done to reduce complexity in configuration and make the gem easier to maintain.

**Note: `.annotaterb.yml` is optional.** In its, AnnotateRb will use command line arguments and then the defaults. The defaults are implemented in `AnnotateRb::Options`.
**Note: `.annotate_rb.yml` is optional.** In its, AnnotateRb will use command line arguments and then the defaults. The defaults are implemented in `AnnotateRb::Options`.

----------

Expand Down Expand Up @@ -116,8 +116,8 @@ $ bin/rails g annotate_rb:install

to install AnnotateRb's equivalent file into your Rails project.

#### Default .annotaterb.yml
When running the install generator command, `bin/rails g annotate_rb:install`, an `.annotaterb.yml` file gets automatically generated for your project using the defaults from the gem.
#### Default .annotate_rb.yml
When running the install generator command, `bin/rails g annotate_rb:install`, an `.annotate_rb.yml` file gets automatically generated for your project using the defaults from the gem.

It _should_ match the old Annotate defaults however there may be differences.

Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ $ bin/rails g annotate_rb:install

This will copy a rake task into your Rails project's `lib/tasks` directory that will hook into the Rails project rake tasks, automatically running AnnotateRb after database migration rake tasks.

To skip the automatic annotation that happens after a db task, pass the environment variable `ANNOTATERB_SKIP_ON_DB_TASKS=1` before your command.
To skip the automatic annotation that happens after a db task, pass the environment variable `ANNOTATE_RB_SKIP_ON_DB_TASKS=1` before your command.

```sh
$ ANNOTATERB_SKIP_ON_DB_TASKS=1 bin/rails db:migrate
$ ANNOTATE_RB_SKIP_ON_DB_TASKS=1 bin/rails db:migrate
```

### Added Rails generators
Expand All @@ -83,7 +83,7 @@ AnnotateRb:
```

`bin/rails g annotate_rb:config`
- Generates a new configuration file, `.annotaterb.yml`, using defaults from the gem.
- Generates a new configuration file, `.annotate_rb.yml`, using defaults from the gem.

`bin/rails g annotate_rb:hook`
- Installs the Rake file to automatically annotate Rails models on a database task (e.g. AnnotateRb will automatically run after running `bin/rails db:migrate`).
Expand All @@ -92,7 +92,7 @@ AnnotateRb:
- Runs the `config` and `hook` generator commands

`bin/rails g annotate_rb:update_config`
- Appends to `.annotaterb.yml` any configuration key-value pairs that are used by the Gem. This is useful when there's a drift between the config file values and the gem defaults (i.e. when new features get added).
- Appends to `.annotate_rb.yml` any configuration key-value pairs that are used by the Gem. This is useful when there's a drift between the config file values and the gem defaults (i.e. when new features get added).

## Migrating from the annotate gem
Refer to the [migration guide](MIGRATION_GUIDE.md).
Expand All @@ -103,7 +103,7 @@ AnnotateRb has a CLI that you can use to add or remove annotations.

```sh
# To show the CLI options
$ bundle exec annotaterb
$ bundle exec annotaterb

Usage: annotaterb [command] [options]

Expand Down Expand Up @@ -184,10 +184,10 @@ Additional options that work for annotating models and routes
## Configuration

### Storing default options
Previously in the [Annotate](https://github.com/ctran/annotate_models) you could pass options through the CLI or store them as environment variables. Annotaterb removes dependency on the environment variables and instead can read values from a `.annotaterb.yml` file stored in the Rails project root.
Previously in the [Annotate](https://github.com/ctran/annotate_models) you could pass options through the CLI or store them as environment variables. Annotaterb removes dependency on the environment variables and instead can read values from a `.annotate_rb.yml` file stored in the Rails project root.

```yml
# .annotaterb.yml
# .annotate_rb.yml

position: after
```
Expand Down
12 changes: 9 additions & 3 deletions lib/annotate_rb/config_finder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,25 @@

module AnnotateRb
class ConfigFinder
DOTFILE = ".annotaterb.yml"
DOTFILE = ".annotate_rb.yml"
LEGACY_DOTFILE = ".annotaterb.yml"

class << self
def find_project_root
# We should expect this method to be called from a Rails project root and returning it
# e.g. "/Users/drwl/personal/annotaterb/dummyapp"
# e.g. "/Users/drwl/personal/annotate_rb/dummyapp"
Dir.pwd
end

def find_project_dotfile
file_path = File.expand_path(DOTFILE, find_project_root)
legacy_file_path = File.expand_path(LEGACY_DOTFILE, find_project_root)

return file_path if File.exist?(file_path)
if File.exist?(file_path)
file_path
elsif File.exist?(legacy_file_path)
legacy_file_path
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def display_table_comments?

def name
if display_table_comments? && table_comment
formatted_comment = "(#{table_comment.gsub(/\n/, "\\n")})"
formatted_comment = "(#{table_comment.gsub("\n", "\\n")})"

"#{table_name}#{formatted_comment}"
else
Expand Down
2 changes: 1 addition & 1 deletion lib/annotate_rb/model_annotator/annotation_decider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def annotate?
klass_is_not_abstract = klass.respond_to?(:abstract_class?) && !klass.abstract_class?
klass_table_exists = klass.respond_to?(:table_exists?) && klass.table_exists?

not_sure_this_conditional = (!@options[:exclude_sti_subclasses] || !(klass.superclass < ActiveRecord::Base && klass.table_name == klass.superclass.table_name))
not_sure_this_conditional = !@options[:exclude_sti_subclasses] || !(klass.superclass < ActiveRecord::Base && klass.table_name == klass.superclass.table_name)

annotate_conditions = [
klass_is_a_class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def build

display_column_comments = @options[:with_comment] && @options[:with_column_comments]
col_name = if display_column_comments && @model.with_comments? && @column.comment
"#{@column.name}(#{@column.comment.gsub(/\n/, '\\n')})"
"#{@column.name}(#{@column.comment.gsub("\n", '\\n')})"
else
@column.name
end
Expand Down
4 changes: 2 additions & 2 deletions lib/annotate_rb/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -412,14 +412,14 @@ def add_options_to_parser(option_parser) # rubocop:disable Metrics/MethodLength
Array,
"Do not annotate fixtures, test files, factories, and/or serializers") do |exclusions|
exclusions ||= EXCLUSION_LIST
exclusions.each { |exclusion| @options["exclude_#{exclusion}".to_sym] = true }
exclusions.each { |exclusion| @options[:"exclude_#{exclusion}"] = true }
end

option_parser.on("-f",
"--format [bare|rdoc|yard|markdown]",
FORMAT_TYPES,
"Render Schema Information as plain/RDoc/Yard/Markdown") do |format_type|
@options["format_#{format_type}".to_sym] = true
@options[:"format_#{format_type}"] = true
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/annotate_rb/route_annotator/base_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,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?
Expand Down
2 changes: 1 addition & 1 deletion lib/annotate_rb/route_annotator/header_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def generate(options = {})
private

def routes_map(options)
result = `rails routes`.chomp("\n").split(/\n/, -1)
result = `rails 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
Expand Down
2 changes: 1 addition & 1 deletion lib/annotate_rb/route_annotator/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,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?
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/annotate_rb/config/USAGE
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Description:
Generates a default configuration file, `.annotaterb.yml` in your
Generates a default configuration file, `.annotate_rb.yml` in your
Rails app project root.

Example:
Expand Down
4 changes: 2 additions & 2 deletions lib/generators/annotate_rb/hook/templates/annotate_rb.rake
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This rake task was added by annotate_rb gem.

# Can set `ANNOTATERB_SKIP_ON_DB_TASKS` to be anything to skip this
if Rails.env.development? && ENV["ANNOTATERB_SKIP_ON_DB_TASKS"].nil?
# Can set `ANNOTATE_RB_SKIP_ON_DB_TASKS` to be anything to skip this
if Rails.env.development? && ENV["ANNOTATE_RB_SKIP_ON_DB_TASKS"].nil?
require "annotate_rb"

AnnotateRb::Core.load_rake_tasks
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/annotate_rb/update_config/USAGE
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Description:
Appends to .annotaterb.yml any missing default configuration
Appends to .annotate_rb.yml any missing default configuration
key-value pairs.

Example:
Expand Down
4 changes: 2 additions & 2 deletions spec/dummyapp/config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
development:
primary:
<<: *default
database: annotaterb_development
database: annotate_rb_development
<% end %>

<% if ENV['DATABASE_ADAPTER'] == 'pg' %>
Expand All @@ -25,7 +25,7 @@
development:
primary:
<<: *default
database: annotaterb_development
database: annotate_rb_development
<% end %>

<% if ENV['DATABASE_ADAPTER'] == 'sqlite3' %>
Expand Down
2 changes: 1 addition & 1 deletion spec/integration/rails_generator_install_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

let(:rake_task_file) { "lib/tasks/annotate_rb.rake" }
let(:rake_task) { File.join(aruba.config.root_directory, "lib/generators/annotate_rb/hook/templates/annotate_rb.rake") }
let(:config_file) { ".annotaterb.yml" }
let(:config_file) { ".annotate_rb.yml" }

let(:generator_install_command) { "bin/rails generate annotate_rb:install" }

Expand Down
2 changes: 1 addition & 1 deletion spec/integration/rails_generator_update_config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
RSpec.describe "Generator appends to config file", type: "aruba" do
let(:command_timeout_seconds) { 10 }

let(:config_file) { ".annotaterb.yml" }
let(:config_file) { ".annotate_rb.yml" }
let(:config_file_content) do
<<~YML.strip
---
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/annotate_rb/parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ module AnnotateRb # rubocop:disable Metrics/ModuleLength
describe option do
Parser::FORMAT_TYPES.each do |format_type|
context "when passing in format type '#{format_type}'" do
let(:format_key) { "format_#{format_type}".to_sym }
let(:format_key) { :"format_#{format_type}" }
let(:args) { [option, format_type] }

it "sets key for the format type to true" do
Expand Down
Loading