Class: Rails::Command::ConflictedCredentialsCommand::ConflictedCredentials

Inherits:
Object
  • Object
show all
Defined in:
lib/rails/commands/conflicted_credentials/conflicted_credentials_command/conflicted_credentials.rb

Constant Summary collapse

GIT_CONFLICT_MARKER =
/^<{7} (?:(?!={7})[\s\S])*={7}(?:(?!>{7} \w+)[\s\S])*>{7} .+/

Instance Method Summary collapse

Constructor Details

#initialize(content_path, key_path) ⇒ ConflictedCredentials

Returns a new instance of ConflictedCredentials.



11
12
13
14
15
16
17
# File 'lib/rails/commands/conflicted_credentials/conflicted_credentials_command/conflicted_credentials.rb', line 11

def initialize(content_path, key_path)
  @content_path = content_path
  @key_path = key_path
  return if content_path.blank? || !File.exist?(content_path)

  @file_data = File.binread(content_path).strip
end

Instance Method Details

#conflicts?Boolean

Returns:

  • (Boolean)


19
20
21
22
23
# File 'lib/rails/commands/conflicted_credentials/conflicted_credentials_command/conflicted_credentials.rb', line 19

def conflicts?
  return false if @file_data.nil?

  @file_data.match?(GIT_CONFLICT_MARKER)
end

#internalise_conflictsObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/rails/commands/conflicted_credentials/conflicted_credentials_command/conflicted_credentials.rb', line 25

def internalise_conflicts
  left_unencrypted_string, right_unencrypted_string = decrypt_individual_files
  return if right_unencrypted_string.nil?

  conflicted_unencrypted_string = merge_conflicted_strings(
    left_unencrypted_string,
    right_unencrypted_string
  )

  ActiveSupport::EncryptedFile.new(
    content_path: @content_path,
    key_path: @key_path,
    env_key: "RAILS_MASTER_KEY",
    raise_if_missing_key: true
  ).write(conflicted_unencrypted_string)
end