Class: BranchIOCLI::Helper::ConfigurationHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/branch_io_cli/helper/configuration_helper.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.all_domainsObject

Returns the value of attribute all_domains.



9
10
11
# File 'lib/branch_io_cli/helper/configuration_helper.rb', line 9

def all_domains
  @all_domains
end

.keysObject

Returns the value of attribute keys.



8
9
10
# File 'lib/branch_io_cli/helper/configuration_helper.rb', line 8

def keys
  @keys
end

.xcodeprojObject

Returns the value of attribute xcodeproj.



7
8
9
# File 'lib/branch_io_cli/helper/configuration_helper.rb', line 7

def xcodeproj
  @xcodeproj
end

Class Method Details



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/branch_io_cli/helper/configuration_helper.rb', line 77

def app_link_subdomains(options)
  app_link_subdomain = options.app_link_subdomain
  live_key = options.live_key
  test_key = options.test_key
  return [] if live_key.nil? and test_key.nil?
  return [] if app_link_subdomain.nil?

  domains = []
  unless live_key.nil?
    domains += [
      "#{app_link_subdomain}.app.link",
      "#{app_link_subdomain}-alternate.app.link"
    ]
  end
  unless test_key.nil?
    domains += [
      "#{app_link_subdomain}.test-app.link",
      "#{app_link_subdomain}-alternate.test-app.link"
    ]
  end
  domains
end

.validate_all_domains(options) ⇒ Object



40
41
42
43
44
45
46
47
48
# File 'lib/branch_io_cli/helper/configuration_helper.rb', line 40

def validate_all_domains(options)
  app_link_subdomains = app_link_subdomains options
  custom_domains = options.domains || []
  @all_domains = (app_link_subdomains + custom_domains).uniq

  while @all_domains.empty?
    @all_domains = ask "Please enter domains as a comma-separated list: ", ->(str) { str.split "," }
  end
end

.validate_keys_from_setup_options(options) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/branch_io_cli/helper/configuration_helper.rb', line 23

def validate_keys_from_setup_options(options)
  live_key = options.live_key
  test_key = options.test_key
  @keys = {}
  @keys[:live] = live_key unless live_key.nil?
  @keys[:test] = test_key unless test_key.nil?

  while @keys.empty?
    say "A live key, a test key or both is required."
    live_key = ask "Please enter your live Branch key or use --live_key [enter for none]: "
    test_key = ask "Please enter your test Branch key or use --test_key [enter for none]: "

    @keys[:live] = live_key unless live_key == ""
    @keys[:test] = test_key unless test_key == ""
  end
end

.validate_setup_options(options) ⇒ Object



11
12
13
14
15
16
# File 'lib/branch_io_cli/helper/configuration_helper.rb', line 11

def validate_setup_options(options)
  options.xcodeproj = xcodeproj_path options
  validate_keys_from_setup_options options
  validate_all_domains options
  options
end

.validate_validation_options(options) ⇒ Object



18
19
20
21
# File 'lib/branch_io_cli/helper/configuration_helper.rb', line 18

def validate_validation_options(options)
  options.xcodeproj = xcodeproj_path options
  options
end

.xcodeproj_path(options) ⇒ Object

  1. Look for options.xcodeproj.

  2. If not specified, look for projects under . (excluding anything in Pods or Carthage folder).

  3. If none or more than one found, prompt the user.



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/branch_io_cli/helper/configuration_helper.rb', line 53

def xcodeproj_path(options)
  if options.xcodeproj
    path = options.xcodeproj
  else
    all_xcodeproj_paths = Dir[File.expand_path(File.join(".", "**/*.xcodeproj"))]
    # find an xcodeproj (ignoring the Pods and Carthage folders)
    # TODO: Improve this filter
    xcodeproj_paths = all_xcodeproj_paths.reject { |p| p =~ /Pods|Carthage/ }

    path = xcodeproj_paths.first if xcodeproj_paths.count == 1
  end

  loop do
    path = ask "Please enter the path to your Xcode project or use --xcodeproj: " if path.nil?
    # TODO: Allow the user to choose if xcodeproj_paths.count > 0
    begin
      @xcodeproj = Xcodeproj::Project.open path
      return path
    rescue StandardError => e
      say e.message
    end
  end
end