Sha256: fd4ab6adee4a1f3a04a70aee6a47aa443878c192425fa8760d126619122bf409
Contents?: true
Size: 1.75 KB
Versions: 5
Compression:
Stored size: 1.75 KB
Contents
def is_template? cardname.trait_name? :structure, :default end def is_structure? cardname.trait_name? :structure end def template # currently applicable templating card. # note that a *default template is never returned for an existing card. @template ||= begin @virtual = false if new_card? new_card_template else structure_rule_card end end end def default_type_id default_card=nil default_card ? default_card.type_id : Card.default_type_id end def new_card_template default = rule_card :default, skip_modules: true dup_card = dup dup_card.type_id = default_type_id default if (structure = dup_card.structure_rule_card) @virtual = true if junction? self.type_id = structure.type_id if assign_type_to?(structure) structure else default end end def assign_type_to? structure return if type_id == structure.type_id structure.assigns_type? end def assigns_type? # needed because not all *structure templates govern the type of set members # for example, X+*type+*structure governs all cards of type X, # but the content rule does not (in fact cannot) have the type X. return unless (set_pattern = Card.fetch cardname.trunk_name.tag_name, skip_modules: true) return unless (pattern_code = set_pattern.codename) return unless (set_class = Set::Pattern.find pattern_code) set_class.assigns_type end def structure return unless template && template.is_structure? template end def virtual? return false unless new_card? if @virtual.nil? cardname.simple? ? (@virtual = false) : template end @virtual end def structure_rule_card card = rule_card :structure, skip_modules: true card && card.db_content.strip == "_self" ? nil : card end
Version data entries
5 entries across 5 versions & 1 rubygems