Sha256: e9e8d548ecc2056c790bc55442f590c5656d90d7f223f0752cdd65bc15db496e

Contents?: true

Size: 1.1 KB

Versions: 22

Compression:

Stored size: 1.1 KB

Contents

# frozen_string_literal: true

require 'eac_ruby_utils/core_ext'

module Avm
  module Git
    class AutoCommitPath
      require_sub __FILE__, include_modules: true
      enable_console_speaker
      common_constructor :git, :path do
        self.path = path.to_pathname
      end

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

      def run
        banner
        commit
      end

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

      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

      def class_name
        ruby_class_name || relative_path.to_path
      end

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

      def relative_path
        path.relative_path_from(git.root_path)
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
avm-tools-0.93.0 lib/avm/git/auto_commit_path.rb
avm-tools-0.92.0 lib/avm/git/auto_commit_path.rb
avm-tools-0.91.0 lib/avm/git/auto_commit_path.rb
avm-tools-0.90.0 lib/avm/git/auto_commit_path.rb
avm-tools-0.89.0 lib/avm/git/auto_commit_path.rb
avm-tools-0.88.0 lib/avm/git/auto_commit_path.rb
avm-tools-0.87.1 lib/avm/git/auto_commit_path.rb
avm-tools-0.87.0 lib/avm/git/auto_commit_path.rb
avm-tools-0.86.0 lib/avm/git/auto_commit_path.rb
avm-tools-0.85.1 lib/avm/git/auto_commit_path.rb
avm-tools-0.85.0 lib/avm/git/auto_commit_path.rb
avm-tools-0.84.0 lib/avm/git/auto_commit_path.rb
avm-tools-0.83.0 lib/avm/git/auto_commit_path.rb
avm-tools-0.82.1 lib/avm/git/auto_commit_path.rb
avm-tools-0.82.0 lib/avm/git/auto_commit_path.rb
avm-tools-0.81.0 lib/avm/git/auto_commit_path.rb
avm-tools-0.80.0 lib/avm/git/auto_commit_path.rb
avm-tools-0.79.0 lib/avm/git/auto_commit_path.rb
avm-tools-0.78.0 lib/avm/git/auto_commit_path.rb
avm-tools-0.77.0 lib/avm/git/auto_commit_path.rb