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

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

Overview

= Card#fetch

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

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

#abstract_set?, #all_set?, #num_set_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

Class Method Details

.source_locationObject



9
# File 'tmpsets/set/mod003-core/all/fetch.rb', line 9

def self.source_location; "/Users/ethan/dev/decko/gem/card/mod/core/set/all/fetch.rb"; end

Instance Method Details

#fetch(opts = {}) ⇒ Object


INSTANCE METHODS fetching from the context of a card



124
125
126
127
128
129
130
131
132
# File 'tmpsets/set/mod003-core/all/fetch.rb', line 124

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.name.trait(trait), opts
  end
end

#handle_default_content(opts) ⇒ Object



142
143
144
145
146
147
148
149
# File 'tmpsets/set/mod003-core/all/fetch.rb', line 142

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

#refresh(force = false) ⇒ Object



151
152
153
154
155
156
157
# File 'tmpsets/set/mod003-core/all/fetch.rb', line 151

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

#renew(args = {}) ⇒ Object



134
135
136
137
138
139
140
# File 'tmpsets/set/mod003-core/all/fetch.rb', line 134

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