Class: TagMatic

Inherits:
Object
  • Object
show all
Defined in:
lib/tagmatic.rb

Constant Summary collapse

VERSION =
'0.0.3'
HASH_BANG =
'#!/bin/bash'
APP_DIRECTORIES =
%w/
  app
  config
  lib
  src
/
IGNORE_FILES =
%w/
  javascript
  sql
/
HOOKS_FILES =
%w/
  post-checkout
  post-merge
/
HOOK_TEMPLATE =
'tagmatic generate-tags .'
HELP =
'Run `tagmatic install` to setup the hooks that regenerate your "tags" file.'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*argv) ⇒ TagMatic

Returns a new instance of TagMatic.



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/tagmatic.rb', line 28

def initialize(*argv)
  command = argv.shift
  command = command.tr('-', '_') if command

  if command && respond_to?(command) && argv.any?
    send(command, argv)
  elsif command && respond_to?(command)
    send(command)
  else
    puts 'Command not found'
    help
  end
end

Instance Attribute Details

#current_dirObject

Returns the value of attribute current_dir.



26
27
28
# File 'lib/tagmatic.rb', line 26

def current_dir
  @current_dir
end

Instance Method Details

#__versionObject



70
71
72
# File 'lib/tagmatic.rb', line 70

def __version
  puts VERSION
end

#generate_tags(dir_path) ⇒ Object

Raises:

  • (ArgumentError)


53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/tagmatic.rb', line 53

def generate_tags(dir_path)
  raise ArgumentError.new('missing directory') if dir_path.empty?
  puts 'Regenerating tags...'
  self.current_dir = File.expand_path(dir_path.pop)
  remove_tags_file(dir_path)
  APP_DIRECTORIES.each do |path|
    result = `ctags -Ra #{ignore} #{path}` if File.exists?(path)
    unless $CHILD_STATUS.to_i == 0
      raise RuntimeError, result
    end
  end
end

#helpObject



66
67
68
# File 'lib/tagmatic.rb', line 66

def help
  puts HELP
end

#installObject



42
43
44
45
46
47
48
49
50
51
# File 'lib/tagmatic.rb', line 42

def install
  HOOKS_FILES.each do |file_name|
    append(File.join(git_dir, 'hooks', file_name), 0777) do |body, f|
      [HASH_BANG, HOOK_TEMPLATE].each do |text|
        f.puts(text) unless body && body.include?(text)
      end
    end
  end
  puts 'all tagged up'
end