<commit_before>require "fog/core/model"

module Fog
  module Google
    class SQL
      ##
      # Represents a database user in a Cloud SQL instance.
      #
      # @see https://cloud.google.com/sql/docs/mysql/admin-api/v1beta4/users
      class User < Fog::Model
        attribute :name
        attribute :etag
        attribute :host
        attribute :instance
        attribute :kind
        attribute :project

        def destroy(async: true)
          requires :instance, :name, :host

          resp = service.delete_user(instance, host, name)
          operation = Fog::Google::SQL::Operations.new(:service => service).get(resp.name)
          operation.wait_for { ready? } unless async
          operation
        end

        def save(password: <PASSWORD>)
          requires :instance, :name

          data = to_h
          data[:password] = password unless <PASSWORD>?
          service.insert_user(instance, data)
          self
        end
      end
    end
  end
end
<commit_msg>have user.save switch between insert/update<commit_after>require "fog/core/model"

module Fog
  module Google
    class SQL
      ##
      # Represents a database user in a Cloud SQL instance.
      #
      # @see https://cloud.google.com/sql/docs/mysql/admin-api/v1beta4/users
      class User < Fog::Model
        attribute :name
        attribute :etag
        attribute :host
        attribute :instance
        attribute :kind
        attribute :project

        def destroy(async: true)
          requires :instance, :name, :host

          resp = service.delete_user(instance, host, name)
          operation = Fog::Google::SQL::Operations.new(:service => service).get(resp.name)
          operation.wait_for { ready? } unless async
          operation
        end

        def save(password: <PASSWORD>)
          requires :instance, :name

          data = attributes
          data[:password] = password unless <PASSWORD>?
          if etag.nil?
            resp = service.update_user(instance, data)
          else
            resp = service.insert_user(instance, data)
          end

          operation = Fog::Google::SQL::Operations.new(:service => service).get(resp.name)
          operation.wait_for { !pending? }
          reload
        end
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.09277899343544858, 'fraction_numerical': 0.00175054704595186, 'mean_word_length': 1.9496774193548387, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 10, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1344210', 'n_tokens_mistral': 620, 'n_tokens_neox': 614, 'n_words': 165}