Module: Volt::Modes::ClassMethods

Defined in:
lib/volt/utils/modes.rb

Instance Method Summary collapse

Instance Method Details

#in_mode?(mode_name) ⇒ Boolean

Check to see if we are in the specified mode

Returns:



43
44
45
# File 'lib/volt/utils/modes.rb', line 43

def in_mode?(mode_name)
  defined?(Thread) && Thread.current[mode_name]
end

#run_in_mode(mode_name) ⇒ Object

Takes a block that when run, changes to mode inside of it



20
21
22
23
24
25
26
27
28
# File 'lib/volt/utils/modes.rb', line 20

def run_in_mode(mode_name)
  previous = Thread.current[mode_name]
  Thread.current[mode_name] = true
  begin
    yield
  ensure
    Thread.current[mode_name] = previous
  end
end

#run_in_mode_if(conditional, mode_name) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/volt/utils/modes.rb', line 30

def run_in_mode_if(conditional, mode_name)
  if conditional
    # Yes, run in the mode
    Volt.run_in_mode(mode_name) do
      yield
    end
  else
    # Just run normally
    yield
  end
end