Module: Hyperstack::Internal::AutoUnmount

Defined in:
lib/hyperstack/internal/auto_unmount.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



4
5
6
7
8
9
# File 'lib/hyperstack/internal/auto_unmount.rb', line 4

def self.included(base)
  base.include(Hyperstack::Internal::Callbacks)
  base.class_eval do
    define_callback :before_unmount
  end
end

.objects_to_unmountObject



49
50
51
# File 'lib/hyperstack/internal/auto_unmount.rb', line 49

def objects_to_unmount
  @objects_to_unmount ||= Hash.new { |h, k| h[k] = Set.new }
end

Instance Method Details

#after(*args, &block) ⇒ Object



39
40
41
42
43
44
45
46
# File 'lib/hyperstack/internal/auto_unmount.rb', line 39

def after(*args, &block)
  return if unmounted?
  super.tap do |id|
    sself = self
    id.define_singleton_method(:unmount) { abort }
    AutoUnmount.objects_to_unmount[self] << id
  end
end

#every(*args, &block) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/hyperstack/internal/auto_unmount.rb', line 30

def every(*args, &block)
  return if unmounted?
  super.tap do |id|
    sself = self
    id.define_singleton_method(:unmount) { abort }
    AutoUnmount.objects_to_unmount[self] << id
  end
end

#unmountObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/hyperstack/internal/auto_unmount.rb', line 15

def unmount
  run_callback(:before_unmount)
  AutoUnmount.objects_to_unmount[self].each(&:unmount)
  AutoUnmount.objects_to_unmount.delete(self)
  instance_variables.each do |var|
    val = instance_variable_get(var)
    begin
      val.unmount if val.respond_to?(:unmount)
    rescue RUBY_ENGINE == 'opal' ? JS::Error : nil
      nil
    end
  end
  @__hyperstack_internal_auto_unmount_unmounted = true
end

#unmounted?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/hyperstack/internal/auto_unmount.rb', line 11

def unmounted?
  @__hyperstack_internal_auto_unmount_unmounted
end