From fb6d6fce5a4d0fd833dc1cd231dd284a6c89471a Mon Sep 17 00:00:00 2001 From: Andreas Brandl Date: Fri, 16 Mar 2018 13:34:08 +0100 Subject: Address review comments. --- app/models/internal_id.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'app/models/internal_id.rb') diff --git a/app/models/internal_id.rb b/app/models/internal_id.rb index f3630ed1ac5..cbec735c2dd 100644 --- a/app/models/internal_id.rb +++ b/app/models/internal_id.rb @@ -66,6 +66,7 @@ class InternalId < ActiveRecord::Base # scope: Attributes that define the scope for id generation. # usage: Symbol to define the usage of the internal id, see InternalId.usages # init: Block that gets called to initialize InternalId record if not present + # Make sure to not throw exceptions in the absence of records (if this is expected). attr_reader :subject, :scope, :init, :scope_attrs, :usage def initialize(subject, scope, usage, init) @@ -74,9 +75,9 @@ class InternalId < ActiveRecord::Base @init = init @usage = usage - raise ArgumentError, 'scope is not well-defined, need at least one column for scope (given: 0)' if scope.empty? + raise ArgumentError, 'Scope is not well-defined, need at least one column for scope (given: 0)' if scope.empty? - unless InternalId.usages.keys.include?(usage.to_s) + unless InternalId.usages.has_key?(usage.to_s) raise ArgumentError, "Usage '#{usage}' is unknown. Supported values are #{InternalId.usages.keys} from InternalId.usages" end end @@ -85,7 +86,7 @@ class InternalId < ActiveRecord::Base def generate subject.transaction do # Create a record in internal_ids if one does not yet exist - # and increment it's last value + # and increment its last value # # Note this will acquire a ROW SHARE lock on the InternalId record (lookup || create_record).increment_and_save! -- cgit v1.2.3