Class: CredentialsManager::AppfileConfig

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(path = nil) ⇒ AppfileConfig

Returns a new instance of AppfileConfig.



24
25
26
27
28
29
30
31
32
33
# 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.expand_path(path)
  Dir.chdir(File.expand_path('..', path)) do
    eval(File.read(full_path))
  end
end

Class Method Details

.default_pathObject



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



41
42
43
44
45
46
47
48
# File 'lib/credentials_manager/appfile_config.rb', line 41

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



50
51
52
53
54
55
56
57
# File 'lib/credentials_manager/appfile_config.rb', line 50

def apple_id(*args, &block)
  if block_given?
    value = yield
  else
    value = args.shift
  end
  data[:apple_id] = value if value
end

#dataObject



35
36
37
# File 'lib/credentials_manager/appfile_config.rb', line 35

def data
  @data ||= {}
end

#for_lane(lane_name, &block) ⇒ Object

Override Appfile configuration for a specific lane.

lane_name - Symbol representing a lane name. (Can be either :name, ‘name’ or ‘platform 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.


84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/credentials_manager/appfile_config.rb', line 84

def for_lane(lane_name, &block)
  if lane_name.to_s.split(" ").count > 1
    # That's the legacy syntax 'platform name'
    puts "You use deprecated syntax '#{lane_name}' in your Appfile.".yellow
    puts "Please follow the Appfile guide: https://github.com/KrauseFx/fastlane/blob/master/docs/Appfile.md".yellow
    platform, lane_name = lane_name.split(" ")

    return unless platform == ENV["FASTLANE_PLATFORM_NAME"]
    # the lane name will be verified below
  end

  if ENV["FASTLANE_LANE_NAME"] == lane_name.to_s
    block.call
  end
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.


107
108
109
110
111
# File 'lib/credentials_manager/appfile_config.rb', line 107

def for_platform(platform_name, &block)
  if ENV["FASTLANE_PLATFORM_NAME"] == platform_name.to_s
    block.call
  end
end

#team_id(*args, &block) ⇒ Object



59
60
61
62
63
64
65
66
# File 'lib/credentials_manager/appfile_config.rb', line 59

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



68
69
70
71
72
73
74
75
# File 'lib/credentials_manager/appfile_config.rb', line 68

def team_name(*args, &block)
  if block_given?
    value = yield
  else
    value = args.shift
  end
  data[:team_name] = value if value
end