Class: RedmineExtensions::PatchManager::EasyPatchesSection

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/redmine_extensions/patch_manager.rb

Instance Method Summary collapse

Constructor Details

#initializeEasyPatchesSection

attr_reader :name, :order



153
154
155
156
157
158
159
# File 'lib/redmine_extensions/patch_manager.rb', line 153

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 = Array.new
  @last_order = 0
end

Instance Method Details

#[](name) ⇒ Object



177
178
179
# File 'lib/redmine_extensions/patch_manager.rb', line 177

def [](name)
  pcollection = @patches_collections.detect{|patch_col| patch_col.name == name }
end

#apply_all_patchesObject



171
172
173
174
175
# File 'lib/redmine_extensions/patch_manager.rb', line 171

def apply_all_patches
  @patches_collections.each do |patch_collection|
    patch_collection.apply_all_patches
  end
end

#each(&block) ⇒ Object



161
162
163
164
165
166
167
168
169
# File 'lib/redmine_extensions/patch_manager.rb', line 161

def each(&block)
  @patches_collections.each do |patch_collection|
    if block_given?
      block.call patch_collection
    else
      yield patch_collection
    end
  end
end

#find_order(options) ⇒ Object



199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
# File 'lib/redmine_extensions/patch_manager.rb', line 199

def find_order( options )
  if options.delete(:first)
    return 1
  elsif before = options.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 = options.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 options.delete(:last)
    # do nothing
  end

  nil
end

#include_patch?(name) ⇒ Boolean

Returns:

  • (Boolean)


181
182
183
# File 'lib/redmine_extensions/patch_manager.rb', line 181

def include_patch?(name)
  !!@patches_collections.detect{|patch_col| patch_col.name == name }
end

#move_and_get_or_insert(name, options) ⇒ Object



185
186
187
188
189
190
191
192
193
194
195
196
197
# File 'lib/redmine_extensions/patch_manager.rb', line 185

def move_and_get_or_insert( name, options )
  pcollection = @patches_collections.detect{|patch_col| patch_col.name == name }
  founded_order = find_order( options )
  if pcollection
    if founded_order
      pcollection.order = founded_order
      update_order_by(pcollection)
    end
  else
    pcollection = insert( name, founded_order )
  end
  pcollection
end