Module: MongoMapper::Plugins::SpaceKeys::InstanceMethods

Defined in:
lib/rad/mongo_mapper/space_keys.rb

Instance Method Summary collapse

Instance Method Details

#get_create_or_delete_space_keys_container(modifying_operation, &block) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/rad/mongo_mapper/space_keys.rb', line 17

def get_create_or_delete_space_keys_container modifying_operation, &block
  Rad.multitenant_mode?.must_be.true
  
  unless modifying_operation
    container = space_keys_containers.select{|c| c.space_id == Space.current.id}.first || \
      SpaceKeysContainer.new(:space_id => Space.current.id)
    block.call container
  else
    container = space_keys_containers.select{|c| c.space_id == Space.current.id}.first || \
      space_keys_containers.build(:space_id => Space.current.id)              
    block.call container            
    space_keys_containers.delete container if container.blank?
  end
end