Class: GitTools::Branches::Branch

Inherits:
Object
  • Object
show all
Defined in:
lib/git_tools/branches/cleaner.rb

Constant Summary collapse

DATE_REGEXP =
/^Date:\s+(.*)$/

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, remote) ⇒ Branch

Returns a new instance of Branch.



205
206
207
208
209
# File 'lib/git_tools/branches/cleaner.rb', line 205

def initialize(name, remote)
  @name = name
  @remote = remote
  @age = self.class.age(normalized_name)
end

Instance Attribute Details

#ageObject (readonly)

Returns the value of attribute age.



203
204
205
# File 'lib/git_tools/branches/cleaner.rb', line 203

def age
  @age
end

#nameObject (readonly)

Returns the value of attribute name.



203
204
205
# File 'lib/git_tools/branches/cleaner.rb', line 203

def name
  @name
end

#remoteObject (readonly)

Returns the value of attribute remote.



203
204
205
# File 'lib/git_tools/branches/cleaner.rb', line 203

def remote
  @remote
end

Class Method Details

.age(branch) ⇒ Object



187
188
189
190
191
192
193
194
195
# File 'lib/git_tools/branches/cleaner.rb', line 187

def self.age(branch)
  cmd = "git log --shortstat --date=iso -n 1 #{branch}"
  time = DATE_REGEXP.match(`#{cmd}`)
  if time.nil?
    raise "Error due to unexpected git output on command: #{cmd}."
  else
    Time.parse(time[1])
  end
end

.executorObject



197
198
199
# File 'lib/git_tools/branches/cleaner.rb', line 197

def self.executor
  ActionExecutor.new
end

Instance Method Details

#confirm_remove(message, prompt) ⇒ Object



219
220
221
# File 'lib/git_tools/branches/cleaner.rb', line 219

def confirm_remove(message, prompt)
  self.class.executor.execute(remove_branch_action, message, prompt)
end

#normalized_nameObject



211
212
213
# File 'lib/git_tools/branches/cleaner.rb', line 211

def normalized_name
  local? ? name : "#{remote}/#{name}"
end

#remove!(message) ⇒ Object



215
216
217
# File 'lib/git_tools/branches/cleaner.rb', line 215

def remove!(message)
  self.class.executor.execute(remove_branch_action, message)
end

#to_sObject



223
224
225
# File 'lib/git_tools/branches/cleaner.rb', line 223

def to_s
  name
end