Sha256: f42ad400e524b933b8f3781bff39c17f6514ef926bc0ac0159b27a72a16e880d

Contents?: true

Size: 1.23 KB

Versions: 2

Compression:

Stored size: 1.23 KB

Contents

# -*- encoding: utf-8 -*-

require 'git_shizzle/error'
require 'git_shizzle/dsl'
require 'git_shizzle/git'
require 'git_shizzle/index_specifications'

module GitShizzle

  class QuickGit
    def initialize(git = Git::Git.new(Dir.pwd))
      @git = git
      @commands = GitShizzle::Dsl::CommandCollection.new
      @commands.load
    end

    def run(command, *indexes)
      cmd = @commands.find command
      files = changes_for(indexes, cmd)

      cmd.invoke @git, files
    end

    def method_missing(sym, *args)
      run(sym, *args)
    end

    private
    def create_index_specification(indexes)
      specs = indexes.map { |index|
        case index
          when /\.\.\./
            IndexSpecifications::ExclusiveRange.new(index)
          when /\.\./
            IndexSpecifications::Range.new(index)
          when /\./
            IndexSpecifications::Everything.new
          else
            IndexSpecifications::File.new(index)
        end
      }

      IndexSpecifications::Combined.new specs
    end

    def changes_for(indexes, command)
      files = command.applicable_files(@git.status)

      spec = create_index_specification indexes
      spec.apply files
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
git_shizzle-0.2.8 lib/git_shizzle.rb
git_shizzle-0.2.6 lib/git_shizzle.rb