Sha256: 23f5e147c090fadf284be34e6c426b4e2dd1b951933544282f69eb0cb02b7ea2
Contents?: true
Size: 1.73 KB
Versions: 31
Compression:
Stored size: 1.73 KB
Contents
def is_template? name.trait_name? :structure, :default end def is_structure? name.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 name.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? name.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
31 entries across 31 versions & 1 rubygems