Class: CommitSnapshot

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

Constant Summary collapse

ATTRIBUTES =
[:commit_ref, :author, :email, :date, :messages]

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ CommitSnapshot

Returns a new instance of CommitSnapshot.



331
332
333
334
335
336
337
338
339
340
341
342
343
344
# File 'lib/growthspurt.rb', line 331

def initialize(*args)
  if args[0].kind_of? Hash
    ATTRIBUTES.each do | sym |
      self.instance_variable_set "@#{sym}", args[0][sym]
    end
    if self.messages
      self.messages = (self.messages.kind_of?(String) ? self.messages.split(/[;\n]/) : self.messages).delete_if{|e| e.empty?}
    end
    self.date = Time.parse( self.date ) if self.date && !self.date.kind_of?(Time)
  else
    commit = args[0]
    initialize(:commit_ref => commit.id_abbrev, :author => commit.author.name, :email => commit.author.email, :date => commit.date, :messages => commit.message)
  end
end

Instance Method Details

#formatted_dateObject



346
347
348
# File 'lib/growthspurt.rb', line 346

def formatted_date
  self.date.strftime('%Y-%m-%d')
end

#formatted_for_changes_dot_xml_file {|v| ... } ⇒ Object

Yields:

  • (v)


359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
# File 'lib/growthspurt.rb', line 359

def formatted_for_changes_dot_xml_file
  # <action dev=.. due-to=.. due-to-email=.. issue=.. type=.. system=.. date=.. >
  template = "      <action dev='%s' type='%s' date='%s'><![CDATA[%s: %s]]></action>\n"
  reference = self.commit_ref[0...7]
  v = self.messages.collect { | message_within_commit |
    msg = message_within_commit.downcase
    action_type = if !!(msg =~ /bug|fix/)
      'fix'
    elsif !!(msg =~ /update/)
      'update'
    elsif !!(msg =~ /remove/)
      'remove'
    else
      'add'
    end

    template % [self.author, action_type, formatted_date, reference, message_within_commit]
  }.join('')
  yield v if block_given?
  v
end

#formatted_for_changes_file {|v| ... } ⇒ Object

Yields:

  • (v)


350
351
352
353
354
355
356
357
# File 'lib/growthspurt.rb', line 350

def formatted_for_changes_file
  separator = ('-' * self.author.length) + '---------------------------'
  each_message = self.messages.join("\n")
  each_message.gsub!(/(.{1,80}|\S{81,})(?: +|$\n?)/, "    \\1\n")
  v = "#{separator}\n  %s on %s, %s\n#{separator}\n%s\n\n" % [self.author, formatted_date, self.commit_ref[0...7], each_message]
  yield v if block_given?
  v
end