Class: Avm::Git::AutoCommitPath

Inherits:
Object
  • Object
show all
Defined in:
lib/avm/git/auto_commit_path.rb,
lib/avm/git/auto_commit_path/ruby.rb

Defined Under Namespace

Modules: Ruby

Constant Summary collapse

CLASS_NAME_PATTERNS =
[%r{lib/((?!.*/lib/).+)\.rb\z}, %r{app/[^/]+/(.+)\.rb\z}].freeze

Instance Method Summary collapse

Instance Method Details



21
22
23
24
25
# File 'lib/avm/git/auto_commit_path.rb', line 21

def banner
  infom "Checking \"#{relative_path}\""
  infov '  * Class name', class_name
  infov '  * Commit message', commit_message
end

#class_nameObject



34
35
36
# File 'lib/avm/git/auto_commit_path.rb', line 34

def class_name
  ruby_class_name || relative_path.to_path
end

#commitObject



27
28
29
30
31
32
# File 'lib/avm/git/auto_commit_path.rb', line 27

def commit
  infom '  * Commiting...'
  git.system!('reset', 'HEAD')
  git.system!('add', '--', relative_path.to_path)
  git.system!('commit', '-m', commit_message, '--', relative_path.to_path)
end

#commit_messageObject



38
39
40
41
42
# File 'lib/avm/git/auto_commit_path.rb', line 38

def commit_message
  r = class_name
  r += ': remove' unless path.file?
  r + '.'
end

#relative_pathObject



44
45
46
# File 'lib/avm/git/auto_commit_path.rb', line 44

def relative_path
  path.relative_path_from(git.root_path)
end

#runObject



16
17
18
19
# File 'lib/avm/git/auto_commit_path.rb', line 16

def run
  banner
  commit
end