Skip to content

Commit

Permalink
style: code cleanup (nanego#327)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-brousse authored Feb 5, 2025
1 parent df2d7f0 commit 5031ace
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 160 deletions.
167 changes: 44 additions & 123 deletions .rubocop_todo.yml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app/components/list/data_table_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def initialize(data, empty_icon: :table, **_options)

def call
if @data.empty?
render CardComponent.new(extra_classes: "text-center text-secondary-emphasis") do |card|
render CardComponent.new(extra_classes: "text-center text-secondary-emphasis") do
concat(tag.i(class: "bi bi-#{@empty_icon} fs-1 text-secondary text-opacity-25"))
concat(tag.h5(t(".empty_table.title"), class: "card-title mt-3"))
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/modeles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def index
@filter = ProcessorFilter.new(Modele.includes(:category, :enclosures).order(:name), params)
@modeles = @filter.results

@types = @modeles.group_by { |m| m.category.name }.sort_by { |categorie, modeles| categorie.to_s }
@types = @modeles.group_by { |m| m.category.name }.sort_by { |categorie, _modeles| categorie.to_s }
end

def show
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/moves_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ def update_connection
@moved_connections = MovedConnection.per_servers(@servers)

@current_moved_connections = @moved_connections.where('port_from_id IN (?) OR port_to_id IN (?)',
[params[:moved_connection][:port_from_id], params[:moved_connection][:port_to_id]],
[params[:moved_connection][:port_from_id], params[:moved_connection][:port_to_id]])
[params[:moved_connection][:port_from_id], params[:moved_connection][:port_to_id]],
[params[:moved_connection][:port_from_id], params[:moved_connection][:port_to_id]])

if @current_moved_connections.present?
if @current_moved_connections.size > 1
Expand Down
8 changes: 4 additions & 4 deletions app/models/frame.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ def name_with_room_and_islet
def self.to_txt(servers_per_bay, detail)
txt = []
if servers_per_bay.present?
servers_per_bay.each do |islet, lanes|
lanes.each do |lane, bays|
bays.each do |bay, frames|
frames.each do |frame, servers|
servers_per_bay.each do |_islet, lanes|
lanes.each do |_lane, bays|
bays.each do |_bay, frames|
frames.each do |frame, _servers|
txt << frame.to_txt(detail)
end
end
Expand Down
12 changes: 6 additions & 6 deletions app/services/glpi_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@ def init_session

def stubs
Faraday::Adapter::Test::Stubs.new do |stub|
stub.get('/Computer?searchText%5Bserial%5D=AZERTY') { |env| [200, {}, File.read(Rails.root.join('test', 'services', 'computers_results.json'))] }
stub.get(/\/Computer\/4090?.*/) { |env| [200, {}, File.read(Rails.root.join('test', 'services', 'computer_4090_algori.json'))] }
stub.get(/\/DeviceProcessor\/28?.*/) { |env| [200, {}, File.read(Rails.root.join('test', 'services', 'processor_28.json'))] }
stub.get('/initSession') { |env| [200, {}, '{"session_token":"kuji8uh4v77lgghqoj2c0r2848"}'] }
stub.get('/Computer?searchText%5Bserial%5D=AZERTY') { |_env| [200, {}, File.read(Rails.root.join('test', 'services', 'computers_results.json'))] }
stub.get(/\/Computer\/4090?.*/) { |_env| [200, {}, File.read(Rails.root.join('test', 'services', 'computer_4090_algori.json'))] }
stub.get(/\/DeviceProcessor\/28?.*/) { |_env| [200, {}, File.read(Rails.root.join('test', 'services', 'processor_28.json'))] }
stub.get('/initSession') { |_env| [200, {}, '{"session_token":"kuji8uh4v77lgghqoj2c0r2848"}'] }
end
end

Expand All @@ -130,13 +130,13 @@ class Computer < Dry::Struct
def hard_drives_total_capacity
return 0 if hard_drives.blank?

hard_drives.sum { |key, value| value['capacity'] }
hard_drives.sum { |_key, value| value['capacity'] }
end

def memories_total_size
return 0 if memories.blank?

memories.sum { |key, value| value['size'] }
memories.sum { |_key, value| value['size'] }
end
end
end
2 changes: 1 addition & 1 deletion config/initializers/field_with_errors.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

ActionView::Base.field_error_proc = proc do |html_tag, instance|
ActionView::Base.field_error_proc = proc do |html_tag, _instance|
html_tag.html_safe # rubocop:disable Rails/OutputSafety
end
30 changes: 15 additions & 15 deletions db/migrate/20180110152701_add_attributes_to_servers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,44 +65,44 @@ def init_pdus_for_every_frames
category = MigrationCategory.create(name: 'Pdu')
puts "ERROR: #{category}" unless category.valid?
modele = MigrationModele.create(name: 'Pdu 24',
category: category)
category: category)
puts "ERROR: #{modele}" unless modele.valid?
enclosure = MigrationEnclosure.create(modele: modele,
position: 1,
display: 'vertical')
position: 1,
display: 'vertical')
puts "ERROR: #{enclosure}" unless enclosure.valid?
type_composant = MigrationTypeComposant.find_by_name('SLOT')
puts "ERROR: #{type_composant}" unless type_composant.valid?
4.times do |i|
line = (i + 1).odd? ? 'L1' : 'L2'
composant = MigrationComposant.create(type_composant: type_composant,
position: i + 1,
enclosure: enclosure,
name: "ALIM_#{line}")
position: i + 1,
enclosure: enclosure,
name: "ALIM_#{line}")
puts "ERROR: #{composant}" unless composant.valid?
end

port_type = MigrationPortType.find_by_name('ALIM')
puts "ERROR: #{port_type}" unless port_type.valid?
card_type = MigrationCardType.find_or_create_by(name: '6ALIM',
port_quantity: 6,
port_type: port_type)
port_quantity: 6,
port_type: port_type)
puts "ERROR: #{card_type}" unless card_type.valid?

MigrationFrame.all.find_each do |frame|
%w[A B].each do |line_name|
pdu_name = "PDU_#{frame}_#{line_name}"
pdu = MigrationServer.create(frame: frame,
modele: modele,
numero: pdu_name,
name: pdu_name,
side: Pdu.calculated_side(frame, line_name),
color: line_name == 'A' ? 'J' : 'B')
modele: modele,
numero: pdu_name,
name: pdu_name,
side: Pdu.calculated_side(frame, line_name),
color: line_name == 'A' ? 'J' : 'B')
puts "ERROR: #{pdu}" unless pdu.valid?
enclosure.composants.each do |composant|
card = MigrationCard.create(card_type: card_type,
server: pdu,
composant: composant)
server: pdu,
composant: composant)
puts "ERROR: #{card}" unless card.valid?
end
end
Expand Down
14 changes: 7 additions & 7 deletions spec/components/previews/card_component_preview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,44 @@
class CardComponentPreview < ViewComponent::Preview
# @param type select { choices: [default, primary, success, info, warning, danger] }
def default(type: :default)
render CardComponent.new(type:) do |card|
render CardComponent.new(type:) do
tag.p "Season fifteen oz of watermelon in one container of gold tequila."
end
end

# @!group Types
def type_default
render CardComponent.new(type: :default) do |card|
render CardComponent.new(type: :default) do
tag.p "Season fifteen oz of watermelon in one container of gold tequila."
end
end

def type_primary
render CardComponent.new(type: :primary) do |card|
render CardComponent.new(type: :primary) do
tag.p "Season fifteen oz of watermelon in one container of gold tequila."
end
end

def type_success
render CardComponent.new(type: :success) do |card|
render CardComponent.new(type: :success) do
tag.p "Season fifteen oz of watermelon in one container of gold tequila."
end
end

def type_info
render CardComponent.new(type: :info) do |card|
render CardComponent.new(type: :info) do
tag.p "Season fifteen oz of watermelon in one container of gold tequila."
end
end

def type_warning
render CardComponent.new(type: :warning) do |card|
render CardComponent.new(type: :warning) do
tag.p "Season fifteen oz of watermelon in one container of gold tequila."
end
end

def type_danger
render CardComponent.new(type: :danger) do |card|
render CardComponent.new(type: :danger) do
tag.p "Season fifteen oz of watermelon in one container of gold tequila."
end
end
Expand Down

0 comments on commit 5031ace

Please sign in to comment.