Class: Darcs::PatchInfo
- Inherits:
-
Object
- Object
- Darcs::PatchInfo
- Defined in:
- lib/darcs/patchinfo.rb
Overview
This class holds the patch’s name, log, author, date, and other meta-info.
Instance Attribute Summary collapse
-
#author ⇒ Object
readonly
Returns the value of attribute author.
-
#date ⇒ Object
readonly
Returns the value of attribute date.
-
#log ⇒ Object
readonly
Returns the value of attribute log.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
-
.read(f) ⇒ Object
Reads a patch from a stream using the inventory format.
Instance Method Summary collapse
-
#filename ⇒ Object
Retrieve the patch’s name.
-
#initialize(date, name, author, log = nil, inverted = false) ⇒ PatchInfo
constructor
A new instance of PatchInfo.
- #inverted? ⇒ Boolean
-
#timestamp ⇒ Object
Retrieve the patch’s date in string timestamp format.
- #to_s ⇒ Object
Constructor Details
#initialize(date, name, author, log = nil, inverted = false) ⇒ PatchInfo
Returns a new instance of PatchInfo.
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/darcs/patchinfo.rb', line 9 def initialize(date, name, , log = nil, inverted = false) if date.kind_of?(String) @date = parse_date(date) else @date = date end @name = name @author = @log = log @inverted = inverted end |
Instance Attribute Details
#author ⇒ Object (readonly)
Returns the value of attribute author.
21 22 23 |
# File 'lib/darcs/patchinfo.rb', line 21 def @author end |
#date ⇒ Object (readonly)
Returns the value of attribute date.
21 22 23 |
# File 'lib/darcs/patchinfo.rb', line 21 def date @date end |
#log ⇒ Object (readonly)
Returns the value of attribute log.
21 22 23 |
# File 'lib/darcs/patchinfo.rb', line 21 def log @log end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
21 22 23 |
# File 'lib/darcs/patchinfo.rb', line 21 def name @name end |
Class Method Details
.read(f) ⇒ Object
Reads a patch from a stream using the inventory format
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/darcs/patchinfo.rb', line 27 def self.read(f) line = f.gets return nil if line.nil? if line[0..0] != '[' raise "Invalid inventory entry (starts with \"#{line[0..-2]}\")" end name = line[1..-2] line = f.readline raise "Invalid inventory entry" if !line[/^(.*)\*\*([0-9]{14})\]?\s*$/] = $1 date = $2 log = nil if !line[/\]\s*$/] log = "" log += line[1..-1] while !((line = f.readline) =~ /^\]/) end return self.new(date, name, , log) end |
Instance Method Details
#filename ⇒ Object
Retrieve the patch’s name
54 55 56 57 58 59 60 |
# File 'lib/darcs/patchinfo.rb', line 54 def filename = SHA1.new().to_s[0..4] hash = SHA1.new(name + + + (log.nil? ? '' : log.gsub(/\n/, '')) + (inverted? ? 't' : 'f')) "#{}-#{}-#{hash}.gz" end |
#inverted? ⇒ Boolean
22 23 24 |
# File 'lib/darcs/patchinfo.rb', line 22 def inverted? @inverted end |
#timestamp ⇒ Object
Retrieve the patch’s date in string timestamp format
49 50 51 |
# File 'lib/darcs/patchinfo.rb', line 49 def date.strftime("%Y%m%d%H%M%S") end |
#to_s ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/darcs/patchinfo.rb', line 62 def to_s if log the_log = log.gsub(/[\n\s]+$/, '').gsub(/\n/, "\n ") end "[#{name}\n#{}**#{}" + (log.nil? ? '' : "\n " + the_log + "\n") + "]" end |