Class: TDP::PatchSet
- Inherits:
-
Object
- Object
- TDP::PatchSet
- Defined in:
- lib/tdp.rb
Overview
A set of patches.
Instance Method Summary collapse
-
#<<(patch) ⇒ Object
Adds a patch to the set.
-
#[](name) ⇒ Object
Retrieves Patch by name.
-
#each ⇒ Object
Calls the given block once for each patch in collection, passing that element as a parameter.
-
#initialize ⇒ PatchSet
constructor
A new instance of PatchSet.
-
#select ⇒ Object
Returns an array of patches for which given block returns a true value.
Constructor Details
#initialize ⇒ PatchSet
Returns a new instance of PatchSet.
151 152 153 |
# File 'lib/tdp.rb', line 151 def initialize @patches = {} end |
Instance Method Details
#<<(patch) ⇒ Object
Adds a patch to the set. Raises ContradictionError in case if patch set already contains a patch with the same name and different content.
- patch
-
Patch object to add
162 163 164 165 166 167 168 169 |
# File 'lib/tdp.rb', line 162 def <<(patch) known_patch = @patches[patch.name] if known_patch.nil? @patches[patch.name] = patch elsif patch.content != known_patch.content raise ContradictionError, [known_patch, patch] end end |
#[](name) ⇒ Object
Retrieves Patch by name. If there’s no patch with this name, returns nil.
197 198 199 |
# File 'lib/tdp.rb', line 197 def [](name) @patches[name] end |
#each ⇒ Object
Calls the given block once for each patch in collection, passing that element as a parameter.
Ordering of the patches is: first, all permanent patches alphanumerically sorted by name, then all volatile patches sorted in the same way.
179 180 181 |
# File 'lib/tdp.rb', line 179 def each @patches.values.sort.each { |patch| yield patch } end |
#select ⇒ Object
Returns an array of patches for which given block returns a true value.
Ordering of patches is same as in #self.each method.
189 190 191 |
# File 'lib/tdp.rb', line 189 def select @patches.values.sort.select { |patch| yield patch } end |