Only support single scope argument.

We can extend this later, but for now we don't have the use case.
This commit is contained in:
Andreas Brandl 2018-03-14 14:36:07 +01:00
parent 4c1e6fd0e8
commit bc3fc8ec3e

View file

@ -28,11 +28,9 @@ module AtomicInternalId
def has_internal_id(on, scope:, usage: nil, init:) # rubocop:disable Naming/PredicateName def has_internal_id(on, scope:, usage: nil, init:) # rubocop:disable Naming/PredicateName
before_validation(on: :create) do before_validation(on: :create) do
if self.public_send(on).blank? # rubocop:disable GitlabSecurity/PublicSend if self.public_send(on).blank? # rubocop:disable GitlabSecurity/PublicSend
scope_attrs = [scope].flatten.compact.each_with_object({}) do |e, h| scope_attrs = { scope => self.public_send(scope) } # rubocop:disable GitlabSecurity/PublicSend
h[e] = self.public_send(e) # rubocop:disable GitlabSecurity/PublicSend
end
usage = (usage || self.class.table_name).to_sym usage = (usage || self.class.table_name).to_sym
new_iid = InternalId.generate_next(self, scope_attrs, usage, init) new_iid = InternalId.generate_next(self, scope_attrs, usage, init)
self.public_send("#{on}=", new_iid) # rubocop:disable GitlabSecurity/PublicSend self.public_send("#{on}=", new_iid) # rubocop:disable GitlabSecurity/PublicSend
end end