Class: Rpmchange::Spec
- Inherits:
-
Object
- Object
- Rpmchange::Spec
- Defined in:
- lib/rpmchange/spec.rb
Constant Summary collapse
- SECTIONS =
%i{prep build install clean check files changelog}
Instance Attribute Summary collapse
-
#str ⇒ Object
readonly
<< self.
Class Method Summary collapse
Instance Method Summary collapse
- #append_changelog(name:, email:, message:) ⇒ Object
- #append_patch(value) ⇒ Object
- #append_patch_macro(num) ⇒ Object
- #append_patch_tag(value) ⇒ Object
- #append_tag(tag, value) ⇒ Object
- #diff(with: nil, **kwargs) ⇒ Object
- #dump ⇒ Object
- #epoch ⇒ Object
- #epoch=(value) ⇒ Object
- #full_version ⇒ Object
-
#initialize(str) ⇒ Spec
constructor
A new instance of Spec.
- #inspect ⇒ Object
- #name ⇒ Object
- #name=(value) ⇒ Object
- #patch_tags ⇒ Object
- #preamble_lines ⇒ Object
- #release ⇒ Object
- #release=(value) ⇒ Object
- #reload ⇒ Object
- #sections ⇒ Object
- #set_tag(tag, value) ⇒ Object
- #tag(tag) ⇒ Object
- #to_s ⇒ Object
- #to_tag_name(tag) ⇒ Object
- #version ⇒ Object
- #version=(value) ⇒ Object
Constructor Details
#initialize(str) ⇒ Spec
Returns a new instance of Spec.
22 23 24 25 |
# File 'lib/rpmchange/spec.rb', line 22 def initialize(str) @str = str _load! end |
Instance Attribute Details
#str ⇒ Object (readonly)
<< self
20 21 22 |
# File 'lib/rpmchange/spec.rb', line 20 def str @str end |
Class Method Details
.diff(a, b, **kwargs) ⇒ Object
12 13 14 |
# File 'lib/rpmchange/spec.rb', line 12 def diff(a, b, **kwargs) Diffy::Diff.new(a.to_s, b.to_s, {diff: "-U 3"}.merge(kwargs)) end |
.loadfile(path) ⇒ Object
8 9 10 |
# File 'lib/rpmchange/spec.rb', line 8 def loadfile(path) Spec.new(Pathname.new(path).read) end |
.without_macro ⇒ Object
16 17 |
# File 'lib/rpmchange/spec.rb', line 16 def without_macro end |
Instance Method Details
#append_changelog(name:, email:, message:) ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/rpmchange/spec.rb', line 98 def append_changelog(name:, email:, message:) = .to_s.split("\n") [0] = "- #{[0]}" 1.upto(.size - 1).each do |i| [i] = " #{[i]}" end ["* #{Time.now.strftime("%a %b %e %Y")} #{name} <#{email}> - #{full_version}", .join("\n"), "", ].reverse_each {|line| _prepend_line(lines: changelog_lines, new_line: line)} end |
#append_patch(value) ⇒ Object
129 130 131 |
# File 'lib/rpmchange/spec.rb', line 129 def append_patch(value) append_patch_macro append_patch_tag(value) end |
#append_patch_macro(num) ⇒ Object
155 156 157 158 |
# File 'lib/rpmchange/spec.rb', line 155 def append_patch_macro(num) _append_line(lines: prep_lines, new_line: "%patch#{num} -p1", after: _patch_macro_line_regex) nil end |
#append_patch_tag(value) ⇒ Object
140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/rpmchange/spec.rb', line 140 def append_patch_tag(value) patch_num = nil make_line = proc do |insert_ind| if insert_ind > 0 last_patch_num = _patch_tag_line_parse(preamble_lines[insert_ind - 1]).first patch_num = last_patch_num + 1 else patch_num = 0 end "Patch#{patch_num}: #{value}" end _append_line(lines: preamble_lines, new_line: make_line, after: _patch_tag_line_regex) patch_num end |
#append_tag(tag, value) ⇒ Object
125 126 127 |
# File 'lib/rpmchange/spec.rb', line 125 def append_tag(tag, value) _append_line(lines: preamble_lines, new_line: "#{to_tag_name(tag)}: #{value}") end |
#diff(with: nil, **kwargs) ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/rpmchange/spec.rb', line 51 def diff(with: nil, **kwargs) if with self.class.diff(dump, with, **kwargs) else self.class.diff(str, dump, **kwargs) end end |
#dump ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/rpmchange/spec.rb', line 31 def dump [].tap do |res| res.push *preamble_lines sections.each do |section, by_params| by_params.each {|params, lines| res.push ["%#{section}", *params].join(' ') res.push *lines } end end.map {|line| line + "\n"}.join end |
#epoch ⇒ Object
83 84 85 |
# File 'lib/rpmchange/spec.rb', line 83 def epoch tag(:epoch) end |
#epoch=(value) ⇒ Object
87 88 89 |
# File 'lib/rpmchange/spec.rb', line 87 def epoch=(value) set_tag(:epoch, value) end |
#full_version ⇒ Object
91 92 93 94 95 96 |
# File 'lib/rpmchange/spec.rb', line 91 def full_version [epoch, [version, release].compact.join('-')] .compact .join(':') .gsub(/%{.*}/, '') end |
#inspect ⇒ Object
47 48 49 |
# File 'lib/rpmchange/spec.rb', line 47 def inspect "#<#{self.class}: #{name}/#{full_version}>" end |
#name ⇒ Object
59 60 61 |
# File 'lib/rpmchange/spec.rb', line 59 def name tag(:name) end |
#name=(value) ⇒ Object
63 64 65 |
# File 'lib/rpmchange/spec.rb', line 63 def name=(value) set_tag(:name, value) end |
#patch_tags ⇒ Object
133 134 135 136 137 138 |
# File 'lib/rpmchange/spec.rb', line 133 def preamble_lines .grep(_patch_tag_line_regex) .map(&method(:_patch_tag_line_parse)) .to_h end |
#preamble_lines ⇒ Object
164 165 166 |
# File 'lib/rpmchange/spec.rb', line 164 def preamble_lines @preamble_lines ||= [] end |
#release ⇒ Object
75 76 77 |
# File 'lib/rpmchange/spec.rb', line 75 def release tag(:release) end |
#release=(value) ⇒ Object
79 80 81 |
# File 'lib/rpmchange/spec.rb', line 79 def release=(value) set_tag(:release, value) end |
#reload ⇒ Object
27 28 29 |
# File 'lib/rpmchange/spec.rb', line 27 def reload @sections = nil end |
#sections ⇒ Object
160 161 162 |
# File 'lib/rpmchange/spec.rb', line 160 def sections @sections ||= {} end |
#set_tag(tag, value) ⇒ Object
121 122 123 |
# File 'lib/rpmchange/spec.rb', line 121 def set_tag(tag, value) _replace_line(lines: preamble_lines, new_line: "#{to_tag_name(tag)}: #{value.strip}", match: /#{to_tag_name(tag)}:/) end |
#tag(tag) ⇒ Object
115 116 117 118 119 |
# File 'lib/rpmchange/spec.rb', line 115 def tag(tag) match = preamble_lines.find {|line| line.start_with? "#{to_tag_name(tag)}:"} res = match.split(':', 2).last if match res.strip if res end |
#to_s ⇒ Object
43 44 45 |
# File 'lib/rpmchange/spec.rb', line 43 def to_s dump end |
#to_tag_name(tag) ⇒ Object
111 112 113 |
# File 'lib/rpmchange/spec.rb', line 111 def to_tag_name(tag) tag.to_s.capitalize end |
#version ⇒ Object
67 68 69 |
# File 'lib/rpmchange/spec.rb', line 67 def version tag(:version) end |
#version=(value) ⇒ Object
71 72 73 |
# File 'lib/rpmchange/spec.rb', line 71 def version=(value) set_tag(:version, value) end |