class ESA::ContextProvider

Public Class Methods

check_subcontexts(context, namespace, options = {}) click to toggle source
# 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 = {}) click to toggle source
# File lib/esa/context_provider.rb, line 31
def self.contained_ids(context, options = {})
  []
end
contained_subcontexts(context, namespace, existing, options = {}) click to toggle source
# 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 = {}) click to toggle source
# File lib/esa/context_provider.rb, line 27
def self.context_id(context, options = {})
  []
end
existing_subcontexts(context, namespace, options = {}) click to toggle source
# 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() click to toggle source
# File lib/esa/context_provider.rb, line 3
def self.provided_types
  []
end