Further refactoring and bugfixing.
This commit is contained in:
parent
0f28d1f0b6
commit
77ec399fe9
1 changed files with 8 additions and 12 deletions
|
@ -7,8 +7,8 @@ module HasGroups
|
||||||
|
|
||||||
attr_accessor :group_access_buffer
|
attr_accessor :group_access_buffer
|
||||||
|
|
||||||
after_create :check_group_access_buffer
|
after_create :process_group_access_buffer
|
||||||
after_update :check_group_access_buffer
|
after_update :process_group_access_buffer
|
||||||
|
|
||||||
association_attributes_ignored :groups, group_through_identifier
|
association_attributes_ignored :groups, group_through_identifier
|
||||||
|
|
||||||
|
@ -212,16 +212,12 @@ module HasGroups
|
||||||
|
|
||||||
def groups_access_map_store(map)
|
def groups_access_map_store(map)
|
||||||
fill_group_access_buffer do
|
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
|
# use given key as identifier or look it up
|
||||||
# via the given block which returns the identifier
|
# via the given block which returns the identifier
|
||||||
group_id = block_given? ? yield(group_identifier) : group_identifier
|
group_id = block_given? ? yield(group_identifier) : group_identifier
|
||||||
|
|
||||||
if !accesses.is_a?(Array)
|
Array(accesses).each do |access|
|
||||||
accesses = [accesses]
|
|
||||||
end
|
|
||||||
|
|
||||||
accesses.each do |access|
|
|
||||||
push_group_access_buffer(
|
push_group_access_buffer(
|
||||||
group_id: group_id,
|
group_id: group_id,
|
||||||
access: access
|
access: access
|
||||||
|
@ -234,14 +230,14 @@ module HasGroups
|
||||||
def fill_group_access_buffer
|
def fill_group_access_buffer
|
||||||
@group_access_buffer = []
|
@group_access_buffer = []
|
||||||
yield
|
yield
|
||||||
check_group_access_buffer if id
|
process_group_access_buffer if id
|
||||||
end
|
end
|
||||||
|
|
||||||
def push_group_access_buffer(entry)
|
def push_group_access_buffer(entry)
|
||||||
@group_access_buffer.push(entry)
|
@group_access_buffer.push(entry)
|
||||||
end
|
end
|
||||||
|
|
||||||
def flushed_group_access_buffer
|
def flush_group_access_buffer
|
||||||
# group_access_buffer is at least an empty Array
|
# group_access_buffer is at least an empty Array
|
||||||
# if changes to the map were performed
|
# if changes to the map were performed
|
||||||
# otherwise it's just an update of other attributes
|
# otherwise it's just an update of other attributes
|
||||||
|
@ -251,9 +247,9 @@ module HasGroups
|
||||||
cache_delete
|
cache_delete
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_group_access_buffer
|
def process_group_access_buffer
|
||||||
|
|
||||||
flushed_group_access_buffer do
|
flush_group_access_buffer do
|
||||||
destroy_group_relations
|
destroy_group_relations
|
||||||
|
|
||||||
break if group_access_buffer.blank?
|
break if group_access_buffer.blank?
|
||||||
|
|
Loading…
Reference in a new issue