Module: Cheffish::WithPattern

Included in:
ChefRunData
Defined in:
lib/cheffish/with_pattern.rb

Instance Method Summary collapse

Instance Method Details

#with(symbol) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/cheffish/with_pattern.rb', line 3

def with(symbol)
  class_eval <<EOM
    attr_accessor :current_#{symbol}

    def with_#{symbol}(value)
      old_value = self.current_#{symbol}
      self.current_#{symbol} = value
      if block_given?
        begin
          yield
        ensure
          self.current_#{symbol} = old_value
        end
      end
    end
EOM
end