Module: Card::Set::All::Fetch

Extended by:
Card::Set
Defined in:
tmpsets/set/mod001-01_core/all/fetch.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Methods included from Card::Set

abstract_set?, all_set?, card_accessor, card_reader, card_writer, clean_empty_module_from_hash, clean_empty_modules, define_on_format, ensure_set, extended, format, process_base_module_list, process_base_modules, register_set, register_set_format, shortname, stage_method, view, write_tmp_file

Methods included from Event

#define_event, #event

Instance Method Details

#eager_renew?(opts) ⇒ Boolean

Returns:

  • (Boolean)


329
330
331
# File 'tmpsets/set/mod001-01_core/all/fetch.rb', line 329

def eager_renew? opts
  opts[:skip_virtual] && new_card? && opts[:new].present?
end

#expire(subcards = false) ⇒ Object



314
315
316
317
# File 'tmpsets/set/mod001-01_core/all/fetch.rb', line 314

def expire subcards=false
  expire_hard
  expire_soft subcards
end

#expire_hardObject



298
299
300
301
302
# File 'tmpsets/set/mod001-01_core/all/fetch.rb', line 298

def expire_hard
  return unless Card.cache.hard
  Card.cache.hard.delete key
  Card.cache.hard.delete "~#{id}" if id
end

#expire_piecesObject



292
293
294
295
296
# File 'tmpsets/set/mod001-01_core/all/fetch.rb', line 292

def expire_pieces
  cardname.piece_names.each do |piece|
    Card.expire piece, !cardname.field_of?(piece)
  end
end

#expire_soft(subcards = false) ⇒ Object



304
305
306
307
308
309
310
311
312
# File 'tmpsets/set/mod001-01_core/all/fetch.rb', line 304

def expire_soft subcards=false
  if subcards
    expire_subcards
  else
    preserve_subcards
  end
  Card.cache.soft.delete key
  Card.cache.soft.delete "~#{id}" if id
end

#fetch(opts = {}) ⇒ Object

~~~~~~~~~~ Instance ~~~~~~~~~~~~~



265
266
267
268
269
270
271
272
273
# File 'tmpsets/set/mod001-01_core/all/fetch.rb', line 265

def fetch opts={}
  traits = opts.delete(:trait)
  return unless traits
  # should this fail as an incorrect api call?
  traits = Array.wrap traits
  traits.inject(self) do |card, trait|
    Card.fetch card.cardname.trait(trait), opts
  end
end

#handle_default_content(opts) ⇒ Object



283
284
285
286
287
288
289
290
# File 'tmpsets/set/mod001-01_core/all/fetch.rb', line 283

def handle_default_content opts
  if (default_content = opts.delete(:default_content)) && db_content.blank?
    opts[:content] ||= default_content
  elsif db_content.present? && !opts[:content]
    # don't overwrite existing content
    opts[:content] = db_content
  end
end

#name_from_mark!(mark, opts) ⇒ Object



337
338
339
340
341
# File 'tmpsets/set/mod001-01_core/all/fetch.rb', line 337

def name_from_mark! mark, opts
  return if opts[:local_only]
  return unless mark && mark.to_s != name
  self.name = mark.to_s
end

#refresh(force = false) ⇒ Object



319
320
321
322
323
324
325
326
327
# File 'tmpsets/set/mod001-01_core/all/fetch.rb', line 319

def refresh force=false
  if force || frozen? || readonly?
    fresh_card = self.class.find id
    fresh_card.include_set_modules
    fresh_card
  else
    self
  end
end

#renew(args = {}) ⇒ Object



275
276
277
278
279
280
281
# File 'tmpsets/set/mod001-01_core/all/fetch.rb', line 275

def renew args={}
  opts = args[:new].clone
  handle_default_content opts
  opts[:name] ||= cardname
  opts[:skip_modules] = args[:skip_modules]
  Card.new opts
end

#type_unknown?Boolean

Returns:

  • (Boolean)


333
334
335
# File 'tmpsets/set/mod001-01_core/all/fetch.rb', line 333

def type_unknown?
  type_id.nil?
end