Class: Card::Fetch

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

Overview

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

Defined Under Namespace

Modules: All, CardClass, 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
# File 'card/lib/card/fetch.rb', line 11

def initialize *args
  normalize_args args
  validate_opts!
end

Instance Attribute Details

#cardObject (readonly)

Returns the value of attribute card.



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

def card
  @card
end

#markObject (readonly)

Returns the value of attribute mark.



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

def mark
  @mark
end

#optsObject (readonly)

Returns the value of attribute opts.



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

def opts
  @opts
end

Instance Method Details

#local_only?Boolean

Returns:

  • (Boolean)


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

def local_only?
  opts[:local_only]
end

#look_in_trash?Boolean

Returns:

  • (Boolean)


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

def look_in_trash?
  @opts[:look_in_trash]
end

#normalize_args(args) ⇒ Object



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

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

#normalize_markObject



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

def normalize_mark
  return unless mark.name?

  supercard = opts.dig :new, :supercard
  @mark = mark.absolute_name supercard.name if supercard
end

#retrieve_or_newObject



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

def retrieve_or_new
  retrieve_existing
  update_cache
  results
end

#skip_modules?Boolean

Returns:

  • (Boolean)


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

def skip_modules?
  opts[:skip_modules]
end

#skip_type_lookup?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'card/lib/card/fetch.rb', line 53

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

#validate_opts!Object

Raises:



43
44
45
46
47
# File 'card/lib/card/fetch.rb', line 43

def validate_opts!
  return unless opts[:new] && opts[:skip_virtual]

  raise Card::Error, "fetch called with new args and skip_virtual"
end