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

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

Defined Under Namespace

Modules: ClassMethods

Constant Summary

Constants included from Helpers

Helpers::SET_PATTERN_TEST_REGEXP

Instance Method Summary collapse

Methods included from Card::Set

reset_modules

Methods included from I18nScope

#mod_name, #scope

Methods included from Loader

#clean_empty_module_from_hash, #clean_empty_modules, #extended, #process_base_modules, #register_set

Methods included from Helpers

#method_missing, #num_set_parts, #pattern_code, #respond_to_missing?, #set_name_parts, #shortname, #underscore

Methods included from Card::Set::AdvancedApi

#attachment, #ensure_set, #stage_method

Methods included from Format

#before, #format, layout_method_name, #view, view_method_name, view_setting_method_name, wrapper_method_name

Methods included from Inheritance

#include_set, #include_set_formats

Methods included from Basket

#abstract_basket, #add_to_basket, #basket, #unshift_basket

Methods included from Trait

#card_accessor, #card_reader, #card_writer, #require_field

Methods included from Event::Api

#event

Instance Method Details

#eager_renew?(opts) ⇒ Boolean

Returns:

  • (Boolean)


319
320
321
# File 'tmpsets/set/mod002-core/all/fetch.rb', line 319

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

#expireObject



304
305
306
307
# File 'tmpsets/set/mod002-core/all/fetch.rb', line 304

def expire
  expire_hard
  expire_soft
end

#expire_hardObject



293
294
295
296
297
# File 'tmpsets/set/mod002-core/all/fetch.rb', line 293

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

#expire_piecesObject



287
288
289
290
291
# File 'tmpsets/set/mod002-core/all/fetch.rb', line 287

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

#expire_softObject



299
300
301
302
# File 'tmpsets/set/mod002-core/all/fetch.rb', line 299

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

#fetch(opts = {}) ⇒ Object

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



260
261
262
263
264
265
266
267
268
# File 'tmpsets/set/mod002-core/all/fetch.rb', line 260

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



278
279
280
281
282
283
284
285
# File 'tmpsets/set/mod002-core/all/fetch.rb', line 278

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



327
328
329
330
331
# File 'tmpsets/set/mod002-core/all/fetch.rb', line 327

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



309
310
311
312
313
314
315
316
317
# File 'tmpsets/set/mod002-core/all/fetch.rb', line 309

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



270
271
272
273
274
275
276
# File 'tmpsets/set/mod002-core/all/fetch.rb', line 270

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)


323
324
325
# File 'tmpsets/set/mod002-core/all/fetch.rb', line 323

def type_known?
  type_id.present?
end