Class: GitSmart
- 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
- .commands ⇒ Object
-
.register(code, &blk) ⇒ Object
Used like this: GitSmart.register 'my-command' do |repo, args|.
- .run(code, args) ⇒ Object
Class Method Details
.commands ⇒ Object
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. && !e..empty? puts e..red end end else puts "No command #{code.inspect} defined! Available commands are #{commands.keys.sort.inspect}" end end |