Module: Card::Set::All::Templating

Extended by:
Card::Set
Defined in:
tmpsets/set/mod001-01_core/all/templating.rb

Instance Method Summary collapse

Methods included from Card::Set

abstract_set?, all_set?, card_accessor, card_reader, card_writer, clean_empty_module_from_hash, clean_empty_modules, define_active_job, define_event_method, define_event_perform_later_method, define_on_format, ensure_set, event, extended, format, process_base_module_list, process_base_modules, register_set, register_set_format, shortname, view, write_tmp_file

Instance Method Details

#assign_type_to?(structure) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
# File 'tmpsets/set/mod001-01_core/all/templating.rb', line 41

def assign_type_to? structure
  type_id != structure.type_id and structure.assigns_type?
end

#assigns_type?Boolean

Returns:

  • (Boolean)


96
97
98
99
100
101
102
103
104
105
106
107
# File 'tmpsets/set/mod001-01_core/all/templating.rb', line 96

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.
  if is_structure?
    if set_pattern = Card.fetch( cardname.trunk_name.tag_name, :skip_modules=>true )
      pattern_code = set_pattern.codename and
      set_class    = Card::SetPattern.find( pattern_code ) and
      set_class.assigns_type
    end
  end
end

#expire_structuree_referencesObject

FIXME: content settings – do we really need the reference expiration system?

I kind of think so. otherwise how do we handled patterned references in hard-templated cards? I’ll leave the FIXME here until the need (and/or other solution) is well documented. -efm



79
80
81
# File 'tmpsets/set/mod001-01_core/all/templating.rb', line 79

def expire_structuree_references
  update_structurees :references_expired => 1
end

#is_structure?Boolean

Returns:

  • (Boolean)


8
9
10
# File 'tmpsets/set/mod001-01_core/all/templating.rb', line 8

def is_structure?
  cardname.trait_name? :structure
end

#is_template?Boolean

Returns:

  • (Boolean)


4
5
6
# File 'tmpsets/set/mod001-01_core/all/templating.rb', line 4

def is_template?
  cardname.trait_name? :structure, :default
end

#structureObject



45
46
47
48
49
# File 'tmpsets/set/mod001-01_core/all/templating.rb', line 45

def structure
  if template && template.is_structure?
    template
  end
end

#structure_rule_cardObject



59
60
61
62
# File 'tmpsets/set/mod001-01_core/all/templating.rb', line 59

def structure_rule_card
  card = rule_card :structure, :skip_modules=>true
  card && card.db_content.strip == '_self' ? nil : card
end

#structuree_namesObject



64
65
66
67
68
69
70
71
72
# File 'tmpsets/set/mod001-01_core/all/templating.rb', line 64

def structuree_names
  if wql = structuree_spec
    Auth.as_bot do
      Card::Query.new(wql.merge :return=>:name).run
    end
  else
    []
  end
end

#templateObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'tmpsets/set/mod001-01_core/all/templating.rb', line 12

def template
  # currently applicable templating card.
  # note that a *default template is never returned for an existing card.
  @template ||= begin
    @virtual = false

    # NEW CARDS
    if new_card?
      default = rule_card :default, :skip_modules=>true

      dup_card = dup
      dup_card.type_id = default ? default.type_id : Card.default_type_id

      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

    # EXISTING CARDS
    elsif structure = structure_rule_card
      repair_type structure.type_id if assign_type_to?(structure)
      structure
    end
  end
end

#update_structurees(args) ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
94
# File 'tmpsets/set/mod001-01_core/all/templating.rb', line 83

def update_structurees args
  # note that this is not smart about overriding templating rules
  # for example, if someone were to change the type of a +*right+*structure rule that was overridden
  # by a +*type plus right+*structure rule, the override would not be respected.
  if query = structuree_spec
    Auth.as_bot do
      Card::Query.new( query.merge(:return => :id) ).run.each_slice(100) do |id_batch|
        Card.where( :id => id_batch ).update_all args
      end
    end
  end
end

#virtual?Boolean

Returns:

  • (Boolean)


51
52
53
54
55
56
57
# File 'tmpsets/set/mod001-01_core/all/templating.rb', line 51

def virtual?
  return false unless new_card?
  if @virtual.nil?
    cardname.simple? ? @virtual=false : template
  end
  @virtual
end