Class: Fastlane::Configuration::FileReference
- Inherits:
-
Object
- Object
- Fastlane::Configuration::FileReference
- Defined in:
- lib/fastlane/plugin/wpmreleasetoolkit/models/file_reference.rb
Instance Attribute Summary collapse
-
#destination ⇒ Object
Returns the value of attribute destination.
-
#encrypt ⇒ Object
Returns the value of attribute encrypt.
-
#file ⇒ Object
Returns the value of attribute file.
Instance Method Summary collapse
-
#apply ⇒ Object
"Applies" the instruction described in the instance to the file system.
- #destination_contents ⇒ Object
- #destination_file_path ⇒ Object
- #encrypted_file_path ⇒ Object
- #encryption_key ⇒ Object
-
#initialize(params = {}) ⇒ FileReference
constructor
A new instance of FileReference.
- #needs_apply? ⇒ Boolean
- #secrets_repository_file_path ⇒ Object
- #source_contents ⇒ Object
- #to_hash ⇒ Object
- #update ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ FileReference
Returns a new instance of FileReference.
8 9 10 11 12 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/models/file_reference.rb', line 8 def initialize(params = {}) self.file = params[:file] || '' self.destination = params[:destination] || '' self.encrypt = params[:encrypt] || false end |
Instance Attribute Details
#destination ⇒ Object
Returns the value of attribute destination.
6 7 8 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/models/file_reference.rb', line 6 def destination @destination end |
#encrypt ⇒ Object
Returns the value of attribute encrypt.
6 7 8 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/models/file_reference.rb', line 6 def encrypt @encrypt end |
#file ⇒ Object
Returns the value of attribute file.
6 7 8 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/models/file_reference.rb', line 6 def file @file end |
Instance Method Details
#apply ⇒ Object
"Applies" the instruction described in the instance to the file system.
That is, copies the content of the source file to the destination path.
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/models/file_reference.rb', line 48 def apply # Only decrypt the file if the destination is ignored in Git unless Fastlane::Helper::GitHelper.is_ignored?(path: destination_file_path) raise "Attempted to decrypt #{file} to #{destination_file_path} which is not ignored under Git. Please either edit your `.configure` file to use an already-ignored destination, or add that destination to the `.gitignore` manually to fix this." end # Create the destination directory if it doesn't exist FileUtils.mkdir_p(Pathname.new(destination_file_path).dirname) # Copy/decrypt the file File.write(destination_file_path, source_contents) end |
#destination_contents ⇒ Object
22 23 24 25 26 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/models/file_reference.rb', line 22 def destination_contents return nil unless File.file?(destination_file_path) File.read(destination_file_path) end |
#destination_file_path ⇒ Object
68 69 70 71 72 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/models/file_reference.rb', line 68 def destination_file_path return File.(destination) if destination.start_with?('~') File.join(Fastlane::Helper::FilesystemHelper.project_path, destination) end |
#encrypted_file_path ⇒ Object
64 65 66 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/models/file_reference.rb', line 64 def encrypted_file_path Fastlane::Helper::FilesystemHelper.encrypted_file_path(file) end |
#encryption_key ⇒ Object
74 75 76 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/models/file_reference.rb', line 74 def encryption_key Fastlane::Helper::ConfigureHelper.encryption_key end |
#needs_apply? ⇒ Boolean
28 29 30 31 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/models/file_reference.rb', line 28 def needs_apply? destination = destination_contents destination.nil? || source_contents != destination end |
#secrets_repository_file_path ⇒ Object
60 61 62 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/models/file_reference.rb', line 60 def secrets_repository_file_path File.join(Fastlane::Helper::FilesystemHelper.secret_store_dir, file) end |
#source_contents ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/models/file_reference.rb', line 14 def source_contents return File.read(secrets_repository_file_path) unless encrypt || FastlaneCore::Helper.is_ci? return nil unless File.file?(encrypted_file_path) encrypted = File.read(encrypted_file_path) Fastlane::Helper::EncryptionHelper.decrypt(encrypted, encryption_key) end |
#to_hash ⇒ Object
78 79 80 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/models/file_reference.rb', line 78 def to_hash { file: file, destination: destination, encrypt: encrypt } end |
#update ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/models/file_reference.rb', line 33 def update return unless encrypt # Create the destination directory if it doesn't exist FileUtils.mkdir_p(Pathname.new(encrypted_file_path).dirname) # Encrypt the file file_contents = File.read(secrets_repository_file_path) encrypted = Fastlane::Helper::EncryptionHelper.encrypt(file_contents, encryption_key) File.write(encrypted_file_path, encrypted) end |