Class: BzrWrapper::Branch

Inherits:
Object
  • Object
show all
Defined in:
lib/bzrwrapper.rb

Overview

represents bazaar-branch

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Branch

initiate instance with path to existent bazaar-branch :call-seq:

BzrWrapper::Branch.new('/your/path/to/branch')    -> BzrWrapper::Branch


70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/bzrwrapper.rb', line 70

def initialize(path)
  unless File.exist?(path) && File.readable?(path)
    raise ArgumentError, "no such file / not readable: #{path}"
  end
  begin
    Branch.is_branch?(path)
  rescue BzrException => e
    puts "no branch: #{e}"
    exit 0
  end
  @path = path
  @version_info = create_info
end

Instance Attribute Details

#pathObject (readonly)

filepath to the bazaar-branch



61
62
63
# File 'lib/bzrwrapper.rb', line 61

def path
  @path
end

#version_infoObject (readonly)

returns BzrWrapper::Info



63
64
65
# File 'lib/bzrwrapper.rb', line 63

def version_info
  @version_info
end

Class Method Details

.is_branch?(path) ⇒ Boolean

checks if given ‘path’ is a bazaar-branch

Returns:

  • (Boolean)


92
93
94
95
96
97
98
99
100
101
102
# File 'lib/bzrwrapper.rb', line 92

def Branch.is_branch?(path)
  Dir.chdir(path) do |branch|
    IO.popen('bzr version-info') do |io| 
      if io.gets.nil?
        raise BzrException, "Not ab branch: #{path}"
      else
        return true
      end
    end
  end
end

Instance Method Details

#last_commits(num, &block) ⇒ Object

returns last num Commit’s or yields commit if block given



107
108
109
110
# File 'lib/bzrwrapper.rb', line 107

def last_commits(num,&block)
  x = -num
  block_given? ? log.commits[x..-1].each { |commit| yield commit }  : log.commits[x..-1]
end

#logObject

returns BzrWrapper::Log



86
87
88
# File 'lib/bzrwrapper.rb', line 86

def log
  @log || create_log
end