module Card::Fetch::Retrieve
retrieval and instantiation methods for Card::Fetch
Public Instance Methods
Source
# File lib/card/fetch/retrieve.rb, line 43 def id_from_mark mark_type == :id ? mark_value : Lexicon.id(mark_value) end
Source
# File lib/card/fetch/retrieve.rb, line 49 def mark_type @mark_type ||= mark.is_a?(Integer) ? :id : :key end
In both the cache and the db, ids and keys are used to retrieve card data. These methods identify the kind of mark to use and its value
Source
# File lib/card/fetch/retrieve.rb, line 53 def mark_value @mark_value ||= mark.is_a?(Integer) ? mark : mark.key end
Source
# File lib/card/fetch/retrieve.rb, line 28 def retrieval_from_db_query return unless (query = retrieval_from_db_query_base) query[:trash] = false unless look_in_trash? query end
Source
# File lib/card/fetch/retrieve.rb, line 35 def retrieval_from_db_query_base if mark_type == :key && mark.simple? { key: mark_value } elsif (id = id_from_mark) { id: id } end end
Source
# File lib/card/fetch/retrieve.rb, line 6 def retrieve_existing return unless mark.present? retrieve_from_cache || retrieve_from_db end
look for card in cache. if that doesn’t work, look in database
Source
# File lib/card/fetch/retrieve.rb, line 12 def retrieve_from_cache @card = Card.send "retrieve_from_cache_by_#{mark_type}", mark_value, @opts[:local_only] @card = nil if card&.new? && look_in_trash? # don't return cached cards if looking in trash - # we want the db version card end
Source
# File lib/card/fetch/retrieve.rb, line 21 def retrieve_from_db query = retrieval_from_db_query @card = query ? Card.where(query).take : nil @fresh_from_db = true if card.present? && !card.trash card end