Skip to content

Commit

Permalink
Factored out Stage1#merge
Browse files Browse the repository at this point in the history
to please RuboCop Metrics/AbcSize.
  • Loading branch information
mvidner committed May 11, 2016
1 parent 0644e1c commit adcb07b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .rubocop.yml
Expand Up @@ -31,7 +31,7 @@ Metrics/ClassLength:

# Configuration parameters: CountComments.
Metrics/ClassLength:
Max: 250 # TODO this should be lower for new code
Max: 256 # TODO this should be lower for new code
Include:
- 'src/lib/**/*.rb' # be more strict for new code in lib

Expand Down
27 changes: 1 addition & 26 deletions src/lib/bootloader/grub2.rb
Expand Up @@ -95,24 +95,7 @@ def merge(other)
@device_map = other.device_map if !other.device_map.empty?
@trusted_boot = other.trusted_boot unless other.trusted_boot.nil?

# merge here is a bit tricky, as for stage1 does not exist `defined?`
# because grub_installdevice contain value or not, so it is not
# possible to recognize if chosen or just not set
# so logic is following
# 1) if any flag is set to true, then use it because e.g. autoyast defined flags,
# but devices usually not
# 2) if there is devices specified, then set also flags to value in other
# as it mean, that there is enough info to decide
log.info "stage1 to merge #{other.stage1.inspect}"

# so first part of logic
stage1.activate = stage1.activate? || other.stage1.activate?
stage1.generic_mbr = stage1.generic_mbr? || other.stage1.generic_mbr?

# use second part described above if there is some device
replace_with(other) unless other.stage1.devices.empty?

log.info "stage1 after merge #{stage1.inspect}"
stage1.merge(other.stage1)
end

# Display bootloader summary
Expand Down Expand Up @@ -178,14 +161,6 @@ def write_sysconfig(prewrite: false)

private

def replace_with(other)
stage1.clear_devices
other.stage1.devices.each { |d| stage1.add_udev_device(d) }

stage1.activate = other.stage1.activate?
stage1.generic_mbr = other.stage1.generic_mbr?
end

def gpt_disks_devices
boot_devices = stage1.devices
boot_discs = boot_devices.map { |d| Yast::Storage.GetDisk(Yast::Storage.GetTargetMap, d) }
Expand Down
25 changes: 25 additions & 0 deletions src/lib/bootloader/stage1.rb
Expand Up @@ -159,6 +159,31 @@ def can_use_boot?
true
end

def merge(other)
# merge here is a bit tricky, as for stage1 does not exist `defined?`
# because grub_installdevice contain value or not, so it is not
# possible to recognize if chosen or just not set
# so logic is following
# 1) if any flag is set to true, then use it because e.g. autoyast defined flags,
# but devices usually not
# 2) if there is devices specified, then set also flags to value in other
# as it mean, that there is enough info to decide
log.info "stage1 to merge #{other.inspect}"

if other.devices.empty?
self.activate = activate? || other.activate?
self.generic_mbr = generic_mbr? || other.generic_mbr?
else
clear_devices
other.devices.each { |d| add_udev_device(d) }

self.activate = other.activate?
self.generic_mbr = other.generic_mbr?
end

log.info "stage1 after merge #{inspect}"
end

private

def available_partitions(res)
Expand Down

0 comments on commit adcb07b

Please sign in to comment.