Skip to content

Commit

Permalink
format with rubocop
Browse files Browse the repository at this point in the history
  • Loading branch information
jreidinger committed Dec 18, 2024
1 parent e7fcd3d commit ea7a708
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 34 deletions.
3 changes: 3 additions & 0 deletions service/.rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@ Metrics/AbcSize:

Metrics/ParameterLists:
Max: 6

Metrics/ClassLength:
Max: 300
12 changes: 6 additions & 6 deletions service/lib/agama/dbus/storage/manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def deprecated_system
#
# @param serialized_config [String] Serialized storage config.
# @return [Integer] 0 success; 1 error
def set_bootloader_config(serialized_config)
def load_bootloader_config_from_json(serialized_config)
logger.info("Setting bootloader config from D-Bus: #{serialized_config}")

bootloader.config.load_json(serialized_config)
Expand All @@ -163,17 +163,17 @@ def set_bootloader_config(serialized_config)
# Gets and serializes the storage config used to calculate the current proposal.
#
# @return [String] Serialized config according to the JSON schema.
def get_bootloader_config
def bootloader_config_as_json
bootloader.config.to_json
end

dbus_interface BOOTLOADER_INTERFACE do
dbus_method(:SetConfig, "in serialized_config:s, out result:u") do |serialized_config|
set_bootloader_config(serialized_config)
load_bootloader_config_from_json(serialized_config)
end
dbus_method(:GetConfig, "out serialized_config:s") do
bootloader_config_as_json
end
dbus_method(:GetConfig, "out serialized_config:s") {
get_bootloader_config
}
end

# @todo Move device related properties here, for example, the list of system and staging
Expand Down
12 changes: 6 additions & 6 deletions service/lib/agama/storage/bootloader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@

module Agama
module Storage
# Represents bootloader specific functionality
class Bootloader
# Represents bootloader settings
class Config
# If boot menu is forced to wait for user input
attr_accessor :force_user_input

def to_json
def to_json(*_args)
result = {}

# our json use camel case
Expand All @@ -40,9 +42,7 @@ def to_json

def load_json(serialized_config)
hsh = JSON.parse(serialized_config, symbolize_names: true)
if hsh.include?(:forceUserInput)
self.force_user_input = hsh[:forceUserInput]
end
self.force_user_input = hsh[:forceUserInput] if hsh.include?(:forceUserInput)
end
end

Expand All @@ -67,8 +67,8 @@ def write_config
@logger.info "bootloader #{bootloader.name} does not support forcing user input"
end
when false
# TODO: basically as we have single argument we repropose here. If more attributes comes
# we will need to do always propose first and then modify what is in config set
# TODO: basically as we have single argument we repropose here. If more attributes comes
# we will need to do always propose first and then modify what is in config set
bootloader.propose
when nil
# not set, so do nothing and keep it as it is
Expand Down
4 changes: 2 additions & 2 deletions service/lib/agama/storage/manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def initialize(config, logger)

@config = config
@logger = logger
@bootloader = Bootloader::new(logger)
@bootloader = Bootloader.new(logger)
register_proposal_callbacks
on_progress_change { logger.info progress.to_s }
end
Expand Down Expand Up @@ -132,7 +132,7 @@ def install
# first make bootloader proposal to be sure that required packages are installed
proposal = ::Bootloader::ProposalClient.new.make_proposal({})
# then also apply changes to that proposal
self.bootloader.write_config
bootloader.write_config
logger.debug "Bootloader proposal #{proposal.inspect}"
end
progress.step(_("Adding storage-related packages")) { add_packages }
Expand Down
40 changes: 20 additions & 20 deletions service/test/agama/storage/bootloader_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,28 @@
require "agama/storage/bootloader"

describe Agama::Storage::Bootloader::Config do
subject(:config) { described_class.new }
subject(:config) { described_class.new }

describe "#to_json" do
it "serializes its content with keys as camelCase" do
config.force_user_input = true
expect(config.to_json).to eq "{\"forceUserInput\":true}"
end
describe "#to_json" do
it "serializes its content with keys as camelCase" do
config.force_user_input = true
expect(config.to_json).to eq "{\"forceUserInput\":true}"
end

it "can serialize in a way that #load_json can restore it" do
config.force_user_input = false
json = config.to_json
config.force_user_input = true
config.load_json(json)
expect(config.force_user_input).to eq false
end
it "can serialize in a way that #load_json can restore it" do
config.force_user_input = false
json = config.to_json
config.force_user_input = true
config.load_json(json)
expect(config.force_user_input).to eq false
end
end

describe "#load_json" do
it "loads config from given json" do
content = "{\"forceUserInput\":true}"
config.load_json(content)
expect(config.force_user_input).to eq true
end
describe "#load_json" do
it "loads config from given json" do
content = "{\"forceUserInput\":true}"
config.load_json(content)
expect(config.force_user_input).to eq true
end
end
end
end

0 comments on commit ea7a708

Please sign in to comment.