Class: Card::Codename
- Inherits:
-
Object
- Object
- Card::Codename
- Defined in:
- lib/card/codename.rb
Overview
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.
An administrator might add to the Company card via the RESTful web API with a url like
/update/CARDNAME?card[codename]=CODENAME
...or via the api like
Card[CARDNAME].update_attributes! 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
Class Method Summary collapse
-
.[](key) ⇒ String, Integer
returns codename for id and id for codename.
-
.codehash ⇒ Hash
a Hash in which String keys have Integer values and vice versa.
-
.reset_cache ⇒ Object
clear cache both locally and in cache.
Class Method Details
.[](key) ⇒ String, Integer
returns codename for id and id for codename
28 29 30 31 |
# File 'lib/card/codename.rb', line 28 def [] key return if key.nil? codehash[key.is_a?(Integer) ? key : key.to_sym] end |
.codehash ⇒ Hash
a Hash in which String keys have Integer values and vice versa
35 36 37 |
# File 'lib/card/codename.rb', line 35 def codehash @codehash ||= load_codehash end |