Sha256: 3672b4860b04506411cfddd09ad54ae068d8a620d676aa923e8f7c5aee62b857

Contents?: true

Size: 1.74 KB

Versions: 39

Compression:

Stored size: 1.74 KB

Contents

# frozen_string_literal: true

module Rails::Command::CredentialsCommand::Diffing # :nodoc:
  GITATTRIBUTES_ENTRY = <<~END
    config/credentials/*.yml.enc diff=rails_credentials
    config/credentials.yml.enc diff=rails_credentials
  END

  def enroll_project_in_credentials_diffing
    if enrolled_in_credentials_diffing?
      say "Project is already enrolled in credentials file diffing."
    else
      gitattributes.write(GITATTRIBUTES_ENTRY, mode: "a")

      say "Enrolled project in credentials file diffing!"
      say ""
      say "Rails will configure the Git diff driver for credentials when running `#{executable(:edit)}`. See `#{executable(:help)}` for more information."
    end
  end

  def disenroll_project_from_credentials_diffing
    if enrolled_in_credentials_diffing?
      gitattributes.write(gitattributes.read.gsub(GITATTRIBUTES_ENTRY, ""))
      gitattributes.delete if gitattributes.empty?

      say "Disenrolled project from credentials file diffing!"
    else
      say "Project is not enrolled in credentials file diffing."
    end
  end

  def ensure_diffing_driver_is_configured
    configure_diffing_driver if enrolled_in_credentials_diffing? && !diffing_driver_configured?
  end

  private
    def enrolled_in_credentials_diffing?
      gitattributes.file? && gitattributes.read.include?(GITATTRIBUTES_ENTRY)
    end

    def diffing_driver_configured?
      system "git config --get diff.rails_credentials.textconv", out: File::NULL
    end

    def configure_diffing_driver
      system "git config diff.rails_credentials.textconv '#{executable(:diff)}'"
      say "Configured Git diff driver for credentials."
    end

    def gitattributes
      @gitattributes ||= (Rails::Command.root || Pathname.pwd).join(".gitattributes")
    end
end

Version data entries

39 entries across 39 versions & 5 rubygems

Version Path
minato_ruby_api_client-0.2.2 vendor/bundle/ruby/3.2.0/gems/railties-7.1.3.4/lib/rails/commands/credentials/credentials_command/diffing.rb
railties-8.0.1 lib/rails/commands/credentials/credentials_command/diffing.rb
railties-8.0.0.1 lib/rails/commands/credentials/credentials_command/diffing.rb
railties-7.2.2.1 lib/rails/commands/credentials/credentials_command/diffing.rb
railties-7.1.5.1 lib/rails/commands/credentials/credentials_command/diffing.rb
railties-8.0.0 lib/rails/commands/credentials/credentials_command/diffing.rb
railties-7.2.2 lib/rails/commands/credentials/credentials_command/diffing.rb
railties-7.1.5 lib/rails/commands/credentials/credentials_command/diffing.rb
railties-8.0.0.rc2 lib/rails/commands/credentials/credentials_command/diffing.rb
railties-7.2.1.2 lib/rails/commands/credentials/credentials_command/diffing.rb
railties-7.1.4.2 lib/rails/commands/credentials/credentials_command/diffing.rb
railties-8.0.0.rc1 lib/rails/commands/credentials/credentials_command/diffing.rb
railties-7.2.1.1 lib/rails/commands/credentials/credentials_command/diffing.rb
railties-7.1.4.1 lib/rails/commands/credentials/credentials_command/diffing.rb
railties-8.0.0.beta1 lib/rails/commands/credentials/credentials_command/diffing.rb
omg-railties-8.0.0.alpha9 lib/rails/commands/credentials/credentials_command/diffing.rb
omg-railties-8.0.0.alpha8 lib/rails/commands/credentials/credentials_command/diffing.rb
omg-railties-8.0.0.alpha7 lib/rails/commands/credentials/credentials_command/diffing.rb
omg-railties-8.0.0.alpha4 lib/rails/commands/credentials/credentials_command/diffing.rb
omg-railties-8.0.0.alpha3 lib/rails/commands/credentials/credentials_command/diffing.rb