Previously, to enable UBIDs, one would need to define ubid_type function in the each respective model file. However, this function works same for each model; the difference is it returns different constant. With some string manipulation, it is possible to generate the name of the constant. Sequel and we already use similar inflictions to make things feel more "magical", so I don't have much concerns regarding generating constant names via string manipulation. Thanks to this commit, we don't need to define ubid_type for each model anymore. Similarly we also don't need to add new type to when/case block in ubid.rb While doing this, I found two unused constants and removed them. Also slightly modified two other constants' names to match it with the class names. Finally, as a small bonus, we reduced the line count by 77 and unit tests now complete 0.2 seconds faster. Possibly due to removing long when/case block.
11 lines
212 B
Ruby
11 lines
212 B
Ruby
# frozen_string_literal: true
|
|
|
|
require_relative "../model"
|
|
|
|
class AssignedHostAddress < Sequel::Model
|
|
many_to_one :vm_host, key: :host_id
|
|
many_to_one :address, key: :address_id
|
|
|
|
include ResourceMethods
|
|
end
|