tagrity 0.1.12 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 42e6594cf3699cc2f960b28ecb7d06b3ec2c75b8f39d9eb9d6296b6385bb5a52
4
- data.tar.gz: 7bf5d6fd08a760d9f2c99a7e3419dec5580f0bd040a680cb9081ace9922ea25a
3
+ metadata.gz: 20de67060444a9805be57457f42fbead18066cf3f65c7a51f6262328f86381c6
4
+ data.tar.gz: b342a4934b3d604f5fadc98d559a9863346d35e984641606fe6f3697a1829787
5
5
  SHA512:
6
- metadata.gz: b9d20591c5e50bd0d1e662511d1f51095bf91c862b2d1ba7bf38e5c6455a80bcbdcaab1b59831af4a6dcaee53fe74b6dfa04e9090b1a7d0cc9a2382c59b2fce2
7
- data.tar.gz: c8ac398b851e39503f9a68d8c8655dadadbddaff7d5ff82ff5843ec555ac52ec586d6be39f0456440187742f31fb53343ab1605b14c7f6a4a4426eded189caf6
6
+ metadata.gz: 227ecdbf6ea0faa4b24b5ec2b6238285ef1cb8c585e42abef2aa82baeaf6a1b65d403e34dd42aafff3acf1ac7eaeec798f87ec7c318e416f7b1acc897eeaf5ba
7
+ data.tar.gz: 16c33ed46225a24a24bd090661d88866c5a760ef5ee373e718f2ae93f97cbd221142e1634ddeb83362645c203ae9001c38e9e2161d9684addb48b92997f6ce64
@@ -0,0 +1,38 @@
1
+ # which command to use to generate tags for a specific file extension
2
+ # overrides default_command
3
+ # DEFAULT: empty
4
+ extension_commands:
5
+ rb: ripper-tags
6
+ c: ctags
7
+
8
+ # default command to generate tags
9
+ # DEFAULT: ctags
10
+ default_command: ctags
11
+
12
+ # filename (relative to pwd) to generate tags into
13
+ # DEFAULT: tags
14
+ tagf: tags
15
+
16
+ # list of extensions to exclusively generate tags for
17
+ # this will take precendence over extensions_blacklist if it is non-empty
18
+ # DEFAULT: []
19
+ extensions_whitelist: [rb]
20
+
21
+ # list of extensions to not generate tags for
22
+ # this can will be ignored if extensions_whitelist is non-empty
23
+ # DEFAULT: []
24
+ # extensions_blacklist: [erb, html, txt]
25
+
26
+ # how to integrate with git
27
+ # git_strategy: TRACKED | IGNORED | NA
28
+ # TRACKED: only index files tracked by git
29
+ # IGNORED: don't index files which are ignored by git
30
+ # NA: don't use git, index all files under pwd
31
+ # DEFAULT: TRACKED
32
+ git_strategy: TRACKED
33
+
34
+ # which paths (relative to pwd) to ignore
35
+ # It's usually better to avoid this since tagrity integrates with git by
36
+ # default using the strategy specified by git_strategy
37
+ # DEFAULT: []
38
+ excluded_paths: [test_files]
data/.travis.yml CHANGED
@@ -4,4 +4,9 @@ language: ruby
4
4
  cache: bundler
5
5
  rvm:
6
6
  - 2.6.3
7
- before_install: gem install bundler -v 2.0.2
7
+ before_install:
8
+ - gem install bundler -v 2.0.2
9
+ - gem install ripper-tags -v 0.8.1
10
+ - brew unlink python@2
11
+ - brew install --HEAD universal-ctags/universal-ctags/universal-ctags
12
+ os: osx
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- tagrity (0.1.11)
4
+ tagrity (0.2.0)
5
5
  cli-ui (~> 1.3.0)
6
6
  listen (~> 3.0)
7
7
  pry (~> 0.9.9)
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Tagrity
2
2
 
3
+ [![Build Status](https://travis-ci.com/RRethy/tagrity.svg?branch=master)](https://travis-ci.com/RRethy/tagrity)
4
+
3
5
  Automatically regenerate tags on file changes.
4
6
 
5
7
  ## Installation
@@ -38,7 +40,8 @@ Configuration can be done through use of a `tagrity_config.yml` file that looks
38
40
  # which command to use to generate tags for a specific file extension
39
41
  # overrides default_command
40
42
  # commands must support --append, -f, -L
41
- # DEFAULT: empty
43
+ #
44
+ # Default: empty
42
45
  extension_commands:
43
46
  rb: ripper-tags
44
47
  c: ctags
@@ -46,21 +49,25 @@ extension_commands:
46
49
 
47
50
  # default command to generate tags
48
51
  # command must support --append, -f, -L
49
- # DEFAULT: ctags
52
+ #
53
+ # Default: ctags
50
54
  default_command: ctags
51
55
 
52
56
  # filename (relative to pwd) to generate tags into
53
- # DEFAULT: tags
57
+ #
58
+ # Default: tags
54
59
  tagf: tags
55
60
 
56
61
  # list of extensions to exclusively generate tags for
57
62
  # this will take precendence over extensions_blacklist if it is non-empty
58
- # DEFAULT: []
63
+ #
64
+ # Default: []
59
65
  extensions_whitelist: [rb, c, h, js]
60
66
 
61
67
  # list of extensions to not generate tags for
62
68
  # this can will be ignored if extensions_whitelist is non-empty
63
- # DEFAULT: []
69
+ #
70
+ # Default: []
64
71
  extensions_blacklist: [erb, html, txt]
65
72
 
66
73
  # how to integrate with git
@@ -69,13 +76,14 @@ extensions_blacklist: [erb, html, txt]
69
76
  # IGNORED: don't index files which are ignored by git
70
77
  # NA: don't use git, index all files under pwd
71
78
  #
72
- # DEFAULT: TRACKED
79
+ # Default: TRACKED
73
80
  git_strategy: TRACKED
74
81
 
75
82
  # which paths (relative to pwd) to ignore
76
83
  # It's usually better to avoid this since tagrity integrates with git by
77
84
  # default using the strategy specified by git_strategy
78
- # DEFAULT: []
85
+ #
86
+ # Default: []
79
87
  excluded_paths: [vendor, node_modules]
80
88
  ```
81
89
 
@@ -12,18 +12,16 @@ module Tagrity
12
12
  LOCAL_CONFIG_PATH = File.expand_path("./.#{CONFIG_FNAME}")
13
13
  GLOBAL_CONFIG_PATH = File.expand_path("#{ENV['XDG_CONFIG_HOME'] || "#{ENV['HOME']}/.config"}/tagrity/#{CONFIG_FNAME}")
14
14
 
15
- def init
16
- ensure_extension_commands
17
- ensure_default_command
18
- ensure_tagf
19
- ensure_extensions_whitelist
20
- ensure_extensions_blacklist
21
- ensure_git_strategy
22
- ensure_excluded_paths
15
+ def reload_local
16
+ read_config(fname: local_config_path)
17
+ end
18
+
19
+ def reload_global
20
+ read_config(fname: global_config_path)
23
21
  end
24
22
 
25
23
  def command_for_extension(extension)
26
- cmd = extension_commands[extension]
24
+ cmd = extension_commands[extension.to_s]
27
25
  if cmd.nil?
28
26
  default_command
29
27
  else
@@ -33,14 +31,14 @@ module Tagrity
33
31
 
34
32
  def ignore_extension?(extension)
35
33
  unless extensions_whitelist.empty?
36
- return !extensions_whitelist.include?(extension)
34
+ return !extensions_whitelist.include?(extension.to_s)
37
35
  end
38
36
 
39
- extensions_blacklist.include?(extension)
37
+ extensions_blacklist.include?(extension.to_s)
40
38
  end
41
39
 
42
40
  def path_ignored?(path)
43
- excluded_paths.any? { |pat| /#{pat}/ =~ path }
41
+ excluded_paths.any? { |pat| !(/^#{pat}/ =~ path.to_s).nil? }
44
42
  end
45
43
 
46
44
  def respect_git?
@@ -81,6 +79,16 @@ module Tagrity
81
79
 
82
80
  private
83
81
 
82
+ def init
83
+ ensure_extension_commands
84
+ ensure_default_command
85
+ ensure_tagf
86
+ ensure_extensions_whitelist
87
+ ensure_extensions_blacklist
88
+ ensure_git_strategy
89
+ ensure_excluded_paths
90
+ end
91
+
84
92
  def ensure_extension_commands
85
93
  ensure_option('extension_commands', {})
86
94
  end
@@ -109,7 +117,7 @@ module Tagrity
109
117
  end
110
118
 
111
119
  def ensure_excluded_paths
112
- ensure_option('extension_commands', [])
120
+ ensure_option('excluded_paths', [])
113
121
  end
114
122
 
115
123
  def ensure_option(name, default)
@@ -122,14 +130,27 @@ module Tagrity
122
130
  @config ||= read_config
123
131
  end
124
132
 
125
- def read_config
126
- if File.readable?(LOCAL_CONFIG_PATH)
127
- @config = YAML.load_file(LOCAL_CONFIG_PATH)
128
- elsif File.readable?(GLOBAL_CONFIG_PATH)
129
- @config = YAML.load_file(GLOBAL_CONFIG_PATH)
133
+ def read_config(fname: nil)
134
+ @config = {}
135
+ if fname.nil?
136
+ if File.readable?(local_config_path)
137
+ read_config(fname: local_config_path)
138
+ elsif File.readable?(global_config_path)
139
+ read_config(fname: global_config_path)
140
+ end
130
141
  else
131
- @config = {}
142
+ @config = YAML.load_file(fname)
132
143
  end
144
+ init
145
+ @config
146
+ end
147
+
148
+ def global_config_path
149
+ File.expand_path("#{ENV['XDG_CONFIG_HOME'] || "#{ENV['HOME']}/.config"}/tagrity/#{CONFIG_FNAME}")
150
+ end
151
+
152
+ def local_config_path
153
+ File.expand_path("./.#{CONFIG_FNAME}")
133
154
  end
134
155
  end
135
156
  end
@@ -15,7 +15,7 @@ module Tagrity
15
15
  LOG_DIR
16
16
  end
17
17
 
18
- def is_executable?(cmd)
18
+ def executable?(cmd)
19
19
  !%x{command -v #{cmd}}.empty?
20
20
  end
21
21
 
@@ -32,7 +32,7 @@ module Tagrity
32
32
  true
33
33
  end
34
34
 
35
- def is_git_dir?
35
+ def git_dir?
36
36
  `git rev-parse --git-dir &> /dev/null`
37
37
  $?.exitstatus == 0
38
38
  end
@@ -24,7 +24,7 @@ module Tagrity
24
24
  pid = pid_from_path(path)
25
25
  pid_file_dir = File.read(path)
26
26
 
27
- if dir.nil? || is_same_dirs(pid_file_dir, dir)
27
+ if dir.nil? || same_dirs?(pid_file_dir, dir)
28
28
  if Helper.alive?(pid)
29
29
  pid_files << PidFile.new(pid_file_dir, pid)
30
30
  else
@@ -38,7 +38,7 @@ module Tagrity
38
38
 
39
39
  private
40
40
 
41
- def is_same_dirs(dir1, dir2)
41
+ def same_dirs?(dir1, dir2)
42
42
  File.realdirpath(dir1) == File.realdirpath(dir2)
43
43
  end
44
44
 
@@ -1,5 +1,6 @@
1
1
  require 'tagrity/config_file'
2
2
  require 'tagrity/tag_generator'
3
+ require 'tagrity/tlogger'
3
4
 
4
5
  module Tagrity
5
6
  class Provider
@@ -12,7 +13,7 @@ module Tagrity
12
13
  end
13
14
 
14
15
  def provide_tag_generator
15
- TagGenerator.new
16
+ TagGenerator.new(ConfigFile.instance, Tlogger.instance)
16
17
  end
17
18
  end
18
19
  end
@@ -2,15 +2,15 @@ require 'tmpdir'
2
2
  require 'tempfile'
3
3
  require 'fileutils'
4
4
  require 'tagrity/helper'
5
- require 'tagrity/tlogger'
5
+ require 'pry'
6
6
 
7
7
  module Tagrity
8
8
  class TagGenerator
9
9
  class ExecutableNonExist < StandardError; end
10
10
 
11
- def initialize
12
- assert_executables
13
- @config = ConfigFile.instance
11
+ def initialize(config, logger)
12
+ @config = config
13
+ @logger = logger
14
14
  end
15
15
 
16
16
  def generate_all
@@ -26,7 +26,7 @@ module Tagrity
26
26
  if $?.exitstatus == 0
27
27
  generate(files)
28
28
  else
29
- logger.error("Failed to get a listing of all files under pwd for use with --fresh. Used #{cmd}.")
29
+ @logger.error("Failed to get a listing of all files under pwd for use with --fresh. Used #{cmd}.")
30
30
  end
31
31
  end
32
32
 
@@ -40,9 +40,9 @@ module Tagrity
40
40
  IO::write(tmpf.path, fnames.join("\n"))
41
41
  system(cmd, '-f', tagf, '--append', '-L', tmpf.path, out: File::NULL)
42
42
  if $?.exitstatus == 0
43
- logger.info("{#{cmd}} generated tags for #{fnames} into #{tagf}")
43
+ @logger.info("{#{cmd}} generated tags for #{fnames} into #{tagf}")
44
44
  else
45
- logger.info("{#{cmd}} failed to generate tags for #{fnames} into #{tagf}")
45
+ @logger.info("{#{cmd}} failed to generate tags for #{fnames} into #{tagf}")
46
46
  end
47
47
  end
48
48
  end
@@ -60,7 +60,7 @@ module Tagrity
60
60
  end
61
61
  tmpf.rewind
62
62
  FileUtils.mv(tmpf.path, tagf, force: true)
63
- logger.info("Deleted tags for #{files} from #{tagf}")
63
+ @logger.info("Deleted tags for #{files} from #{tagf}")
64
64
  end
65
65
  end
66
66
 
@@ -71,7 +71,7 @@ module Tagrity
71
71
  end
72
72
 
73
73
  def indexable?(file)
74
- file != tagf && !is_file_excluded(file) && File.readable?(file)
74
+ file != tagf && !file_excluded?(file) && File.readable?(file)
75
75
  end
76
76
 
77
77
  def copacetic_with_git?(file)
@@ -87,27 +87,15 @@ module Tagrity
87
87
  end
88
88
 
89
89
  def check_git?
90
- @config.respect_git? && Helper.is_git_dir?
90
+ @check_git ||= @config.respect_git? && Helper.git_dir?
91
91
  end
92
92
 
93
- def is_file_excluded(fname)
93
+ def file_excluded?(fname)
94
94
  @config.ignore_extension?(fname.partition('.').last) || @config.path_ignored?(fname)
95
95
  end
96
96
 
97
- def assert_executables
98
- %w(cat grep mv).each do |exe|
99
- if !Helper.is_executable?(exe)
100
- raise ExecutableNonExist, "tagrity depends on the executable #{exe}"
101
- end
102
- end
103
- end
104
-
105
97
  def tagf
106
98
  @config.tagf
107
99
  end
108
-
109
- def logger
110
- Tlogger.instance
111
- end
112
100
  end
113
101
  end
@@ -1,3 +1,3 @@
1
1
  module Tagrity
2
- VERSION = "0.1.12"
2
+ VERSION = "0.2.0"
3
3
  end
data/sample_config.yml CHANGED
@@ -1,7 +1,8 @@
1
1
  # which command to use to generate tags for a specific file extension
2
2
  # overrides default_command
3
3
  # commands must support --append, -f, -L
4
- # DEFAULT: empty
4
+ #
5
+ # Default: empty
5
6
  extension_commands:
6
7
  rb: ripper-tags
7
8
  c: ctags
@@ -9,21 +10,25 @@ extension_commands:
9
10
 
10
11
  # default command to generate tags
11
12
  # command must support --append, -f, -L
12
- # DEFAULT: ctags
13
+ #
14
+ # Default: ctags
13
15
  default_command: ctags
14
16
 
15
17
  # filename (relative to pwd) to generate tags into
16
- # DEFAULT: tags
18
+ #
19
+ # Default: tags
17
20
  tagf: tags
18
21
 
19
22
  # list of extensions to exclusively generate tags for
20
23
  # this will take precendence over extensions_blacklist if it is non-empty
21
- # DEFAULT: []
24
+ #
25
+ # Default: []
22
26
  extensions_whitelist: [rb, c, h, js]
23
27
 
24
28
  # list of extensions to not generate tags for
25
29
  # this can will be ignored if extensions_whitelist is non-empty
26
- # DEFAULT: []
30
+ #
31
+ # Default: []
27
32
  extensions_blacklist: [erb, html, txt]
28
33
 
29
34
  # how to integrate with git
@@ -32,11 +37,12 @@ extensions_blacklist: [erb, html, txt]
32
37
  # IGNORED: don't index files which are ignored by git
33
38
  # NA: don't use git, index all files under pwd
34
39
  #
35
- # DEFAULT: TRACKED
40
+ # Default: TRACKED
36
41
  git_strategy: TRACKED
37
42
 
38
43
  # which paths (relative to pwd) to ignore
39
44
  # It's usually better to avoid this since tagrity integrates with git by
40
45
  # default using the strategy specified by git_strategy
41
- # DEFAULT: []
46
+ #
47
+ # Default: []
42
48
  excluded_paths: [vendor, node_modules]
@@ -0,0 +1 @@
1
+ foobar.rb
@@ -0,0 +1,37 @@
1
+ # which command to use to generate tags for a specific file extension
2
+ # overrides default_command
3
+ # DEFAULT: empty
4
+ extension_commands:
5
+ rb: ripper-tags
6
+
7
+ # default command to generate tags
8
+ # DEFAULT: ctags
9
+ default_command: ctags
10
+
11
+ # filename (relative to pwd) to generate tags into
12
+ # DEFAULT: tags
13
+ tagf: tags
14
+
15
+ # list of extensions to exclusively generate tags for
16
+ # this will take precendence over extensions_blacklist if it is non-empty
17
+ # DEFAULT: []
18
+ extensions_whitelist: [rb, c, vim]
19
+
20
+ # list of extensions to not generate tags for
21
+ # this can will be ignored if extensions_whitelist is non-empty
22
+ # DEFAULT: []
23
+ # extensions_blacklist: [erb, html, txt]
24
+
25
+ # how to integrate with git
26
+ # git_strategy: TRACKED | IGNORED | NA
27
+ # TRACKED: only index files tracked by git
28
+ # IGNORED: don't index files which are ignored by git
29
+ # NA: don't use git, index all files under pwd
30
+ # DEFAULT: TRACKED
31
+ git_strategy: IGNORED
32
+
33
+ # which paths (relative to pwd) to ignore
34
+ # It's usually better to avoid this since tagrity integrates with git by
35
+ # default using the strategy specified by git_strategy
36
+ # DEFAULT: []
37
+ excluded_paths: [vendor, node_modules]
@@ -0,0 +1,7 @@
1
+ int barbaz_one() {
2
+ return 0;
3
+ }
4
+
5
+ int barbaz_two() {
6
+ return 0;
7
+ }
@@ -0,0 +1,6 @@
1
+ barbaz_fun_one foo/barbaz.rb /^def barbaz_fun_one$/;" f class:Object
2
+ barbaz_fun_two foo/barbaz.rb /^def barbaz_fun_two$/;" f class:Object
3
+ barbaz_one barbaz.c /^int barbaz_one() {$/;" f typeref:typename:int
4
+ barbaz_two barbaz.c /^int barbaz_two() {$/;" f typeref:typename:int
5
+ foobar_fun_one foo/foobar.rb /^def foobar_fun_one$/;" f class:Object
6
+ foobar_fun_two foo/foobar.rb /^def foobar_fun_two$/;" f class:Object
@@ -0,0 +1,6 @@
1
+ barbaz_fun_one foo/barbaz.rb /^def barbaz_fun_one$/;" f class:Object
2
+ barbaz_fun_two foo/barbaz.rb /^def barbaz_fun_two$/;" f class:Object
3
+ barbaz_one barbaz.c /^int barbaz_one() {$/;" f typeref:typename:int
4
+ barbaz_one foo/foobar.c /^int barbaz_one() {$/;" f typeref:typename:int
5
+ barbaz_two barbaz.c /^int barbaz_two() {$/;" f typeref:typename:int
6
+ barbaz_two foo/foobar.c /^int barbaz_two() {$/;" f typeref:typename:int
@@ -0,0 +1,10 @@
1
+ barbaz_fun_one foo/barbaz.rb /^def barbaz_fun_one$/;" f class:Object
2
+ barbaz_fun_two foo/barbaz.rb /^def barbaz_fun_two$/;" f class:Object
3
+ barbaz_one barbaz.c /^int barbaz_one() {$/;" f typeref:typename:int
4
+ barbaz_one foo/foobar.c /^int barbaz_one() {$/;" f typeref:typename:int
5
+ barbaz_two barbaz.c /^int barbaz_two() {$/;" f typeref:typename:int
6
+ barbaz_two foo/foobar.c /^int barbaz_two() {$/;" f typeref:typename:int
7
+ foobar_fun_one foo/foobar.rb /^def foobar_fun_one$/;" f class:Object
8
+ foobar_fun_one foobar.rb /^def foobar_fun_one$/;" f class:Object
9
+ foobar_fun_two foo/foobar.rb /^def foobar_fun_two$/;" f class:Object
10
+ foobar_fun_two foobar.rb /^def foobar_fun_two$/;" f class:Object
@@ -0,0 +1,5 @@
1
+ def barbaz_fun_one
2
+ end
3
+
4
+ def barbaz_fun_two
5
+ end
@@ -0,0 +1,7 @@
1
+ int barbaz_one() {
2
+ return 0;
3
+ }
4
+
5
+ int barbaz_two() {
6
+ return 0;
7
+ }
@@ -0,0 +1,5 @@
1
+ def foobar_fun_one
2
+ end
3
+
4
+ def foobar_fun_two
5
+ end
@@ -0,0 +1,5 @@
1
+ def foobar_fun_one
2
+ end
3
+
4
+ def foobar_fun_two
5
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tagrity
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.12
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam P. Regasz-Rethy
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-12-25 00:00:00.000000000 Z
11
+ date: 2020-01-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -132,6 +132,7 @@ extra_rdoc_files: []
132
132
  files:
133
133
  - ".gitignore"
134
134
  - ".rspec"
135
+ - ".tagrity_config.yml"
135
136
  - ".travis.yml"
136
137
  - CODE_OF_CONDUCT.md
137
138
  - Gemfile
@@ -157,6 +158,16 @@ files:
157
158
  - lib/tagrity/version.rb
158
159
  - sample_config.yml
159
160
  - tagrity.gemspec
161
+ - test_files/.gitignore
162
+ - test_files/.tagrity_config.yml
163
+ - test_files/barbaz.c
164
+ - test_files/expected_after_delete
165
+ - test_files/expected_genall_git_tags
166
+ - test_files/expected_genall_nongit_tags
167
+ - test_files/foo/barbaz.rb
168
+ - test_files/foo/foobar.c
169
+ - test_files/foo/foobar.rb
170
+ - test_files/foobar.rb
160
171
  homepage: https://github.com/RRethy/tagrity
161
172
  licenses:
162
173
  - MIT