Class: ClimateControl::Modifier

Inherits:
Object
  • Object
show all
Defined in:
lib/climate_control/modifier.rb

Defined Under Namespace

Classes: OverlappingKeysWithChangedValues

Instance Method Summary collapse

Constructor Details

#initialize(env, environment_overrides = {}, &block) ⇒ Modifier

Returns a new instance of Modifier.



3
4
5
6
7
# File 'lib/climate_control/modifier.rb', line 3

def initialize(env, environment_overrides = {}, &block)
  @environment_overrides = stringify_keys(environment_overrides)
  @block = block
  @env = env
end

Instance Method Details

#processObject



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/climate_control/modifier.rb', line 9

def process
  @env.synchronize do
    begin
      prepare_environment_for_block
      run_block
    ensure
      cache_environment_after_block
      delete_keys_that_do_not_belong
      revert_changed_keys
    end
  end
end