Module: Card::Set::All::References
- Extended by:
- Card::Set
- Defined in:
- tmpsets/set/mod001-01_core/all/references.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
#extended_referencers ⇒ Object
9
10
11
12
|
# File 'tmpsets/set/mod001-01_core/all/references.rb', line 9
def extended_referencers
(dependents + [self]).map(&:referencers).flatten.uniq
end
|
#includees ⇒ Object
103
104
105
106
|
# File 'tmpsets/set/mod001-01_core/all/references.rb', line 103
def includees
return [] unless refs = references_to.where( :ref_type => 'I' )
refs.map { |ref| Card.fetch ref.referee_key, :new=>{} }.compact
end
|
#includers ⇒ Object
93
94
95
96
|
# File 'tmpsets/set/mod001-01_core/all/references.rb', line 93
def includers
return [] unless refs = references_from.where( :ref_type => 'I' )
refs.map(&:referer_id).map( &Card.method(:fetch) ).compact
end
|
#name_referencers(link_name = nil) ⇒ Object
4
5
6
7
|
# File 'tmpsets/set/mod001-01_core/all/references.rb', line 4
def name_referencers link_name=nil
link_name = link_name.nil? ? key : link_name.to_name.key
Card.joins( :references_to ).where card_references: { referee_key: link_name }
end
|
98
99
100
101
|
# File 'tmpsets/set/mod001-01_core/all/references.rb', line 98
def referees
return [] unless refs = references_to
refs.map { |ref| Card.fetch ref.referee_key, :new=>{} }.compact
end
|
#referencers ⇒ Object
88
89
90
91
|
# File 'tmpsets/set/mod001-01_core/all/references.rb', line 88
def referencers
return [] unless refs = references_from
refs.map(&:referer_id).map( &Card.method(:fetch) ).compact
end
|
#replace_references(old_name, new_name) ⇒ Object
replace references in card content
16
17
18
19
20
21
22
23
24
25
26
|
# File 'tmpsets/set/mod001-01_core/all/references.rb', line 16
def replace_references old_name, new_name
obj_content = Card::Content.new raw_content, card=self
obj_content.find_chunks( Card::Chunk::Reference ).select do |chunk|
if old_ref_name = chunk.referee_name and new_ref_name = old_ref_name.replace_part(old_name, new_name)
chunk.referee_name = chunk.replace_reference old_name, new_name
Card::Reference.where( :referee_key => old_ref_name.key ).update_all :referee_key => new_ref_name.key
end
end
obj_content.to_s
end
|
#update_references(rendered_content = nil, refresh = false) ⇒ Object
update entries in reference table
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
# File 'tmpsets/set/mod001-01_core/all/references.rb', line 29
def update_references rendered_content = nil, refresh = false
raise "update references should not be called on new cards" if id.nil?
Card::Reference.delete_all_from self
Card.connection.execute("update cards set references_expired=NULL where id=#{id}")
expire if refresh
rendered_content ||= Card::Content.new(raw_content, card=self)
rendered_content.find_chunks(Card::Chunk::Reference).each do |chunk|
if referee_name = chunk.referee_name referee_id = chunk.referee_id
if id != referee_id
referee_name.piece_names.each do |name|
if name.key != key
ref_type =
if name == referee_name
case chunk
when Card::Chunk::Link then 'L'
when Card::Chunk::QueryReference then 'Q'
else 'I'
end
else 'P'
end
Card::Reference.create!(
:referer_id => id,
:referee_id => Card.where(:key=>name.key).pluck(:id).first,
:referee_key => name.key,
:ref_type => ref_type,
:present => 1
)
end
end
end
end
end
end
|