Class: ESA::ContextProvider
- Inherits:
-
Object
- Object
- ESA::ContextProvider
show all
- Defined in:
- lib/esa/context_provider.rb
Class Method Summary
collapse
Class Method Details
.check_subcontexts(context, namespace, options = {}) ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/esa/context_provider.rb', line 7
def self.check_subcontexts(context, namespace, options = {})
existing = existing_subcontexts(context, namespace)
contained = contained_subcontexts(context, namespace, existing, options)
created = contained - existing
created.each do |sub|
sub.save if sub.new_record? or sub.changed?
end
unregistered = contained - context.subcontexts
context.subcontexts += unregistered
removed = existing - contained
context.subcontexts -= removed
removed.each(&:destroy) if context.can_be_persisted?
contained
end
|
.contained_ids(context, options = {}) ⇒ Object
31
32
33
|
# File 'lib/esa/context_provider.rb', line 31
def self.contained_ids(context, options = {})
[]
end
|
.contained_subcontexts(context, namespace, existing, options = {}) ⇒ Object
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/esa/context_provider.rb', line 39
def self.contained_subcontexts(context, namespace, existing, options = {})
contained_ids = contained_ids(context, options)
existing_grouped = existing.group_by{|sub| context_id(sub, options)}
existing_ids = existing_grouped.keys
new_ids = contained_ids - existing_ids
new_subcontexts = new_ids.map do |id|
instantiate(context, namespace, id, options)
end
keep_subcontexts = existing_grouped.map do |id,group|
(id.in? contained_ids) ? group.first : nil
end.compact
new_subcontexts + keep_subcontexts
end
|
.context_id(context, options = {}) ⇒ Object
27
28
29
|
# File 'lib/esa/context_provider.rb', line 27
def self.context_id(context, options = {})
[]
end
|
.existing_subcontexts(context, namespace, options = {}) ⇒ Object
35
36
37
|
# File 'lib/esa/context_provider.rb', line 35
def self.existing_subcontexts(context, namespace, options = {})
context.subcontexts.where(type: provided_types, namespace: namespace).all
end
|
.provided_types ⇒ Object
3
4
5
|
# File 'lib/esa/context_provider.rb', line 3
def self.provided_types
[]
end
|