forked from ctran/annotate_models
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor lib/annotate.rb (ctran#707)
This change converts .all_options into a constant and moves it into Annotate::Constants. It also changes usages of .all_options.
- Loading branch information
Showing
11 changed files
with
281 additions
and
150 deletions.
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.