Skip to content

Commit

Permalink
WIP: Rubocop
Browse files Browse the repository at this point in the history
  • Loading branch information
joseivanlopez committed Jul 24, 2023
1 parent 7dc224e commit 9b3a7e0
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def initialize(settings)
# Performs the conversion to D-Bus format.
#
# @return [Hash]
def convert
def convert # rubocop:disable Metrics/AbcSize
{
"BootDevice" => settings.boot_device.to_s,
"LVM" => settings.lvm,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def candidate_devices
# @return [Array<String>]
def all_devices
devices = candidate_devices
devices += settings.volumes.map { |v| v.device }
devices += settings.volumes.map(&:device)

devices.uniq.map { |d| device_or_partitions(d) }.flatten
end
Expand Down
15 changes: 15 additions & 0 deletions service/lib/agama/storage/proposal_settings_reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,16 @@

module Agama
module Storage
# Proposal settings reader.
class ProposalSettingsReader
# @param config [Agama::Config]
def initialize(config)
@config = config
end

# Reads the proposal settings from the control file.
#
# @return [ProposalSettings]
def read
settings = ProposalSettings.new
config.fetch("storage", {}).each do |key, value|
Expand All @@ -39,8 +44,10 @@ def read

private

# @return [Agama::Config]
attr_reader :config

# Settings from control file and their readers.
READERS = {
"lvm" => :lvm_reader,
"encrypttion" => :encryption_reader,
Expand All @@ -50,10 +57,14 @@ def read

private_constant :CONFIG_READERS

# @param settings [Agama::Storage::ProposalSettings]
# @param value [Boolean]
def lvm_reader(settings, value)
settings.lvm.enabled = value
end

# @param settings [Agama::Storage::ProposalSettings]
# @param encryption [Hash]
def encryption_reader(settings, encryption)
method = Y2Storage::EncryptionMethod.find(encryption.fetch("method", ""))
pbkd_function = Y2Storage::PbkdFunction.find(encryption.fetch("pbkd_function", ""))
Expand All @@ -62,10 +73,14 @@ def encryption_reader(settings, encryption)
settings.encryption.pbkd_function = pbkd_function if pbkd_function
end

# @param settings [Agama::Storage::ProposalSettings]
# @param value [String]
def space_policy_reader(settings, value)
settings.space.policy = value.to_sym
end

# @param settings [Agama::Storage::ProposalSettings]
# @param volumes [Array<Hash>]
def volumes_reader(settings, volumes)
builder = VolumeTemplatesBuilder.new_from_config(config)
mount_paths = volumes.map { |v| v["mount_path"] }.compact
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def convert

# @param target [Agama::Storage::Volume]
def sizes_conversion(target)
target.auto_size = !(spec.ignore_fallback_sizes? && spec.ignore_fallback_sizes?)
target.auto_size = !(spec.ignore_fallback_sizes? && spec.ignore_snapshots_sizes?)

planned = planned_device_for(spec.mount_point)
target.min_size = planned&.min || spec.min_size
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def initialize(volume)
# Performs the conversion to Y2Storage format.
#
# @return [Y2Storage::VolumeSpecification]
def convert
def convert # rubocop:disable Metrics/AbcSize
Y2Storage::VolumeSpecification.new({}).tap do |target|
target.device = volume.device
target.separate_vg_name = volume.separate_vg_name
Expand Down
6 changes: 3 additions & 3 deletions service/lib/agama/storage/volume_templates_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def key(data)
cleanpath(path)
end

def values(data)
def values(data) # rubocop:disable Metrics/AbcSize
{}.tap do |values|
values[:btrfs] = btrfs(data)
values[:outline] = outline(data)
Expand All @@ -105,7 +105,7 @@ def btrfs(data)
btrfs.read_only = btrfs_data.fetch("read_only", false)
btrfs.default_subvolume = btrfs_data.fetch("default_subvolume", "")
btrfs.subvolumes = btrfs_data["subvolumes"]
btrfs.subvolumes.map! { |subvol_data| subvolume(subvol_data) } if btrfs.subvolumes
btrfs.subvolumes&.map! { |subvol_data| subvolume(subvol_data) }
end
end

Expand All @@ -117,7 +117,7 @@ def subvolume(data)
)
end

def outline(data)
def outline(data) # rubocop:disable Metrics/AbcSize
outline_data = data.fetch("outline", {})
VolumeOutline.new.tap do |outline|
outline.required = outline_data.fetch("required", false)
Expand Down

0 comments on commit 9b3a7e0

Please sign in to comment.