Class: RedmineExtensions::PatchManager::EasyPatchesSection
- Includes:
- Enumerable
- Defined in:
- lib/redmine_extensions/patch_manager.rb
Instance Method Summary collapse
- #[](name) ⇒ Object
- #apply_all_patches ⇒ Object
- #each(&block) ⇒ Object
- #find_order(options) ⇒ Object
- #include_patch?(name) ⇒ Boolean
-
#initialize ⇒ EasyPatchesSection
constructor
attr_reader :name, :order.
- #move_and_get_or_insert(name, options) ⇒ Object
Constructor Details
#initialize ⇒ EasyPatchesSection
attr_reader :name, :order
190 191 192 193 194 195 196 |
# File 'lib/redmine_extensions/patch_manager.rb', line 190 def initialize #( name = nil, order = nil ) # raise ArgumentError, 'Section order has to be a integer!' unless order.is_a?(Numeric) # @name = name # @order = order @patches_collections = [] @last_order = 0 end |
Instance Method Details
#[](name) ⇒ Object
210 211 212 |
# File 'lib/redmine_extensions/patch_manager.rb', line 210 def [](name) pcollection = @patches_collections.detect{|patch_col| patch_col.name == name } end |
#apply_all_patches ⇒ Object
204 205 206 207 208 |
# File 'lib/redmine_extensions/patch_manager.rb', line 204 def apply_all_patches @patches_collections.each do |patch_collection| patch_collection.apply_all_patches end end |
#each(&block) ⇒ Object
198 199 200 201 202 |
# File 'lib/redmine_extensions/patch_manager.rb', line 198 def each(&block) @patches_collections.each do |patch_collection| yield patch_collection end end |
#find_order(options) ⇒ Object
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 |
# File 'lib/redmine_extensions/patch_manager.rb', line 232 def find_order( ) if .delete(:first) return 1 elsif before = .delete(:before) if before.is_a? Array min = nil before.each do |before_class_name| actual = nil before_patch = self[before_class_name] actual = before_patch.order if before_patch if actual && ( !min || actual < min ) min = actual end end return min else before_patch = self[before] return before_patch.order + 1 if before_patch end elsif after = .delete(:after) if after.is_a? Array max = -1 after.each do |after_class_name| actual = nil after_patch = self[after_class_name] actual = after_patch.order + 1 if after_patch if actual && actual > max max = actual end end return max else after_patch = self[after] return after_patch.order + 1 if after_patch end elsif .delete(:last) # do nothing end nil end |
#include_patch?(name) ⇒ Boolean
214 215 216 |
# File 'lib/redmine_extensions/patch_manager.rb', line 214 def include_patch?(name) !!@patches_collections.detect{|patch_col| patch_col.name == name } end |
#move_and_get_or_insert(name, options) ⇒ Object
218 219 220 221 222 223 224 225 226 227 228 229 230 |
# File 'lib/redmine_extensions/patch_manager.rb', line 218 def move_and_get_or_insert( name, ) pcollection = @patches_collections.detect{|patch_col| patch_col.name == name } founded_order = find_order( ) if pcollection if founded_order pcollection.order = founded_order update_order_by(pcollection) end else pcollection = insert( name, founded_order ) end pcollection end |