Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
joseivanlopez committed Oct 1, 2024
1 parent 2b776f6 commit 50fcc92
Show file tree
Hide file tree
Showing 18 changed files with 69 additions and 180 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,18 @@ module FromJSONConversions
# Boot conversion from JSON hash according to schema.
class Boot < Base
# @see Base#convert
#
# @param boot_json [Hash]
# @return [Configs::Boot]
def convert(boot_json)
@boot_json = boot_json

def convert
super(Configs::Boot.new)
end

private

# @return [Hash]
attr_reader :boot_json
alias_method :boot_json, :config_json

# @see Base#conversions
#
# @param _config [Configs::Boot]
# @return [Hash]
def conversions(_config)
def conversions
{
configure: boot_json[:configure],
device: boot_json[:device]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,18 @@ module FromJSONConversions
# Btrfs conversion from JSON hash according to schema.
class Btrfs < Base
# @see Base#convert
#
# @param btrfs_json [Hash]
# @return [Configs::Btrfs]
def convert(btrfs_json)
@btrfs_json = btrfs_json

def convert
super(Configs::Btrfs.new)
end

private

# @return [String]
attr_reader :btrfs_json
alias_method :btrfs_json, :config_json

# @see Base#conversions
#
# @param _config [Configs::Btrfs]
# @return [Hash]
def conversions(_config)
def conversions
{
snapshots: btrfs_json[:snapshots]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,16 @@ module FromJSONConversions
# Config conversion from JSON hash according to schema.
class Config < Base
# @see Base#convert
#
# @param config_json [Hash]
# @return [Config]
def convert(config_json)
@config_json = config_json

def convert
super(Storage::Config.new)
end

private

# @return [Hash]
attr_reader :config_json

# @see Base#conversions
#
# @param default [Config]
# @return [Hash]
def conversions(config)
def conversions
{
boot: convert_boot,
drives: convert_drives,
Expand All @@ -63,7 +54,7 @@ def convert_boot
boot_json = config_json[:boot]
return unless boot_json

FromJSONConversions::Boot.new.convert(boot_json)
FromJSONConversions::Boot.new(boot_json).convert
end

# @return [Array<Configs::Drive>, nil]
Expand All @@ -77,7 +68,7 @@ def convert_drives
# @param drive_json [Hash]
# @return [Configs::Drive]
def convert_drive(drive_json)
FromJSONConversions::Drive.new.convert(drive_json)
FromJSONConversions::Drive.new(drive_json).convert
end

# @return [Array<Configs::VolumeGroup>, nil]
Expand All @@ -91,7 +82,7 @@ def convert_volume_groups
# @param volume_group_json [Hash]
# @return [Configs::VolumeGroup]
def convert_volume_group(volume_group_json)
FromJSONConversions::VolumeGroup.new.convert(volume_group_json)
FromJSONConversions::VolumeGroup.new(volume_group_json).convert
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,32 +40,25 @@ class Drive < Base
include WithPartitions

# @see Base#convert
#
# @param drive_json [Hash]
# @return [Configs::Drive]
def convert(drive_json)
@drive_json = drive_json

def convert
super(Configs::Drive.new)
end

private

# @return [Hash]
attr_reader :drive_json
alias_method :drive_json, :config_json

# @see Base#conversions
#
# @param _config [Configs::Drive]
# @return [Hash]
def conversions(_config)
def conversions
{
search: convert_search(drive_json),
search: convert_search,
alias: drive_json[:alias],
encryption: convert_encryption(drive_json),
filesystem: convert_filesystem(drive_json),
ptable_type: convert_ptable_type(drive_json),
partitions: convert_partitions(drive_json)
encryption: convert_encryption,
filesystem: convert_filesystem,
ptable_type: convert_ptable_type,
partitions: convert_partitions
}
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,18 @@ module FromJSONConversions
# Encryption conversion from JSON hash according to schema.
class Encryption < Base
# @see Base#convert
#
# @param encryption_json [Hash, String]
# @return [Configs::Encryption]
def convert(encryption_json)
@encryption_json = encryption_json

def convert
super(Configs::Encryption.new)
end

private

# @return [Hash, String]
attr_reader :encryption_json
alias_method :encryption_json, :config_json

# @see Base#conversions
#
# @param _config [Configs::Encryption]
# @return [Hash]
def conversions(_config)
def conversions
return luks1_conversions if luks1?
return luks2_conversions if luks2?
return pervasive_luks2_conversions if pervasive_luks2?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,18 @@ module FromJSONConversions
# Filesystem conversion from JSON hash according to schema.
class Filesystem < Base
# @see Base#convert
#
# @param filesystem_json [Hash]
# @return [Configs::Filesystem]
def convert(filesystem_json)
@filesystem_json = filesystem_json

def convert
super(Configs::Filesystem.new)
end

private

# @return [Hash]
attr_reader :filesystem_json
alias_method :filesystem_json, :config_json

# @see Base#conversions
#
# @param _config [Configs::Filesystem]
# @return [Hash]
def conversions(_config)
def conversions
{
reuse: filesystem_json[:reuseIfPossible],
label: filesystem_json[:label],
Expand All @@ -74,7 +67,7 @@ def convert_type
filesystem_type_json = filesystem_json[:type]
return unless filesystem_type_json

FromJSONConversions::FilesystemType.new.convert(filesystem_type_json)
FromJSONConversions::FilesystemType.new(filesystem_type_json).convert
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,18 @@ module FromJSONConversions
# Filesystem type conversion from JSON hash according to schema.
class FilesystemType < Base
# @see Base#convert
#
# @param filesystem_type_json [Hash, String]
# @return [Configs::FilesystemType]
def convert(filesystem_type_json)
@filesystem_type_json = filesystem_type_json

def convert
super(Configs::FilesystemType.new)
end

private

# @return [Hash, String]
attr_reader :filesystem_type_json
alias_method :filesystem_type_json, :config_json

# @see Base#conversions
#
# @param _default [Configs::FilesystemType]
# @return [Hash]
def conversions(_default)
def conversions
{
fs_type: convert_type,
btrfs: convert_btrfs
Expand All @@ -70,7 +63,7 @@ def convert_btrfs
btrfs_json = filesystem_type_json[:btrfs]
return unless btrfs_json

FromJSONConversions::Btrfs.new.convert(btrfs_json)
FromJSONConversions::Btrfs.convert(btrfs_json).convert
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,36 +36,24 @@ class LogicalVolume < Base
include WithFilesystem
include WithSize

# @param logical_volume_json [Hash]
# @param config_builder [ConfigBuilder, nil]
def initialize(logical_volume_json, config_builder: nil)
super(config_builder)
@logical_volume_json = logical_volume_json
end

# @see Base#convert
#
# @param default [Configs::LogicalVolume, nil]
# @return [Configs::LogicalVolume]
def convert(default = nil)
super(default || Configs::LogicalVolume.new)
def conver
super(Configs::LogicalVolume.new)
end

private

# @return [Hash]
attr_reader :logical_volume_json
alias_method :logical_volume_json, :config_json

# @see Base#conversions
#
# @param default [Configs::LogicalVolume]
# @return [Hash]
def conversions(default)
def conversions
{
alias: logical_volume_json[:alias],
encryption: convert_encryption(logical_volume_json, default: default.encryption),
filesystem: convert_filesystem(logical_volume_json, default: default.filesystem),
size: convert_size(logical_volume_json, default: default.size),
encryption: convert_encryption,
filesystem: convert_filesystem,
size: convert_size,
name: logical_volume_json[:name],
stripes: logical_volume_json[:stripes],
stripe_size: convert_stripe_size,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,7 @@ class Partition < Base
include WithFilesystem
include WithSize

# @param partition_json [Hash]
def initialize(partition_json)
super(partition_json)
end

# @see Base#convert
#
# @return [Configs::Partition]
def convert
super(Configs::Partition.new)
Expand All @@ -55,16 +49,14 @@ def convert
alias_method :partition_json, :config_json

# @see Base#conversions
#
# @param default [Configs::Partition]
# @return [Hash]
def conversions(default)
def conversions
{
search: convert_search(partition_json),
search: convert_search,
alias: partition_json[:alias],
encryption: convert_encryption(partition_json),
filesystem: convert_filesystem(partition_json),
size: convert_size(partition_json),
encryption: convert_encryption,
filesystem: convert_filesystem,
size: convert_size,
id: convert_id,
delete: partition_json[:delete],
delete_if_needed: partition_json[:deleteIfNeeded]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,18 @@ module FromJSONConversions
# Search conversion from JSON hash according to schema.
class Search < Base
# @see Base#convert
#
# @param search_json [Hash, String]
# @return [Configs::Search]
def convert(search_json)
@search_json = search_json

def convert
super(Configs::Search.new)
end

private

# @return [Hash, String]
attr_reader :search_json
alias_method :search_json, :config_json

# @see Base#conversions
#
# @param _config [Configs::Partition]
# @return [Hash]
def conversions(_config)
def conversions
{
name: convert_name,
if_not_found: convert_not_found
Expand Down
Loading

0 comments on commit 50fcc92

Please sign in to comment.