Skip to content

Commit

Permalink
nix the string interpolation
Browse files Browse the repository at this point in the history
thanks Keenan and Jason :)
  • Loading branch information
d-m-u committed May 8, 2020
1 parent 341ece6 commit 3658d3e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 2 additions & 3 deletions app/models/mixins/aggregation_mixin/methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,11 @@ def all_storages
end

def aggregate_hardware(from, field, targets = nil)
from = from.to_s.singularize
from = from.to_s.singularize.to_sym
select = field == :aggregate_cpu_speed ? "cpu_total_cores, cpu_speed" : field
targets ||= send("all_#{from}_ids")
targets = targets.collect(&:id) unless targets.first.kind_of?(Integer)
hdws = Hardware.where("#{from}_id".to_sym => targets).select(select)

hdws = Hardware.where(from => targets).select(select)
hdws.inject(0) { |t, hdw| t + hdw.send(field).to_i }
end

Expand Down
7 changes: 7 additions & 0 deletions spec/models/mixins/aggregation_mixin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,13 @@
end
end

describe "aggregate_hardware" do
it "calculates from hosts" do
cluster = cluster_2_1_host(hardware_args)
expect(cluster.aggregate_hardware("host", :aggregate_cpu_speed)).to eq(cpu_speed * 2)
end
end

private

def cluster_2_1_host(hardware_args)
Expand Down

0 comments on commit 3658d3e

Please sign in to comment.