Class: SvnAuto::SvnInfo
- Inherits:
-
Object
- Object
- SvnAuto::SvnInfo
- Defined in:
- lib/svnauto/svn_info.rb
Constant Summary collapse
- ATTRIBUTES =
at least for now, it’s eaiser to parse via regex instead of XML
[ [:path, /^Path:\s+(.+)$/], [:url, /^URL:\s+(.+)$/], [:repository_root, /^Repository\s+Root:\s+(.+)$/], [:revision, /^Revision:\s+(\d+)$/], [:last_change_revision, /^Last\s+Changed\s+Rev:\s+(\d+)$/], [:last_change_date, /^Last\s+Changed\s+Date:\s+([\d-]+\s+[\d:]+(?:\s+[\d+-]+))/], ]
Instance Attribute Summary collapse
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Class Method Summary collapse
-
.for(path, raise_on_error = false) ⇒ Object
get info about the given path.
Instance Method Summary collapse
-
#initialize(attributes = {}) ⇒ SvnInfo
constructor
create a new SvnInfo object.
-
#load_for_path(path) ⇒ Object
parse the output of svn info.
Constructor Details
#initialize(attributes = {}) ⇒ SvnInfo
create a new SvnInfo object
55 56 57 58 59 60 61 62 |
# File 'lib/svnauto/svn_info.rb', line 55 def initialize (attributes={}) ATTRIBUTES.each {|a| instance_variable_set("@#{a.first}", nil)} attributes.each do |k,v| raise "bad SvnInfo attribute given to initialize: #{k}" unless ATTRIBUTES.find {|a| a.first == k} instance_variable_set("@#{k}", v) end end |
Instance Attribute Details
#status ⇒ Object (readonly)
Returns the value of attribute status.
41 42 43 |
# File 'lib/svnauto/svn_info.rb', line 41 def status @status end |
Class Method Details
.for(path, raise_on_error = false) ⇒ Object
get info about the given path
45 46 47 48 49 50 51 |
# File 'lib/svnauto/svn_info.rb', line 45 def self.for (path, raise_on_error=false) info = self.new info.load_for_path(path) raise "svn info command failed for #{path}" if !info.status and raise_on_error info end |
Instance Method Details
#load_for_path(path) ⇒ Object
parse the output of svn info
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/svnauto/svn_info.rb', line 66 def load_for_path (path) attributes = ATTRIBUTES.inject({}) {|m, e| m.store(e.first, nil); m} @status = Svn.info(path) do |line| ATTRIBUTES.each do |a| if m = line.match(a.last) instance_variable_set("@#{a.first}", m[1]) attributes[a.first] = true break end end end # no need to check the status of the regexes if svn info failed return @status unless @status attributes.each do |k, v| unless v error = "please report a bug in #{Constants::ME}, I can't parse the output " error << "of 'svn info', specifically, this regex did not match: " error << ATTRIBUTES.find {|a| a.first == k}.last.to_s + ' ' error << "please also include the output of 'svn info #{path}'" raise error end end @status end |