Module: CableRoom::Room::PortScoping

Extended by:
ActiveSupport::Concern
Included in:
Base
Defined in:
lib/cable_room/room/port_scoping.rb

Instance Method Summary collapse

Instance Method Details

#simplify_port_scope(**kwargs) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/cable_room/room/port_scoping.rb', line 25

def simplify_port_scope(**kwargs)
  catch :abort do
    remaining = _apply_port_scope(**kwargs)
    return remaining
  end
  nil
end

#with_port_scope(**kwargs, &blk) ⇒ Object

Wrap the passed block with a specific messaging scope



17
18
19
20
21
22
23
# File 'lib/cable_room/room/port_scoping.rb', line 17

def with_port_scope(**kwargs, &blk)
  prev = Room.current_port_scope
  Room.current_port_scope = prev ? prev.merge(kwargs) : kwargs
  yield
ensure
  Room.current_port_scope = prev
end

#with_port_scope!(**kwargs, &blk) ⇒ Object

Similar to with_port_scope, but won't call the block if no ports match



34
35
36
37
38
39
40
41
42
43
# File 'lib/cable_room/room/port_scoping.rb', line 34

def with_port_scope!(**kwargs, &blk)
  if kwargs.empty?
    reduced_scope = simplify_port_scope(**Room.current_port_scope || {})
    blk.call(**reduced_scope) unless reduced_scope.nil?
  else
    with_port_scope(**kwargs) do
      with_port_scope!(&blk)
    end
  end
end

#without_port_scope(&blk) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/cable_room/room/port_scoping.rb', line 8

def without_port_scope(&blk)
  prev = Room.current_port_scope
  Room.current_port_scope = nil
  yield
ensure
  Room.current_port_scope = prev
end