Module: Card::Cache::Populate
- Included in:
- ClassMethods
- Defined in:
- card/lib/card/cache/populate.rb
Overview
population-related class methods for Card::Cache
Instance Method Summary collapse
-
#populate_fields(list, *fields) ⇒ Object
-
#populate_ids(ids) ⇒ Object
-
#populate_names(names) ⇒ Object
Instance Method Details
#populate_fields(list, *fields) ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'card/lib/card/cache/populate.rb', line 28 def populate_fields list, *fields name_arrays = list.each_with_object([]) do |item, arrays| fields.flatten.each do |field| arrays << [item, field] end end populate_names name_arrays end |
#populate_ids(ids) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'card/lib/card/cache/populate.rb', line 5 def populate_ids ids # use ids to look up names results = Lexicon.cache.read_multi(ids.map(&:to_s)).values names = [] pairs = [] results.each do |result| result.is_a?(String) ? (names << result) : (pairs << result) end if pairs.any? populate_ids pairs.flatten names += pairs.map(&:cardname) end # use keys to look up populate_names names end |