Sha256: eaba358003f7a9a5176856a233a2555e0c9383359de8b32183ac98c65d590800

Contents?: true

Size: 1.13 KB

Versions: 37

Compression:

Stored size: 1.13 KB

Contents

# frozen_string_literal: true

module Rails::Command::CredentialsCommand::Diffing # :nodoc:
  def enroll_project_in_credentials_diffing
    if enrolled?
      true
    else
      gitattributes.write(<<~end_of_template, mode: "a")
        config/credentials/*.yml.enc diff=rails_credentials
        config/credentials.yml.enc diff=rails_credentials
      end_of_template

      say "Project successfully enrolled!"
      say "Rails ensures the rails_credentials diff driver is set when running `credentials:edit`. See `credentials:help` for more."
    end
  end

  def ensure_rails_credentials_driver_is_set
    set_driver if enrolled? && !driver_configured?
  end

  private
    def enrolled?
      gitattributes.read.match?(/config\/credentials(\/\*)?\.yml\.enc diff=rails_credentials/)
    rescue Errno::ENOENT
      false
    end

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

    def set_driver
      puts "running"
      system "git config diff.rails_credentials.textconv 'bin/rails credentials:diff'"
    end

    def gitattributes
      Rails.root.join(".gitattributes")
    end
end

Version data entries

37 entries across 37 versions & 4 rubygems

Version Path
railties-6.1.7.10 lib/rails/commands/credentials/credentials_command/diffing.rb
railties-6.1.7.9 lib/rails/commands/credentials/credentials_command/diffing.rb
railties-6.1.7.8 lib/rails/commands/credentials/credentials_command/diffing.rb
railties-6.1.7.7 lib/rails/commands/credentials/credentials_command/diffing.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/railties-6.1.6.1/lib/rails/commands/credentials/credentials_command/diffing.rb
railties-6.1.7.6 lib/rails/commands/credentials/credentials_command/diffing.rb
railties-6.1.7.5 lib/rails/commands/credentials/credentials_command/diffing.rb
railties-6.1.7.4 lib/rails/commands/credentials/credentials_command/diffing.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/railties-6.1.6.1/lib/rails/commands/credentials/credentials_command/diffing.rb
railties-6.1.7.3 lib/rails/commands/credentials/credentials_command/diffing.rb
railties-6.1.7.2 lib/rails/commands/credentials/credentials_command/diffing.rb
railties-6.1.7.1 lib/rails/commands/credentials/credentials_command/diffing.rb
railties-6.1.7 lib/rails/commands/credentials/credentials_command/diffing.rb
railties-6.1.6.1 lib/rails/commands/credentials/credentials_command/diffing.rb
railties-6.1.6 lib/rails/commands/credentials/credentials_command/diffing.rb
railties-6.1.5.1 lib/rails/commands/credentials/credentials_command/diffing.rb
railties-6.1.5 lib/rails/commands/credentials/credentials_command/diffing.rb
railties-6.1.4.7 lib/rails/commands/credentials/credentials_command/diffing.rb
railties-6.1.4.6 lib/rails/commands/credentials/credentials_command/diffing.rb
railties-6.1.4.5 lib/rails/commands/credentials/credentials_command/diffing.rb