annotate 2.7.1 → 2.7.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -18,33 +18,61 @@
18
18
  # Released under the same license as Ruby. No Support. No Warranty.
19
19
  #
20
20
  module AnnotateRoutes
21
- PREFIX = '# == Route Map'
21
+ PREFIX = '== Route Map'.freeze
22
+ PREFIX_MD = '## Route Map'.freeze
23
+ HEADER_ROW = ['Prefix', 'Verb', 'URI Pattern', 'Controller#Action']
22
24
 
23
- def self.do_annotations(options={})
24
- return unless routes_exists?
25
+ class << self
26
+ def content(line, maxs, options = {})
27
+ return line.rstrip unless options[:format_markdown]
25
28
 
26
- routes_map = AnnotateRoutes.app_routes_map(options)
29
+ line.each_with_index.map do |elem, index|
30
+ min_length = maxs.map { |arr| arr[index] }.max || 0
27
31
 
28
- header = [
29
- "#{PREFIX}" + (options[:timestamp] ? " (Updated #{Time.now.strftime('%Y-%m-%d %H:%M')})" : ''), '#'
30
- ] + routes_map.map { |line| "# #{line}".rstrip }
32
+ sprintf("%-#{min_length}.#{min_length}s", elem.tr('|', '-'))
33
+ end.join(' | ')
34
+ end
35
+
36
+ def header(options = {})
37
+ routes_map = app_routes_map(options)
38
+
39
+ out = ["# #{options[:format_markdown] ? PREFIX_MD : PREFIX}" + (options[:timestamp] ? " (Updated #{Time.now.strftime('%Y-%m-%d %H:%M')})" : '')]
40
+ out += ['#']
41
+ return out if routes_map.size.zero?
42
+
43
+ maxs = [HEADER_ROW.map(&:size)] + routes_map[1..-1].map { |line| line.split.map(&:size) }
31
44
 
32
- existing_text = File.read(routes_file)
45
+ if options[:format_markdown]
46
+ max = maxs.map(&:max).compact.max
33
47
 
34
- if write_contents(existing_text, header, options)
35
- puts "#{routes_file} annotated."
48
+ out += ["# #{content(HEADER_ROW, maxs, options)}"]
49
+ out += ["# #{content(['-' * max, '-' * max, '-' * max, '-' * max], maxs, options)}"]
50
+ else
51
+ out += ["# #{content(routes_map[0], maxs, options)}"]
52
+ end
53
+
54
+ out + routes_map[1..-1].map { |line| "# #{content(options[:format_markdown] ? line.split(' ') : line, maxs, options)}" }
36
55
  end
37
- end
38
56
 
39
- def self.remove_annotations(options={})
40
- return unless routes_exists?
41
- existing_text = File.read(routes_file)
42
- content, where_header_found = strip_annotations(existing_text)
57
+ def do_annotations(options = {})
58
+ return unless routes_exists?
59
+ existing_text = File.read(routes_file)
60
+
61
+ if write_contents(existing_text, header(options), options)
62
+ puts "#{routes_file} annotated."
63
+ end
64
+ end
65
+
66
+ def remove_annotations(options={})
67
+ return unless routes_exists?
68
+ existing_text = File.read(routes_file)
69
+ content, where_header_found = strip_annotations(existing_text)
43
70
 
44
- content = strip_on_removal(content, where_header_found)
71
+ content = strip_on_removal(content, where_header_found)
45
72
 
46
- if write_contents(existing_text, content, options)
47
- puts "Removed annotations from #{routes_file}."
73
+ if write_contents(existing_text, content, options)
74
+ puts "Removed annotations from #{routes_file}."
75
+ end
48
76
  end
49
77
  end
50
78
 
@@ -1,5 +1,5 @@
1
1
  module Annotate
2
2
  def self.version
3
- '2.7.1'
3
+ '2.7.2'
4
4
  end
5
5
  end
@@ -2,45 +2,50 @@
2
2
  # NOTE: are sensitive to local FS writes, and besides -- it's just not proper
3
3
  # NOTE: to have a dev-mode tool do its thing in production.
4
4
  if Rails.env.development?
5
+ require 'annotate'
5
6
  task :set_annotation_options do
6
7
  # You can override any of these by setting an environment variable of the
7
8
  # same name.
8
9
  Annotate.set_defaults(
9
- 'routes' => 'false',
10
- 'position_in_routes' => 'before',
11
- 'position_in_class' => 'before',
12
- 'position_in_test' => 'before',
13
- 'position_in_fixture' => 'before',
14
- 'position_in_factory' => 'before',
15
- 'position_in_serializer' => 'before',
16
- 'show_foreign_keys' => 'true',
17
- 'show_indexes' => 'true',
18
- 'simple_indexes' => 'false',
19
- 'model_dir' => 'app/models',
20
- 'root_dir' => '',
21
- 'include_version' => 'false',
22
- 'require' => '',
23
- 'exclude_tests' => 'false',
24
- 'exclude_fixtures' => 'false',
25
- 'exclude_factories' => 'false',
26
- 'exclude_serializers' => 'false',
27
- 'exclude_scaffolds' => 'true',
28
- 'exclude_controllers' => 'true',
29
- 'exclude_helpers' => 'true',
30
- 'ignore_model_sub_dir' => 'false',
31
- 'ignore_columns' => nil,
32
- 'ignore_routes' => nil,
33
- 'ignore_unknown_models' => 'false',
34
- 'hide_limit_column_types' => '<%= AnnotateModels::NO_LIMIT_COL_TYPES.join(",") %>',
35
- 'skip_on_db_migrate' => 'false',
36
- 'format_bare' => 'true',
37
- 'format_rdoc' => 'false',
38
- 'format_markdown' => 'false',
39
- 'sort' => 'false',
40
- 'force' => 'false',
41
- 'trace' => 'false',
42
- 'wrapper_open' => nil,
43
- 'wrapper_close' => nil
10
+ 'routes' => 'false',
11
+ 'position_in_routes' => 'before',
12
+ 'position_in_class' => 'before',
13
+ 'position_in_test' => 'before',
14
+ 'position_in_fixture' => 'before',
15
+ 'position_in_factory' => 'before',
16
+ 'position_in_serializer' => 'before',
17
+ 'show_foreign_keys' => 'true',
18
+ 'show_complete_foreign_keys' => 'false',
19
+ 'show_indexes' => 'true',
20
+ 'simple_indexes' => 'false',
21
+ 'model_dir' => 'app/models',
22
+ 'root_dir' => '',
23
+ 'include_version' => 'false',
24
+ 'require' => '',
25
+ 'exclude_tests' => 'false',
26
+ 'exclude_fixtures' => 'false',
27
+ 'exclude_factories' => 'false',
28
+ 'exclude_serializers' => 'false',
29
+ 'exclude_scaffolds' => 'true',
30
+ 'exclude_controllers' => 'true',
31
+ 'exclude_helpers' => 'true',
32
+ 'exclude_sti_subclasses' => 'false',
33
+ 'ignore_model_sub_dir' => 'false',
34
+ 'ignore_columns' => nil,
35
+ 'ignore_routes' => nil,
36
+ 'ignore_unknown_models' => 'false',
37
+ 'hide_limit_column_types' => '<%= AnnotateModels::NO_LIMIT_COL_TYPES.join(",") %>',
38
+ 'hide_default_column_types' => '<%= AnnotateModels::NO_DEFAULT_COL_TYPES.join(",") %>',
39
+ 'skip_on_db_migrate' => 'false',
40
+ 'format_bare' => 'true',
41
+ 'format_rdoc' => 'false',
42
+ 'format_markdown' => 'false',
43
+ 'sort' => 'false',
44
+ 'force' => 'false',
45
+ 'trace' => 'false',
46
+ 'wrapper_open' => nil,
47
+ 'wrapper_close' => nil,
48
+ 'with_comment' => true
44
49
  )
45
50
  end
46
51
 
@@ -10,7 +10,7 @@ task annotate_models: :environment do
10
10
  require "#{annotate_lib}/annotate/annotate_models"
11
11
  require "#{annotate_lib}/annotate/active_record_patch"
12
12
 
13
- options={is_rake: true}
13
+ options = {is_rake: true}
14
14
  ENV['position'] = options[:position] = Annotate.fallback(ENV['position'], 'before')
15
15
  options[:position_in_class] = Annotate.fallback(ENV['position_in_class'], ENV['position'])
16
16
  options[:position_in_fixture] = Annotate.fallback(ENV['position_in_fixture'], ENV['position'])
@@ -18,10 +18,11 @@ task annotate_models: :environment do
18
18
  options[:position_in_test] = Annotate.fallback(ENV['position_in_test'], ENV['position'])
19
19
  options[:position_in_serializer] = Annotate.fallback(ENV['position_in_serializer'], ENV['position'])
20
20
  options[:show_foreign_keys] = Annotate.true?(ENV['show_foreign_keys'])
21
+ options[:show_complete_foreign_keys] = Annotate.true?(ENV['show_complete_foreign_keys'])
21
22
  options[:show_indexes] = Annotate.true?(ENV['show_indexes'])
22
23
  options[:simple_indexes] = Annotate.true?(ENV['simple_indexes'])
23
24
  options[:model_dir] = ENV['model_dir'] ? ENV['model_dir'].split(',') : ['app/models']
24
- options[:root_dir] = ENV['root_dir'] ? ENV['root_dir'].split(',') : ['']
25
+ options[:root_dir] = ENV['root_dir']
25
26
  options[:include_version] = Annotate.true?(ENV['include_version'])
26
27
  options[:require] = ENV['require'] ? ENV['require'].split(',') : []
27
28
  options[:exclude_tests] = Annotate.true?(ENV['exclude_tests'])
@@ -31,6 +32,7 @@ task annotate_models: :environment do
31
32
  options[:exclude_scaffolds] = Annotate.true?(ENV['exclude_scaffolds'])
32
33
  options[:exclude_controllers] = Annotate.true?(ENV.fetch('exclude_controllers', 'true'))
33
34
  options[:exclude_helpers] = Annotate.true?(ENV.fetch('exclude_helpers', 'true'))
35
+ options[:exclude_sti_subclasses] = Annotate.true?(ENV['exclude_sti_subclasses'])
34
36
  options[:ignore_model_sub_dir] = Annotate.true?(ENV['ignore_model_sub_dir'])
35
37
  options[:format_bare] = Annotate.true?(ENV['format_bare'])
36
38
  options[:format_rdoc] = Annotate.true?(ENV['format_rdoc'])
@@ -44,6 +46,7 @@ task annotate_models: :environment do
44
46
  options[:ignore_columns] = ENV.fetch('ignore_columns', nil)
45
47
  options[:ignore_routes] = ENV.fetch('ignore_routes', nil)
46
48
  options[:hide_limit_column_types] = Annotate.fallback(ENV['hide_limit_column_types'], '')
49
+ options[:hide_default_column_types] = Annotate.fallback(ENV['hide_default_column_types'], '')
47
50
 
48
51
  AnnotateModels.do_annotations(options)
49
52
  end
@@ -53,7 +56,7 @@ task remove_annotation: :environment do
53
56
  require "#{annotate_lib}/annotate/annotate_models"
54
57
  require "#{annotate_lib}/annotate/active_record_patch"
55
58
 
56
- options={is_rake: true}
59
+ options = {is_rake: true}
57
60
  options[:model_dir] = ENV['model_dir']
58
61
  options[:root_dir] = ENV['root_dir']
59
62
  options[:require] = ENV['require'] ? ENV['require'].split(',') : []
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: annotate
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.7.1
4
+ version: 2.7.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Chaffee
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2016-05-09 00:00:00.000000000 Z
15
+ date: 2017-06-02 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: rake
@@ -23,7 +23,7 @@ dependencies:
23
23
  version: '10.4'
24
24
  - - "<"
25
25
  - !ruby/object:Gem::Version
26
- version: '12.0'
26
+ version: '13.0'
27
27
  type: :runtime
28
28
  prerelease: false
29
29
  version_requirements: !ruby/object:Gem::Requirement
@@ -33,7 +33,7 @@ dependencies:
33
33
  version: '10.4'
34
34
  - - "<"
35
35
  - !ruby/object:Gem::Version
36
- version: '12.0'
36
+ version: '13.0'
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: activerecord
39
39
  requirement: !ruby/object:Gem::Requirement
@@ -87,8 +87,8 @@ files:
87
87
  - lib/generators/annotate/install_generator.rb
88
88
  - lib/generators/annotate/templates/auto_annotate_models.rake
89
89
  - lib/tasks/annotate_models.rake
90
+ - lib/tasks/annotate_models_migrate.rake
90
91
  - lib/tasks/annotate_routes.rake
91
- - lib/tasks/migrate.rake
92
92
  homepage: http://github.com/ctran/annotate_models
93
93
  licenses:
94
94
  - Ruby
@@ -109,10 +109,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
109
109
  version: '0'
110
110
  requirements: []
111
111
  rubyforge_project: annotate
112
- rubygems_version: 2.5.1
112
+ rubygems_version: 2.6.8
113
113
  signing_key:
114
114
  specification_version: 4
115
115
  summary: Annotates Rails Models, routes, fixtures, and others based on the database
116
116
  schema.
117
117
  test_files: []
118
- has_rdoc: