Module: Card::Set::All::Name
- Extended by:
- Card::Set
- Defined in:
- tmpsets/set/mod001-01_core/all/name.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary
collapse
Methods included from Card::Set
abstract_set?, all_set?, clean_empty_module_from_hash, clean_empty_modules, define_on_format, each_format, ensure_set, extended, format, include_set, include_set_formats, process_base_module_list, process_base_modules, register_set, register_set_format, shortname, stage_method, view, write_tmp_file
Methods included from Trait
#card_accessor, #card_reader, #card_writer
Methods included from Event
#define_event, #event
Instance Method Details
#[](*args) ⇒ Object
105
106
107
108
109
110
111
112
113
|
# File 'tmpsets/set/mod001-01_core/all/name.rb', line 105
def [] *args
case args[0]
when Fixnum, Range
fetch_name = Array.wrap(cardname.parts[args[0]]).compact.join '+'
Card.fetch(fetch_name, args[1] || {}) if !simple?
else
super
end
end
|
#absolute_name(context_name = nil) ⇒ Object
83
84
85
86
87
88
|
# File 'tmpsets/set/mod001-01_core/all/name.rb', line 83
def absolute_name context_name=nil
if !context_name && @supercard
context_name = @supercard.cardname
end
cardname.absolute_name(context_name)
end
|
#autoname(name) ⇒ Object
55
56
57
58
59
60
61
|
# File 'tmpsets/set/mod001-01_core/all/name.rb', line 55
def autoname name
if Card.exists? name
autoname name.next
else
name
end
end
|
51
52
53
|
# File 'tmpsets/set/mod001-01_core/all/name.rb', line 51
def cardname
name.to_name
end
|
#child_names(parent_name = nil, side = nil) ⇒ Object
139
140
141
142
143
144
145
|
# File 'tmpsets/set/mod001-01_core/all/name.rb', line 139
def child_names parent_name=nil, side=nil
parent_name ||= name
side ||= parent_name.to_name.simple? ? :part : :left
Card.search({ side => parent_name, return: :name },
"(#{side}) children of #{parent_name}")
end
|
135
136
137
|
# File 'tmpsets/set/mod001-01_core/all/name.rb', line 135
def children
child_names.map { |name| Card[name] }
end
|
#contextual_name ⇒ Object
72
73
74
|
# File 'tmpsets/set/mod001-01_core/all/name.rb', line 72
def contextual_name
@contextual_name || name
end
|
#descendant_names(parent_name = nil) ⇒ Object
147
148
149
150
151
152
153
154
155
156
|
# File 'tmpsets/set/mod001-01_core/all/name.rb', line 147
def descendant_names parent_name=nil
return [] if new_card?
parent_name ||= name
Auth.as_bot do
deps = child_names parent_name
deps.inject(deps) do |array, childname|
array + descendant_names(childname)
end
end
end
|
#descendants ⇒ Object
158
159
160
161
162
163
|
# File 'tmpsets/set/mod001-01_core/all/name.rb', line 158
def descendants
@descendants ||= descendant_names.map { |name| Card.quick_fetch name }
end
|
#execute_referencers_update(descendants) ⇒ Object
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
|
# File 'tmpsets/set/mod001-01_core/all/name.rb', line 318
def execute_referencers_update descendants
Auth.as_bot do
[name_referencers(name_was) + descendants.map(&:referencers)]
.flatten.uniq.each do |card|
Rails.logger.debug "------------------ UPDATE REFERER #{card.name} " \
'------------------------'
unless card == self || card.structure
card = card.refresh
card.db_content = card.replace_references name_was, name
card.save!
end
end
end
end
|
#field_names(parent_name = nil) ⇒ Object
131
132
133
|
# File 'tmpsets/set/mod001-01_core/all/name.rb', line 131
def field_names parent_name=nil
child_names parent_name, :left
end
|
127
128
129
|
# File 'tmpsets/set/mod001-01_core/all/name.rb', line 127
def fields
field_names.map { |name| Card[name] }
end
|
#junction? ⇒ Boolean
68
69
70
|
# File 'tmpsets/set/mod001-01_core/all/name.rb', line 68
def junction?
cardname.junction?
end
|
#left(*args) ⇒ Object
90
91
92
93
94
95
96
97
98
99
|
# File 'tmpsets/set/mod001-01_core/all/name.rb', line 90
def left *args
return if simple?
@superleft || begin
unless name_changed? &&
name.to_name.trunk_name.key == name_was.to_name.key
Card.fetch cardname.left, *args
end
end
end
|
#left_or_new(args = {}) ⇒ Object
123
124
125
|
# File 'tmpsets/set/mod001-01_core/all/name.rb', line 123
def left_or_new args={}
left(args) || Card.new(args.merge(name: cardname.left))
end
|
#name=(newname) ⇒ Object
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'tmpsets/set/mod001-01_core/all/name.rb', line 24
def name= newname
cardname = newname.to_name
if @supercard
@supercard.subcards.rename key, cardname.key
@contextual_name = cardname.to_s
relparts = cardname.parts
if relparts.size == 2 &&
(relparts.first.blank? || relparts.first.to_name.key == @supercard.key)
@superleft = @supercard
end
cardname = cardname.to_absolute_name @supercard.name
end
newkey = cardname.key
if key != newkey
self.key = newkey
reset_patterns_if_rule
reset_patterns
end
subcards.each do |subcard|
subcard.name = subcard.cardname.replace_part name, newname
end
write_attribute :name, cardname.s
end
|
#relative_name(context_name = nil) ⇒ Object
76
77
78
79
80
81
|
# File 'tmpsets/set/mod001-01_core/all/name.rb', line 76
def relative_name context_name=nil
if !context_name && @supercard
context_name = @supercard.cardname
end
cardname.relative_name(context_name)
end
|
#repair_key ⇒ Object
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
|
# File 'tmpsets/set/mod001-01_core/all/name.rb', line 165
def repair_key
Auth.as_bot do
correct_key = cardname.key
current_key = key
return self if current_key == correct_key
if (key_blocker = Card.find_by_key_and_trash(correct_key, true))
key_blocker.cardname = key_blocker.cardname + "*trash#{rand(4)}"
key_blocker.save
end
saved = (self.key = correct_key) && self.save!
saved ||= (self.cardname = current_key) && self.save!
if saved
descendants.each(&:repair_key)
else
Rails.logger.debug "FAILED TO REPAIR BROKEN KEY: #{key}"
self.name = "BROKEN KEY: #{name}"
end
self
end
rescue
Rails.logger.info "BROKE ATTEMPTING TO REPAIR BROKEN KEY: #{key}"
self
end
|
#right(*args) ⇒ Object
101
102
103
|
# File 'tmpsets/set/mod001-01_core/all/name.rb', line 101
def right *args
Card.fetch(cardname.right, *args) if !simple?
end
|
#simple? ⇒ Boolean
FIXME: use delegations and include all cardname functions
64
65
66
|
# File 'tmpsets/set/mod001-01_core/all/name.rb', line 64
def simple?
cardname.simple?
end
|
#suspend_name(name) ⇒ Object
287
288
289
290
291
292
293
|
# File 'tmpsets/set/mod001-01_core/all/name.rb', line 287
def suspend_name name
Card.expire name
tmp_name = 'tmp:' + UUID.new.generate
Card.where(id: id).update_all(name: tmp_name, key: tmp_name)
end
|
#tag(*args) ⇒ Object
119
120
121
|
# File 'tmpsets/set/mod001-01_core/all/name.rb', line 119
def tag *args
simple? ? self : Card.fetch(cardname.right, *args)
end
|
#trunk(*args) ⇒ Object
115
116
117
|
# File 'tmpsets/set/mod001-01_core/all/name.rb', line 115
def trunk *args
simple? ? self : left(*args)
end
|