Further refactoring and bugfixing.

This commit is contained in:
Thorsten Eckel 2018-02-27 16:52:30 +01:00
parent 0f28d1f0b6
commit 77ec399fe9

View file

@ -7,8 +7,8 @@ module HasGroups
attr_accessor :group_access_buffer
after_create :check_group_access_buffer
after_update :check_group_access_buffer
after_create :process_group_access_buffer
after_update :process_group_access_buffer
association_attributes_ignored :groups, group_through_identifier
@ -212,16 +212,12 @@ module HasGroups
def groups_access_map_store(map)
fill_group_access_buffer do
map.each do |group_identifier, accesses|
Hash(map).each do |group_identifier, accesses|
# use given key as identifier or look it up
# via the given block which returns the identifier
group_id = block_given? ? yield(group_identifier) : group_identifier
if !accesses.is_a?(Array)
accesses = [accesses]
end
accesses.each do |access|
Array(accesses).each do |access|
push_group_access_buffer(
group_id: group_id,
access: access
@ -234,14 +230,14 @@ module HasGroups
def fill_group_access_buffer
@group_access_buffer = []
yield
check_group_access_buffer if id
process_group_access_buffer if id
end
def push_group_access_buffer(entry)
@group_access_buffer.push(entry)
end
def flushed_group_access_buffer
def flush_group_access_buffer
# group_access_buffer is at least an empty Array
# if changes to the map were performed
# otherwise it's just an update of other attributes
@ -251,9 +247,9 @@ module HasGroups
cache_delete
end
def check_group_access_buffer
def process_group_access_buffer
flushed_group_access_buffer do
flush_group_access_buffer do
destroy_group_relations
break if group_access_buffer.blank?