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



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

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.



194
195
196
# File 'lib/git_tools/branches/cleaner.rb', line 194

def age
  @age
end

#nameObject (readonly)

Returns the value of attribute name.



194
195
196
# File 'lib/git_tools/branches/cleaner.rb', line 194

def name
  @name
end

#remoteObject (readonly)

Returns the value of attribute remote.



194
195
196
# File 'lib/git_tools/branches/cleaner.rb', line 194

def remote
  @remote
end

Class Method Details

.age(branch) ⇒ Object



179
180
181
182
183
184
185
186
# File 'lib/git_tools/branches/cleaner.rb', line 179

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



188
189
190
# File 'lib/git_tools/branches/cleaner.rb', line 188

def self.executor
  ActionExecutor.new
end

Instance Method Details

#confirm_remove(message, prompt) ⇒ Object



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

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

#normalized_nameObject



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

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

#remove!(message) ⇒ Object



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

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

#to_sObject



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

def to_s
  name
end