Class: GitSmart

Inherits:
Object show all
Defined in:
lib/git-smart.rb,
lib/git-smart/git_smart.rb,
lib/git-smart/exceptions.rb

Defined Under Namespace

Classes: Exception, RunFailed, UnexpectedOutput

Class Method Summary collapse

Class Method Details

.commandsObject



25
26
27
# File 'lib/git-smart/git_smart.rb', line 25

def self.commands
  @commands ||= {}
end

.register(code, &blk) ⇒ Object

Used like this: GitSmart.register ‘my-command’ do |repo, args|



19
20
21
22
23
# File 'lib/git-smart/git_smart.rb', line 19

def self.register(code, &blk)
  commands[code] = lambda { |args|
    ExecutionContext.new.instance_exec(GitRepo.new("."), args, &blk)
  }
end

.run(code, args) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/git-smart/git_smart.rb', line 2

def self.run(code, args)
  lambda = commands[code]
  if lambda
    begin
      lambda.call(args)
    rescue GitSmart::Exception => e
      if e.message && !e.message.empty?
        puts e.message.red
      end
    end
  else
    puts "No command #{code.inspect} defined! Available commands are #{commands.keys.sort.inspect}"
  end
end