-
Notifications
You must be signed in to change notification settings - Fork 609
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
Refactor lib/annotate.rb #707
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
72f3ac6
Copy skip_on_migration?, include_routes?, and include_models? methods
drwl 7a463d2
Make methods point to Helpers class methods
drwl d880737
Rerun `rubocop --auto-gen-config`
drwl d7c290b
Replace usages of methods to point to Helpers class instead
drwl bd5564b
Remove redundant methods from Annotate
drwl 048b7dc
Copy .true? to Annotate::Helpers
drwl 91708a8
Redirect usages of .true? to refer to Helpers.true?
drwl c6ea1ff
Copy .fallback to Helpers
drwl 73f9aa1
Changes usages of .fallback to use Helpers.fallback instead
drwl 6c1271b
Copy .reset_options into Helpers
drwl d2b0a55
Move options constants into Constants module
drwl ef39676
Add Constants to spec_helper
drwl cdf40c3
Remove .all_options from lib/annotate.rb
drwl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,38 @@ | ||
module Annotate | ||
module Constants | ||
TRUE_RE = /^(true|t|yes|y|1)$/i.freeze | ||
|
||
## | ||
# The set of available options to customize the behavior of Annotate. | ||
# | ||
POSITION_OPTIONS = [ | ||
:position_in_routes, :position_in_class, :position_in_test, | ||
:position_in_fixture, :position_in_factory, :position, | ||
:position_in_serializer | ||
].freeze | ||
|
||
FLAG_OPTIONS = [ | ||
:show_indexes, :simple_indexes, :include_version, :exclude_tests, | ||
:exclude_fixtures, :exclude_factories, :ignore_model_sub_dir, | ||
:format_bare, :format_rdoc, :format_markdown, :sort, :force, :frozen, | ||
:trace, :timestamp, :exclude_serializers, :classified_sort, | ||
:show_foreign_keys, :show_complete_foreign_keys, | ||
:exclude_scaffolds, :exclude_controllers, :exclude_helpers, | ||
:exclude_sti_subclasses, :ignore_unknown_models, :with_comment | ||
].freeze | ||
|
||
OTHER_OPTIONS = [ | ||
:additional_file_patterns, :ignore_columns, :skip_on_db_migrate, :wrapper_open, :wrapper_close, | ||
:wrapper, :routes, :models, :hide_limit_column_types, :hide_default_column_types, | ||
:ignore_routes, :active_admin | ||
].freeze | ||
|
||
PATH_OPTIONS = [ | ||
:require, :model_dir, :root_dir | ||
].freeze | ||
|
||
ALL_ANNOTATE_OPTIONS = [ | ||
POSITION_OPTIONS, FLAG_OPTIONS, OTHER_OPTIONS, PATH_OPTIONS | ||
].freeze | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
module Annotate | ||
# Class for holding helper methods. Done to make lib/annotate.rb less bloated. | ||
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 | ||
end | ||
|
||
def include_routes? | ||
ENV['routes'] =~ Constants::TRUE_RE | ||
end | ||
|
||
def include_models? | ||
ENV['models'] =~ Constants::TRUE_RE | ||
end | ||
|
||
def true?(val) | ||
return false if val.blank? | ||
return false unless val =~ Constants::TRUE_RE | ||
|
||
true | ||
end | ||
|
||
def fallback(*args) | ||
args.detect { |arg| !arg.blank? } | ||
end | ||
|
||
def reset_options(options) | ||
options.flatten.each { |key| ENV[key.to_s] = nil } | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be mixed in instead of specifying full path? It would also cut back the number of changes needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ctran this is done intentionally for now to make it easier to see where everything is coming from. Do you think it would be okay to keep for now?
I'm thinking we could untangle
lib/annotate.rb
. I'm looking at the Pry gem as a source of inspiration.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine either way, was just wondering if you had specific reasons to do that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to make it more explicit where it's coming from right now. I'm expecting
Helpers
to be a temporary solution until it's clearer what the different pieces are.