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

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

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Methods included from I18nScope

#mod_name, #scope

Methods included from Loader

#clean_empty_module_from_hash, #clean_empty_modules, #extended, #pattern_and_modules_from_path, #process_base_modules, #register_set, #tmp_file_frame, #tmp_file_template, #tmp_file_wrapped_content, #write_tmp_file

Methods included from Helpers

#abstract_set?, #all_set?, #shortname

Methods included from Card::Set::AdvancedApi

#attachment, #ensure_set, #stage_method

Methods included from Format

#all_set_format_mod!, #define_on_format, #format, #register_set_format, #view

Methods included from Inheritance

#include_set, #include_set_formats

Methods included from Basket

#abstract_basket, #add_to_basket, #basket

Methods included from Trait

#card_accessor, #card_reader, #card_writer

Methods included from Event

#event

Instance Method Details

#eager_renew?(opts) ⇒ Boolean

Returns:

  • (Boolean)


317
318
319
# File 'tmpsets/set/mod001-core/all/fetch.rb', line 317

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

#expireObject



302
303
304
305
# File 'tmpsets/set/mod001-core/all/fetch.rb', line 302

def expire
  expire_hard
  expire_soft
end

#expire_hardObject



291
292
293
294
295
# File 'tmpsets/set/mod001-core/all/fetch.rb', line 291

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

#expire_piecesObject



285
286
287
288
289
# File 'tmpsets/set/mod001-core/all/fetch.rb', line 285

def expire_pieces
  cardname.piece_names.each do |piece|
    Card.expire piece
  end
end

#expire_softObject



297
298
299
300
# File 'tmpsets/set/mod001-core/all/fetch.rb', line 297

def expire_soft
  Card.cache.soft.delete key
  Card.cache.soft.delete "~#{id}" if id
end

#fetch(opts = {}) ⇒ Object

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



258
259
260
261
262
263
264
265
266
# File 'tmpsets/set/mod001-core/all/fetch.rb', line 258

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



276
277
278
279
280
281
282
283
# File 'tmpsets/set/mod001-core/all/fetch.rb', line 276

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



325
326
327
328
329
# File 'tmpsets/set/mod001-core/all/fetch.rb', line 325

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



307
308
309
310
311
312
313
314
315
# File 'tmpsets/set/mod001-core/all/fetch.rb', line 307

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



268
269
270
271
272
273
274
# File 'tmpsets/set/mod001-core/all/fetch.rb', line 268

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_known?Boolean

Returns:

  • (Boolean)


321
322
323
# File 'tmpsets/set/mod001-core/all/fetch.rb', line 321

def type_known?
  type_id.present?
end