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.
6 7 8 9 10 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/models/file_reference.rb', line 6 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.
4 5 6 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/models/file_reference.rb', line 4 def destination @destination end |
#encrypt ⇒ Object
Returns the value of attribute encrypt.
4 5 6 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/models/file_reference.rb', line 4 def encrypt @encrypt end |
#file ⇒ Object
Returns the value of attribute file.
4 5 6 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/models/file_reference.rb', line 4 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.
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/models/file_reference.rb', line 46 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
20 21 22 23 24 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/models/file_reference.rb', line 20 def destination_contents return nil unless File.file?(destination_file_path) File.read(destination_file_path) end |
#destination_file_path ⇒ Object
66 67 68 69 70 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/models/file_reference.rb', line 66 def destination_file_path return File.(destination) if destination.start_with?('~') File.join(Fastlane::Helper::FilesystemHelper.project_path, destination) end |
#encrypted_file_path ⇒ Object
62 63 64 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/models/file_reference.rb', line 62 def encrypted_file_path Fastlane::Helper::FilesystemHelper.encrypted_file_path(file) end |
#encryption_key ⇒ Object
72 73 74 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/models/file_reference.rb', line 72 def encryption_key Fastlane::Helper::ConfigureHelper.encryption_key end |
#needs_apply? ⇒ Boolean
26 27 28 29 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/models/file_reference.rb', line 26 def needs_apply? destination = destination_contents destination.nil? || source_contents != destination end |
#secrets_repository_file_path ⇒ Object
58 59 60 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/models/file_reference.rb', line 58 def secrets_repository_file_path File.join(Fastlane::Helper::FilesystemHelper.secret_store_dir, file) end |
#source_contents ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/models/file_reference.rb', line 12 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
76 77 78 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/models/file_reference.rb', line 76 def to_hash { file: file, destination: destination, encrypt: encrypt } end |
#update ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/models/file_reference.rb', line 31 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 |