Module: Card::Set::All::Fetch::ClassMethods
- Defined in:
- tmpsets/set/mod003-core/all/fetch.rb
Overview
and "virtual" card construction
Instance Method Summary collapse
-
#[](*mark) ⇒ Card
fetch only real (no virtual) cards.
-
#fetch(*args) ⇒ Card
Look for cards in * cache * database * virtual cards.
- #fetch_from_cast(cast) ⇒ Card
- #fetch_id(*mark) ⇒ Integer
- #fetch_name(*mark) ⇒ Card::Name
-
#fetch_soft(*args) ⇒ Card
fetch only from the soft cache.
- #fetch_type_id(*mark) ⇒ Integer
-
#id(cardish) ⇒ Object
---------------------------------------------------------------------- ATTRIBUTE FETCHING The following methods optimize fetching of specific attributes.
-
#quick_fetch(*mark) ⇒ Card
fetch real cards without set modules loaded.
Instance Method Details
#[](*mark) ⇒ Card
fetch only real (no virtual) cards
48 49 50 |
# File 'tmpsets/set/mod003-core/all/fetch.rb', line 48 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 37 38 39 40 41 42 |
# File 'tmpsets/set/mod003-core/all/fetch.rb', line 31 def fetch *args mark, opts = normalize_fetch_args args validate_fetch_opts! opts card, needs_caching = retrieve_or_new mark, opts return if card.nil? write_to_cache card, opts[:local_only] if needs_caching standard_fetch_results card, mark, opts rescue ActiveModel::RangeError => _e return Card.new name: "card id out of range: #{mark}" end |
#fetch_from_cast(cast) ⇒ Card
72 73 74 75 |
# File 'tmpsets/set/mod003-core/all/fetch.rb', line 72 def fetch_from_cast cast fetch_args = cast[:id] ? [cast[:id].to_i] : [cast[:name], { new: cast }] fetch *fetch_args end |
#fetch_id(*mark) ⇒ Integer
92 93 94 95 96 97 |
# File 'tmpsets/set/mod003-core/all/fetch.rb', line 92 def fetch_id *mark mark, _opts = normalize_fetch_args mark return mark if mark.is_a? Integer card = quick_fetch mark.to_s card && card.id end |
#fetch_name(*mark) ⇒ Card::Name
101 102 103 104 105 106 107 108 109 110 111 |
# File 'tmpsets/set/mod003-core/all/fetch.rb', line 101 def fetch_name *mark if (card = quick_fetch(mark)) card.name elsif block_given? yield.to_name end rescue ActiveModel::RangeError => _e block_given? ? yield.to_name : nil rescue Card::Error::CodenameNotFound => e block_given? ? yield.to_name : raise(e) end |
#fetch_soft(*args) ⇒ Card
fetch only from the soft cache
66 67 68 69 |
# File 'tmpsets/set/mod003-core/all/fetch.rb', line 66 def fetch_soft *args mark, opts = normalize_fetch_args args fetch mark, opts.merge(local_only: true) end |
#fetch_type_id(*mark) ⇒ Integer
115 116 117 |
# File 'tmpsets/set/mod003-core/all/fetch.rb', line 115 def fetch_type_id *mark (card = quick_fetch(mark)) && card.type_id end |
#id(cardish) ⇒ Object
ATTRIBUTE FETCHING The following methods optimize fetching of specific attributes
81 82 83 84 85 86 87 88 |
# File 'tmpsets/set/mod003-core/all/fetch.rb', line 81 def id cardish case cardish when Integer then cardish when Card then cardish.id when Symbol then Card::Codename.id cardish else fetch_id cardish end end |
#quick_fetch(*mark) ⇒ Card
fetch real cards without set modules loaded. Should only be used for simple attributes
58 59 60 |
# File 'tmpsets/set/mod003-core/all/fetch.rb', line 58 def quick_fetch *mark fetch mark, skip_virtual: true, skip_modules: true end |