Class: Match::Storage::Interface

Inherits:
Object
  • Object
show all
Defined in:
match/lib/match/storage/interface.rb

Direct Known Subclasses

GitStorage, GoogleCloudStorage

Constant Summary collapse

MATCH_VERSION_FILE_NAME =
"match_version.txt"

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#working_directoryObject

To make debugging easier, we have a custom exception here



9
10
11
# File 'match/lib/match/storage/interface.rb', line 9

def working_directory
  @working_directory
end

Instance Method Details

#clear_changesObject

Call this method to reset any changes made locally to the files



86
87
88
89
90
91
# File 'match/lib/match/storage/interface.rb', line 86

def clear_changes
  return unless @working_directory

  FileUtils.rm_rf(self.working_directory)
  self.working_directory = nil
end

#configureObject

Call this method after creating a new object to configure the given Storage object. This method will take different paramters depending on specific class being used



22
23
24
# File 'match/lib/match/storage/interface.rb', line 22

def configure
  not_implemented(__method__)
end

#delete_files(files_to_delete: [], custom_message: nil) ⇒ Object



77
78
79
# File 'match/lib/match/storage/interface.rb', line 77

def delete_files(files_to_delete: [], custom_message: nil)
  not_implemented(__method__)
end

#downloadObject

Call this method for the initial clone/download of the user’s certificates & profiles As part of this method, the ‘self.working_directory` attribute will be set



30
31
32
# File 'match/lib/match/storage/interface.rb', line 30

def download
  not_implemented(__method__)
end

#save_changes!(files_to_commit: nil, files_to_delete: nil, custom_message: nil) ⇒ Object

Call this method after locally modifying the files This will commit the changes and push it back to the given remote server This method is blocking, meaning it might take multiple seconds or longer to run



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'match/lib/match/storage/interface.rb', line 43

def save_changes!(files_to_commit: nil, files_to_delete: nil, custom_message: nil)
  # Custom init to `[]` in case `nil` is passed
  files_to_commit ||= []
  files_to_delete ||= []

  Dir.chdir(File.expand_path(self.working_directory)) do
    if files_to_commit.count > 0 # everything that isn't `match nuke`
      UI.user_error!("You can't provide both `files_to_delete` and `files_to_commit` right now") if files_to_delete.count > 0

      if !File.exist?(MATCH_VERSION_FILE_NAME) || File.read(MATCH_VERSION_FILE_NAME) != Fastlane::VERSION.to_s
        files_to_commit << MATCH_VERSION_FILE_NAME
        File.write(MATCH_VERSION_FILE_NAME, Fastlane::VERSION) # stored unencrypted
      end

      template = File.read("#{Match::ROOT}/lib/assets/READMETemplate.md")
      readme_path = "README.md"
      if (!File.exist?(readme_path) || File.read(readme_path) != template) && !self.skip_docs
        files_to_commit << readme_path
        File.write(readme_path, template)
      end

      self.upload_files(files_to_upload: files_to_commit, custom_message: custom_message)
    elsif files_to_delete.count > 0
      self.delete_files(files_to_delete: files_to_delete, custom_message: custom_message)
    else
      UI.user_error!("Neither `files_to_commit` nor `files_to_delete` were provided to the `save_changes!` method call")
    end
  end
end

#skip_docsObject



81
82
83
# File 'match/lib/match/storage/interface.rb', line 81

def skip_docs
  not_implemented(__method__)
end

#upload_files(files_to_upload: [], custom_message: nil) ⇒ Object



73
74
75
# File 'match/lib/match/storage/interface.rb', line 73

def upload_files(files_to_upload: [], custom_message: nil)
  not_implemented(__method__)
end