File Manager

Path: /opt/chef/embedded/lib/ruby/gems/2.7.0/gems/cheffish-16.0.2/lib/cheffish/

Viewing File: with_pattern.rb

module Cheffish
  module WithPattern
    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
  end
end