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(*args, &block) ⇒ Object
Setters.
- #apple_id(*args, &block) ⇒ 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(*args, &block) ⇒ Object
- #team_name(*args, &block) ⇒ Object
Constructor Details
#initialize(path = nil) ⇒ AppfileConfig
Returns a new instance of AppfileConfig.
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 53 54 55 56 57 |
# File 'lib/credentials_manager/appfile_config.rb', line 24 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. if for_platform_configuration?(blocks) # Plaform specified. 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
17 18 19 20 21 22 |
# File 'lib/credentials_manager/appfile_config.rb', line 17 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 11 12 13 14 15 |
# File 'lib/credentials_manager/appfile_config.rb', line 5 def self.try_fetch_value(key) if self.default_path begin return self.new.data[key] rescue => ex puts ex.to_s return nil end end nil end |
Instance Method Details
#app_identifier(*args, &block) ⇒ Object
Setters
69 70 71 72 73 74 75 76 |
# File 'lib/credentials_manager/appfile_config.rb', line 69 def app_identifier(*args, &block) if block_given? value = yield else value = args.shift end data[:app_identifier] = value if value end |
#apple_id(*args, &block) ⇒ Object
78 79 80 81 82 83 84 85 |
# File 'lib/credentials_manager/appfile_config.rb', line 78 def apple_id(*args, &block) if block_given? value = yield else value = args.shift end data[:apple_id] = value if value end |
#blocks ⇒ Object
59 60 61 |
# File 'lib/credentials_manager/appfile_config.rb', line 59 def blocks @blocks ||= {} end |
#data ⇒ Object
63 64 65 |
# File 'lib/credentials_manager/appfile_config.rb', line 63 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.
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/credentials_manager/appfile_config.rb', line 112 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"].to_s.strip.empty? # No platform specified, assigned configuration by lane name blocks[lane_name.to_s] = block else if ENV["FASTLANE_LANE_NAME"] # The for_lane could be formatted as: # - only {lane_name} (i.e. 'for_lane beta ...') # - {platform_name} {lane_name} (i.e. 'for_lane "ios beta" ...') # # Either case it is a valid configuration to run the overwriting of the settings. if lane_name.to_s == "#{ENV["FASTLANE_PLATFORM_NAME"]} #{ENV["FASTLANE_LANE_NAME"]}" || lane_name.to_s == ENV["FASTLANE_LANE_NAME"] blocks[ENV["FASTLANE_LANE_NAME"]] = block end end end end |
#for_lane_configuration?(block) ⇒ Boolean
Private helpers
145 146 147 148 |
# File 'lib/credentials_manager/appfile_config.rb', line 145 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.
138 139 140 141 |
# File 'lib/credentials_manager/appfile_config.rb', line 138 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
150 151 152 153 |
# File 'lib/credentials_manager/appfile_config.rb', line 150 def for_platform_configuration?(block) return block[ENV["FASTLANE_PLATFORM_NAME"].to_s] if ENV["FASTLANE_PLATFORM_NAME"] false end |
#team_id(*args, &block) ⇒ Object
87 88 89 90 91 92 93 94 |
# File 'lib/credentials_manager/appfile_config.rb', line 87 def team_id(*args, &block) if block_given? value = yield else value = args.shift end data[:team_id] = value if value end |
#team_name(*args, &block) ⇒ Object
96 97 98 99 100 101 102 103 |
# File 'lib/credentials_manager/appfile_config.rb', line 96 def team_name(*args, &block) if block_given? value = yield else value = args.shift end data[:team_name] = value if value end |