lib/card/codename.rb in card-1.96.8 vs lib/card/codename.rb in card-1.97.0
- old
+ new
@@ -1,14 +1,16 @@
# -*- encoding : utf-8 -*-
+
require_dependency "card/cache"
require_dependency "card/name"
class Card
- # {Card}'s names can be changed, and therefore _names_ should not be directly mentioned in code, lest a name change break the application.
+ # {Card}'s names can be changed, and therefore _names_ should not be directly mentioned
+ # in code, lest a name change break the application.
#
- # Instead, a {Card} that needs specific code manipulations should be given a {Codename}, which will not change even if the card's name
- # does.
+ # Instead, a {Card} that needs specific code manipulations should be given a {Codename},
+ # which will not change even if the card's name does.
#
# An administrator might add to the Company card via the RESTful web API with a url like
#
# /update/CARDNAME?card[codename]=CODENAME
#
@@ -16,11 +18,12 @@
#
# Card[CARDNAME].update! codename: CODENAME
#
# Generally speaking, _codenames_ are represented by Symbols.
#
- # The {Codename} class provides a fast cache for this slow-changing data. Every process maintains a complete cache that is not frequently reset
+ # The {Codename} class provides a fast cache for this slow-changing data.
+ # Every process maintains a complete cache that is not frequently reset
#
class Codename
class << self
# returns codename for id and id for codename
# @param key [Integer, Symbol, String, Card::Name]
@@ -100,10 +103,11 @@
end
# @todo remove duplicate checks here; should be caught upon creation
def check_duplicates codehash, codename, card_id
return unless codehash.key?(codename) || codehash.key?(card_id)
+
Rails.logger.debug "dup codename: #{codename}, "\
"ID:#{card_id} (#{codehash[codename]})"
end
# generate Hash for @codehash and put it in the cache
@@ -123,12 +127,12 @@
hash
end
def unknown_codename! mark
raise Card::Error::CodenameNotFound, I18n.t(:exception_unknown_codename,
- scope: "lib.card.codename",
- codename: mark)
+ scope: "lib.card.codename",
+ codename: mark)
end
end
end
# If a card has the codename _example_, then Card::ExampleID should
@@ -137,9 +141,10 @@
# @param const [Const]
# @return [Integer]
# @raise error if codename is missing
def self.const_missing const
return super unless const.to_s =~ /^([A-Z]\S*)ID$/
+
code = Regexp.last_match(1).underscore
code_id = Card::Codename.id!(code)
const_set const, code_id
end
end