Sha256: 9001882c9daaae92069c551c8d1ccb7099ed09eeedd565f34a0748b223692f30

Contents?: true

Size: 1.2 KB

Versions: 9

Compression:

Stored size: 1.2 KB

Contents

# frozen_string_literal: true

require 'eac_ruby_utils/core_ext'

module Avm
  module Git
    class AutoCommitPath
      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
        CLASS_NAME_PATTERNS.each do |pattern|
          pattern.if_match(relative_path.to_path, false) { |m| return m[1].camelize }
        end
        raise "No pattern matched \"#{relative_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

9 entries across 9 versions & 1 rubygems

Version Path
avm-tools-0.75.1 lib/avm/git/auto_commit_path.rb
avm-tools-0.75.0 lib/avm/git/auto_commit_path.rb
avm-tools-0.74.1 lib/avm/git/auto_commit_path.rb
avm-tools-0.74.0 lib/avm/git/auto_commit_path.rb
avm-tools-0.73.0 lib/avm/git/auto_commit_path.rb
avm-tools-0.72.0 lib/avm/git/auto_commit_path.rb
avm-tools-0.71.0 lib/avm/git/auto_commit_path.rb
avm-tools-0.70.2 lib/avm/git/auto_commit_path.rb
avm-tools-0.70.1 lib/avm/git/auto_commit_path.rb