Method: VV::ObjectMethods#consider

Defined in:
lib/vv/object_methods.rb

#consider(input, &block) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/vv/object_methods.rb', line 7

def consider input, &block
  @__vv_consideration_dismissed_level ||= false

  # For a potential parent consideration
  return if self._consideration_dismissed?

  @__vv_consideration_others ||= Hash.new
  @__vv_consideration_level  ||= -1
  @__vv_consideration_level   +=  1

  @__vv_considerations ||= Array.new
  @__vv_considerations << input
  yield
ensure
  if @__vv_consideration_dismissed_level == \
     @__vv_consideration_level
    remove_instance_variable :@__vv_consideration_dismissed_level
  end

  @__vv_consideration_level -= 1
  if @__vv_consideration_level < 0
    remove_instance_variable :@__vv_consideration_level
    remove_instance_variable :@__vv_consideration_others
  end
  @__vv_considerations.pop
  unless @__vv_considerations.any?
    remove_instance_variable :@__vv_considerations
  end
end