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.



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

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.



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

def age
  @age
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#remoteObject (readonly)

Returns the value of attribute remote.



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

def remote
  @remote
end

Class Method Details

.age(branch) ⇒ Object



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

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

.executorObject



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

def self.executor
  ActionExecutor.new
end

Instance Method Details

#confirm_remove(message, prompt) ⇒ Object



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

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

#normalized_nameObject



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

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

#remove!(message) ⇒ Object



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

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

#to_sObject



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

def to_s
  name
end