Class: CredentialsManager::AppfileConfig
- Inherits:
-
Object
- Object
- CredentialsManager::AppfileConfig
- Defined in:
- lib/credentials_manager/appfile_config.rb
Overview
Access the content of the app file (e.g. app identifier and Apple ID)
Class Method Summary collapse
Instance Method Summary collapse
-
#app_identifier(value) ⇒ Object
Setters.
- #apple_id(value) ⇒ Object
- #blocks ⇒ Object
- #data ⇒ Object
-
#for_lane(lane_name, &block) ⇒ Object
Override Appfile configuration for a specific lane.
-
#for_lane_configuration?(block) ⇒ Boolean
Private helpers.
-
#for_platform(platform_name, &block) ⇒ Object
Override Appfile configuration for a specific platform.
- #for_platform_configuration?(block) ⇒ Boolean
-
#initialize(path = nil) ⇒ AppfileConfig
constructor
A new instance of AppfileConfig.
- #team_id(value) ⇒ Object
- #team_name(value) ⇒ Object
Constructor Details
#initialize(path = nil) ⇒ AppfileConfig
Returns a new instance of AppfileConfig.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/credentials_manager/appfile_config.rb', line 19 def initialize(path = nil) path ||= self.class.default_path raise "Could not find Appfile at path '#{path}'".red unless File.exists?(path) full_path = File.(path) Dir.chdir(File.('..', path)) do eval(File.read(full_path)) end # If necessary override per lane configuration # # Appfile can specify different rules per: # - Platform # - Lane # # It is forbidden to specify multiple configuration for the same platform. It will raise an exception. # Plaform specified. if for_platform_configuration?(blocks) blocks[ENV["FASTLANE_PLATFORM_NAME"]].call inner_block = blocks[ENV["FASTLANE_PLATFORM_NAME"]] if for_lane_configuration?(inner_block) # .. Lane specified inner_block[ENV["FASTLANE_LANE_NAME"]].call end else # Platform not specified if for_lane_configuration?(blocks) # .. Lane specified blocks[ENV["FASTLANE_LANE_NAME"]].call end end end |
Class Method Details
.default_path ⇒ Object
12 13 14 15 16 17 |
# File 'lib/credentials_manager/appfile_config.rb', line 12 def self.default_path ["./fastlane/Appfile", "./Appfile"].each do |current| return current if File.exists?current end nil end |
.try_fetch_value(key) ⇒ Object
5 6 7 8 9 10 |
# File 'lib/credentials_manager/appfile_config.rb', line 5 def self.try_fetch_value(key) if self.default_path return (self.new.data[key] rescue nil) end nil end |
Instance Method Details
#app_identifier(value) ⇒ Object
Setters
64 65 66 67 |
# File 'lib/credentials_manager/appfile_config.rb', line 64 def app_identifier(value) value ||= yield if block_given? data[:app_identifier] = value if value end |
#apple_id(value) ⇒ Object
69 70 71 72 |
# File 'lib/credentials_manager/appfile_config.rb', line 69 def apple_id(value) value ||= yield if block_given? data[:apple_id] = value if value end |
#blocks ⇒ Object
54 55 56 |
# File 'lib/credentials_manager/appfile_config.rb', line 54 def blocks @blocks ||= {} end |
#data ⇒ Object
58 59 60 |
# File 'lib/credentials_manager/appfile_config.rb', line 58 def data @data ||= {} end |
#for_lane(lane_name, &block) ⇒ Object
Override Appfile configuration for a specific lane.
lane_name - Symbol representing a lane name. block - Block to execute to override configuration values.
Discussion If received lane name does not match the lane name available as environment variable, no changes will
be applied.
91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/credentials_manager/appfile_config.rb', line 91 def for_lane(lane_name, &block) raise "Configuration for lane '#{lane_name}' is defined multiple times!".red if blocks[lane_name] if ENV["FASTLANE_PLATFORM_NAME"].nil? # No platform specified, assigned configuration by lane name blocks[lane_name.to_s] = block else if ENV["FASTLANE_LANE_NAME"] # Platform and lane name specified, assigned lane configuration per different platforms blocks[ENV["FASTLANE_PLATFORM_NAME"]] = {lane_name.to_s => block } if lane_name.to_s == ENV["FASTLANE_LANE_NAME"] end end end |
#for_lane_configuration?(block) ⇒ Boolean
Private helpers
118 119 120 121 |
# File 'lib/credentials_manager/appfile_config.rb', line 118 def for_lane_configuration?(block) return block[ENV["FASTLANE_LANE_NAME"].to_s] if ENV["FASTLANE_LANE_NAME"] false end |
#for_platform(platform_name, &block) ⇒ Object
Override Appfile configuration for a specific platform.
platform_name - Symbol representing a platform name. block - Block to execute to override configuration values.
Discussion If received paltform name does not match the platform name available as environment variable, no changes will
be applied.
111 112 113 114 |
# File 'lib/credentials_manager/appfile_config.rb', line 111 def for_platform(platform_name, &block) raise "Configuration for platform '#{platform_name}' is defined multiple times!".red if blocks[platform_name] blocks[platform_name.to_s] = block end |
#for_platform_configuration?(block) ⇒ Boolean
123 124 125 126 |
# File 'lib/credentials_manager/appfile_config.rb', line 123 def for_platform_configuration?(block) return block[ENV["FASTLANE_PLATFORM_NAME"].to_s] if ENV["FASTLANE_PLATFORM_NAME"] false end |
#team_id(value) ⇒ Object
74 75 76 77 |
# File 'lib/credentials_manager/appfile_config.rb', line 74 def team_id(value) value ||= yield if block_given? data[:team_id] = value if value end |
#team_name(value) ⇒ Object
79 80 81 82 |
# File 'lib/credentials_manager/appfile_config.rb', line 79 def team_name(value) value ||= yield if block_given? data[:team_name] = value if value end |