Class: Debian
- Inherits:
-
Object
- Object
- Debian
- Defined in:
- lib/msp_release/debian.rb
Defined Under Namespace
Modules: Versions
Instance Attribute Summary collapse
-
#fname ⇒ Object
readonly
Returns the value of attribute fname.
Instance Method Summary collapse
- #add(version, stub, distribution = self.distribution) ⇒ Object
- #amend(version, distribution = self.distribution) ⇒ Object
- #create_signoff ⇒ Object
- #create_top_line(v, distribution) ⇒ Object
- #default_distribution ⇒ Object
- #distribution ⇒ Object
- #distribution_pattern ⇒ Object
-
#initialize(basedir, fname) ⇒ Debian
constructor
A new instance of Debian.
- #matches(version) ⇒ Object
- #package_name ⇒ Object
- #read_top_line ⇒ Object
- #reset_at(project_version) ⇒ Object
- #version ⇒ Object
- #version_classes ⇒ Object
- #version_string_from_top_line ⇒ Object
Constructor Details
#initialize(basedir, fname) ⇒ Debian
Returns a new instance of Debian.
130 131 132 |
# File 'lib/msp_release/debian.rb', line 130 def initialize(basedir, fname) @fname = File.join(basedir, fname) end |
Instance Attribute Details
#fname ⇒ Object (readonly)
Returns the value of attribute fname.
134 135 136 |
# File 'lib/msp_release/debian.rb', line 134 def fname @fname end |
Instance Method Details
#add(version, stub, distribution = self.distribution) ⇒ Object
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/msp_release/debian.rb', line 193 def add(version, stub, distribution=self.distribution) tline = create_top_line(version, distribution) all = File.open(@fname, 'r') {|f| f.readlines } new = [ tline, "", " * #{stub}", "", create_signoff + "\n", "" ] File.open(@fname, 'w') {|f| f.write(new.join("\n")); f.write(all.join) } version end |
#amend(version, distribution = self.distribution) ⇒ Object
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'lib/msp_release/debian.rb', line 176 def amend(version, distribution=self.distribution) # replace the first line tline, *all = File.open(@fname, 'r') {|f|f.readlines} cur_version = /^[^\(]+\(([^\)]+).+/.match(tline)[1] tline = tline.gsub(cur_version, "#{version}"). gsub(distribution_pattern) {|m|"#{$1}#{distribution}" } all.unshift(tline) signoff_idx = all.index {|l| /^ -- .+$/.match(l) } all[signoff_idx] = create_signoff File.open(@fname, 'w') { |f| all.each {|l|f.puts(l) } } version end |
#create_signoff ⇒ Object
215 216 217 218 219 |
# File 'lib/msp_release/debian.rb', line 215 def create_signoff date = MSPRelease.time_rfc = MSPRelease. " -- #{.name} <#{.email}> #{date}" end |
#create_top_line(v, distribution) ⇒ Object
221 222 223 224 225 226 |
# File 'lib/msp_release/debian.rb', line 221 def create_top_line(v, distribution) tline = "#{package_name} (#{v})" # FIXME, un-hardcode this? tline + " #{distribution}; urgency=low" end |
#default_distribution ⇒ Object
128 |
# File 'lib/msp_release/debian.rb', line 128 def default_distribution ; "msp" ; end |
#distribution ⇒ Object
156 157 158 |
# File 'lib/msp_release/debian.rb', line 156 def distribution (m = distribution_pattern.match(read_top_line)) && m[2] end |
#distribution_pattern ⇒ Object
152 153 154 |
# File 'lib/msp_release/debian.rb', line 152 def distribution_pattern /([^ ]+ [^ ]+ )([^;]+)/ end |
#matches(version) ⇒ Object
172 173 174 |
# File 'lib/msp_release/debian.rb', line 172 def matches(version) self.version == version end |
#package_name ⇒ Object
160 161 162 |
# File 'lib/msp_release/debian.rb', line 160 def package_name /[a-z0-9\-]+/.match(read_top_line) end |
#read_top_line ⇒ Object
136 137 138 |
# File 'lib/msp_release/debian.rb', line 136 def read_top_line File.open(@fname, 'r') {|f|f.readline} end |
#reset_at(project_version) ⇒ Object
211 212 213 |
# File 'lib/msp_release/debian.rb', line 211 def reset_at(project_version) Versions::Unreleased.new_from_version(project_version).bump end |
#version ⇒ Object
144 145 146 147 148 149 150 |
# File 'lib/msp_release/debian.rb', line 144 def version version_classes.each do |c| v = c.new_if_matches(version_string_from_top_line) and return v end Versions::Unrecognized.new(version_string_from_top_line) end |
#version_classes ⇒ Object
140 141 142 |
# File 'lib/msp_release/debian.rb', line 140 def version_classes [Versions::Unreleased, Versions::Stable, Versions::Development] end |
#version_string_from_top_line ⇒ Object
164 165 166 167 168 169 170 |
# File 'lib/msp_release/debian.rb', line 164 def version_string_from_top_line tline = read_top_line match = /[a-z\-]+ \(([^\)]+)\)/.match(tline) match && match[1] or raise "could not parse version info from #{tline}" end |