Module: Card::Fetch::CardClass
- Included in:
- Card
- Defined in:
- lib/card/fetch/card_class.rb
Overview
A multipurpose retrieval system that integrates caching, database lookups, and “virtual” card construction
Instance Method Summary collapse
-
#[](*mark) ⇒ Card
a shortcut for fetch that returns only real cards (no virtuals).
-
#fetch(*args) ⇒ Card
Look for cards in * cache * database * virtual cards.
- #fetch_from_cast(cast) ⇒ Card
-
#fetch_name(*mark) ⇒ Card::Name
DEPRECATED - use mark.cardname.
- #fetch_type_id(*mark) ⇒ Integer
-
#id(cardish) ⇒ Integer
numerical card id.
-
#quick_fetch(*mark) ⇒ Card
fetch real cards without set modules loaded.
-
#uri_fetch(params) ⇒ Object
Specialized fetching appropriate for cards requested by URI.
Instance Method Details
#[](*mark) ⇒ Card
a shortcut for fetch that returns only real cards (no virtuals)
42 43 44 |
# File 'lib/card/fetch/card_class.rb', line 42 def [] *mark fetch(*mark, skip_virtual: true) end |
#fetch(*args) ⇒ Card
Look for cards in
* cache
* database
* virtual cards
31 32 33 34 35 36 |
# File 'lib/card/fetch/card_class.rb', line 31 def fetch *args f = Fetch.new(*args) f.retrieve_or_new rescue ActiveModel::RangeError => _e Card.new name: "card id out of range: #{f.mark}" end |
#fetch_from_cast(cast) ⇒ Card
59 60 61 62 |
# File 'lib/card/fetch/card_class.rb', line 59 def fetch_from_cast cast fetch_args = cast[:id] ? [cast[:id].to_i] : [cast[:name], { new: cast }] fetch(*fetch_args) end |
#fetch_name(*mark) ⇒ Card::Name
DEPRECATED
-
use mark.cardname
86 87 88 |
# File 'lib/card/fetch/card_class.rb', line 86 def fetch_name *mark quick_fetch(*mark)&.name end |
#fetch_type_id(*mark) ⇒ Integer
92 93 94 |
# File 'lib/card/fetch/card_class.rb', line 92 def fetch_type_id *mark fetch(*mark, skip_modules: true)&.type_id end |
#id(cardish) ⇒ Integer
numerical card id
71 72 73 74 75 76 77 78 79 |
# File 'lib/card/fetch/card_class.rb', line 71 def id cardish case cardish when Integer then cardish when Card then cardish.id when Symbol then Codename.id cardish when String then Lexicon.id cardish else quick_fetch(cardish)&.id end end |
#quick_fetch(*mark) ⇒ Card
fetch real cards without set modules loaded. Should only be used for simple attributes
54 55 56 |
# File 'lib/card/fetch/card_class.rb', line 54 def quick_fetch *mark fetch(*mark, skip_virtual: true, skip_modules: true) end |
#uri_fetch(params) ⇒ Object
Specialized fetching appropriate for cards requested by URI
104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/card/fetch/card_class.rb', line 104 def uri_fetch params card_opts = uri_fetch_opts params if params[:action] == "create" # FIXME: we currently need a "new" card to catch duplicates # (otherwise save will just act like a normal update) # We may need a "#create" instance method to handle this checking? Card.new card_opts else standard_uri_fetch params, card_opts end end |