Class: Card::Fetch

Inherits:
Object
  • Object
show all
Includes:
Results, Retrieve, Store
Defined in:
lib/card/fetch.rb,
lib/card/fetch/store.rb,
lib/card/fetch/results.rb,
lib/card/fetch/retrieve.rb

Overview

retrieve card from cache or database, or (where needed) instantiate new card

Defined Under Namespace

Modules: Results, Retrieve, Store

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Store

#cache_ready?, #eager_caching?, #needs_prep?, #new_card_needed?, #new_for_cache, #new_for_cache?, #prep_for_cache, #reusable?, #update_cache, #update_cache?

Methods included from Results

#assign_name_from_mark, #assignable_content, #fancy_renew?, #finalize_result_card, #name_change?, #new_opts, #new_result_card, #newish_opts, #quick_content, #quick_renew, #quick_renew?, #renew, #results, #supercard_might_change_type?, #type_change?, #type_id_from_new_opts, #update_supercard, #with_new_card

Methods included from Retrieve

#id_from_mark, #mark_type, #mark_value, #retrieval_from_db_query, #retrieval_from_db_query_base, #retrieve_existing, #retrieve_from_cache, #retrieve_from_db

Constructor Details

#initialize(*args) ⇒ Fetch

see arg options in all/fetch



11
12
13
14
15
# File 'lib/card/fetch.rb', line 11

def initialize *args
  normalize_args args
  absolutize_mark
  validate_opts!
end

Instance Attribute Details

#cardObject (readonly)

Returns the value of attribute card.



8
9
10
# File 'lib/card/fetch.rb', line 8

def card
  @card
end

#markObject (readonly)

Returns the value of attribute mark.



8
9
10
# File 'lib/card/fetch.rb', line 8

def mark
  @mark
end

#optsObject (readonly)

Returns the value of attribute opts.



8
9
10
# File 'lib/card/fetch.rb', line 8

def opts
  @opts
end

Instance Method Details

#absolutize_markObject



36
37
38
39
# File 'lib/card/fetch.rb', line 36

def absolutize_mark
  return unless mark.name? && (supercard = opts.dig(:new, :supercard))
  @mark = mark.absolute_name supercard.name
end

#local_only?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/card/fetch.rb', line 23

def local_only?
  opts[:local_only]
end

#look_in_trash?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/card/fetch.rb', line 46

def look_in_trash?
  @opts[:look_in_trash]
end

#normalize_args(args) ⇒ Object



31
32
33
34
# File 'lib/card/fetch.rb', line 31

def normalize_args args
  @opts = args.last.is_a?(Hash) ? args.pop : {}
  @mark = Card.id_or_name args
end

#retrieve_or_newObject



17
18
19
20
21
# File 'lib/card/fetch.rb', line 17

def retrieve_or_new
  retrieve_existing
  update_cache
  results
end

#skip_modules?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/card/fetch.rb', line 27

def skip_modules?
  opts[:skip_modules]
end

#skip_type_lookup?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/card/fetch.rb', line 50

def skip_type_lookup?
  opts[:skip_virtual] || opts[:skip_type_lookup] # || opts[:new]
end

#validate_opts!Object

Raises:



41
42
43
44
# File 'lib/card/fetch.rb', line 41

def validate_opts!
  return unless opts[:new] && opts[:skip_virtual]
  raise Card::Error, "fetch called with new args and skip_virtual"
end