Class: BranchIOCLI::Configuration::SetupConfiguration
- Inherits:
-
Configuration
- Object
- Configuration
- BranchIOCLI::Configuration::SetupConfiguration
- Defined in:
- lib/branch_io_cli/configuration/setup_configuration.rb
Constant Summary collapse
- APP_LINK_REGEXP =
/\.app\.link$|\.test-app\.link$/
- SDK_OPTIONS =
{ "Set this project up to use CocoaPods and add the Branch SDK." => :cocoapods, "Set this project up to use Carthage and add the Branch SDK." => :carthage, "Add Branch.framework directly to the project's dependencies." => :direct, "Skip adding the framework to the project." => :skip }
Instance Attribute Summary collapse
-
#add_sdk ⇒ Object
readonly
Returns the value of attribute add_sdk.
-
#all_domains ⇒ Object
readonly
Returns the value of attribute all_domains.
-
#carthage_command ⇒ Object
readonly
Returns the value of attribute carthage_command.
-
#commit ⇒ Object
readonly
Returns the value of attribute commit.
-
#force ⇒ Object
readonly
Returns the value of attribute force.
-
#keys ⇒ Object
readonly
Returns the value of attribute keys.
-
#patch_source ⇒ Object
readonly
Returns the value of attribute patch_source.
-
#uri_scheme ⇒ Object
readonly
Returns the value of attribute uri_scheme.
-
#validate ⇒ Object
readonly
Returns the value of attribute validate.
Attributes inherited from Configuration
#cartfile_path, #options, #pod_repo_update, #podfile, #podfile_path, #sdk_integration_mode, #target, #workspace, #workspace_path, #xcodeproj, #xcodeproj_path
Instance Method Summary collapse
- #all_domains_from_domains(domains) ⇒ Object
- #app_link_roots_from_domains(domains) ⇒ Object
- #app_link_subdomains(root) ⇒ Object
- #app_link_subdomains_from_roots(roots) ⇒ Object
- #custom_domains_from_domains(domains) ⇒ Object
- #log ⇒ Object
-
#uri_scheme_without_suffix(scheme) ⇒ Object
Removes any trailing :// from the argument and returns a copy.
- #validate_all_domains(options, required = true) ⇒ Object
- #validate_keys_from_setup_options(options) ⇒ Object
- #validate_options ⇒ Object
- #validate_sdk_addition(options) ⇒ Object
- #validate_uri_scheme(options) ⇒ Object
Methods inherited from Configuration
#bridging_header_path, #bridging_header_required?, #helper, #initialize, #modules_enabled?, #open_podfile, #print_identification, #swift_version, #uses_frameworks?, #validate_buildfile_at_path, #validate_buildfile_path, #validate_target, #validate_xcodeproj_path
Constructor Details
This class inherits a constructor from BranchIOCLI::Configuration::Configuration
Instance Attribute Details
#add_sdk ⇒ Object (readonly)
Returns the value of attribute add_sdk.
18 19 20 |
# File 'lib/branch_io_cli/configuration/setup_configuration.rb', line 18 def add_sdk @add_sdk end |
#all_domains ⇒ Object (readonly)
Returns the value of attribute all_domains.
14 15 16 |
# File 'lib/branch_io_cli/configuration/setup_configuration.rb', line 14 def all_domains @all_domains end |
#carthage_command ⇒ Object (readonly)
Returns the value of attribute carthage_command.
15 16 17 |
# File 'lib/branch_io_cli/configuration/setup_configuration.rb', line 15 def carthage_command @carthage_command end |
#commit ⇒ Object (readonly)
Returns the value of attribute commit.
21 22 23 |
# File 'lib/branch_io_cli/configuration/setup_configuration.rb', line 21 def commit @commit end |
#force ⇒ Object (readonly)
Returns the value of attribute force.
19 20 21 |
# File 'lib/branch_io_cli/configuration/setup_configuration.rb', line 19 def force @force end |
#keys ⇒ Object (readonly)
Returns the value of attribute keys.
13 14 15 |
# File 'lib/branch_io_cli/configuration/setup_configuration.rb', line 13 def keys @keys end |
#patch_source ⇒ Object (readonly)
Returns the value of attribute patch_source.
20 21 22 |
# File 'lib/branch_io_cli/configuration/setup_configuration.rb', line 20 def patch_source @patch_source end |
#uri_scheme ⇒ Object (readonly)
Returns the value of attribute uri_scheme.
16 17 18 |
# File 'lib/branch_io_cli/configuration/setup_configuration.rb', line 16 def uri_scheme @uri_scheme end |
#validate ⇒ Object (readonly)
Returns the value of attribute validate.
17 18 19 |
# File 'lib/branch_io_cli/configuration/setup_configuration.rb', line 17 def validate @validate end |
Instance Method Details
#all_domains_from_domains(domains) ⇒ Object
173 174 175 176 177 178 |
# File 'lib/branch_io_cli/configuration/setup_configuration.rb', line 173 def all_domains_from_domains(domains) app_link_roots = app_link_roots_from_domains domains app_link_subdomains = app_link_subdomains_from_roots app_link_roots custom_domains = custom_domains_from_domains domains custom_domains + app_link_subdomains end |
#app_link_roots_from_domains(domains) ⇒ Object
133 134 135 136 137 138 139 |
# File 'lib/branch_io_cli/configuration/setup_configuration.rb', line 133 def app_link_roots_from_domains(domains) return [] if domains.nil? domains.select { |d| d =~ APP_LINK_REGEXP } .map { |d| d.sub(APP_LINK_REGEXP, '').sub(/-alternate$/, '') } .uniq end |
#app_link_subdomains(root) ⇒ Object
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/branch_io_cli/configuration/setup_configuration.rb', line 146 def app_link_subdomains(root) app_link_subdomain = root return [] if app_link_subdomain.nil? live_key = keys[:live] test_key = keys[:test] 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 |
#app_link_subdomains_from_roots(roots) ⇒ Object
169 170 171 |
# File 'lib/branch_io_cli/configuration/setup_configuration.rb', line 169 def app_link_subdomains_from_roots(roots) roots.inject([]) { |domains, root| domains + app_link_subdomains(root) } end |
#custom_domains_from_domains(domains) ⇒ Object
141 142 143 144 |
# File 'lib/branch_io_cli/configuration/setup_configuration.rb', line 141 def custom_domains_from_domains(domains) return [] if domains.nil? domains.reject { |d| d =~ APP_LINK_REGEXP }.uniq end |
#log ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/branch_io_cli/configuration/setup_configuration.rb', line 56 def log super = <<-EOF <%= color('Xcode project:', BOLD) %> #{xcodeproj_path} <%= color('Target:', BOLD) %> #{target.name} <%= color('Live key:', BOLD) %> #{keys[:live] || '(none)'} <%= color('Test key:', BOLD) %> #{keys[:test] || '(none)'} <%= color('Domains:', BOLD) %> #{all_domains} <%= color('URI scheme:', BOLD) %> #{uri_scheme || '(none)'} <%= color('Podfile:', BOLD) %> #{podfile_path || '(none)'} <%= color('Cartfile:', BOLD) %> #{cartfile_path || '(none)'} <%= color('Carthage command:', BOLD) %> #{carthage_command || '(none)'} <%= color('Pod repo update:', BOLD) %> #{pod_repo_update.inspect} <%= color('Validate:', BOLD) %> #{validate.inspect} <%= color('Force:', BOLD) %> #{force.inspect} <%= color('Add SDK:', BOLD) %> #{add_sdk.inspect} <%= color('Patch source:', BOLD) %> #{patch_source.inspect} <%= color('Commit:', BOLD) %> #{commit.inspect} <%= color('SDK integration mode:', BOLD) %> #{sdk_integration_mode || '(none)'} EOF if swift_version += <<-EOF <%= color('Swift version:', BOLD) %> #{swift_version} EOF end += "\n" say end |
#uri_scheme_without_suffix(scheme) ⇒ Object
Removes any trailing :// from the argument and returns a copy
181 182 183 184 |
# File 'lib/branch_io_cli/configuration/setup_configuration.rb', line 181 def uri_scheme_without_suffix(scheme) return nil if scheme.nil? scheme.sub %r{://$}, "" end |
#validate_all_domains(options, required = true) ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/branch_io_cli/configuration/setup_configuration.rb', line 105 def validate_all_domains(, required = true) app_link_roots = app_link_roots_from_domains .domains unless .app_link_subdomain.nil? || app_link_roots.include?(.app_link_subdomain) app_link_roots << .app_link_subdomain end # app_link_roots now contains options.app_link_subdomain, if supplied, and the roots of any # .app.link or .test-app.link domains provided via options.domains. app_link_subdomains = app_link_subdomains_from_roots app_link_roots custom_domains = custom_domains_from_domains .domains @all_domains = (app_link_subdomains + custom_domains).uniq while required && @all_domains.empty? domains = ask "Please enter domains as a comma-separated list: ", ->(str) { str.split "," } @all_domains = all_domains_from_domains domains end end |
#validate_keys_from_setup_options(options) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/branch_io_cli/configuration/setup_configuration.rb', line 88 def () live_key = .live_key test_key = .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_options ⇒ Object
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 53 54 |
# File 'lib/branch_io_cli/configuration/setup_configuration.rb', line 23 def @validate = .validate @patch_source = .patch_source @add_sdk = .add_sdk @force = .force @commit = .commit say "--force is ignored when --no-validate is used." if !.validate && .force if .cartfile && .podfile say "--cartfile and --podfile are mutually exclusive. Please specify the file to patch." exit 1 end validate_xcodeproj_path validate_target validate_all_domains , !target.extension_target_type? validate_uri_scheme # If neither --podfile nor --cartfile is present, arbitrarily look for a Podfile # first. # If --cartfile is present, don't look for a Podfile. Just validate that # Cartfile. validate_buildfile_path .podfile, "Podfile" if .cartfile.nil? && .add_sdk # If --podfile is present or a Podfile was found, don't look for a Cartfile. validate_buildfile_path .cartfile, "Cartfile" if sdk_integration_mode.nil? && .add_sdk @carthage_command = .carthage_command if sdk_integration_mode == :carthage validate_sdk_addition end |
#validate_sdk_addition(options) ⇒ Object
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
# File 'lib/branch_io_cli/configuration/setup_configuration.rb', line 186 def validate_sdk_addition() return if !.add_sdk || sdk_integration_mode # If no CocoaPods or Carthage, check to see if the framework is linked. target = helper.target_from_project xcodeproj, .target return if target.frameworks_build_phase.files.map(&:file_ref).map(&:path).any? { |p| p =~ /Branch.framework$/ } # --podfile, --cartfile not specified. No Podfile found. No Cartfile found. No Branch.framework in project. # Prompt the user: selected = choose do || .header = "No Podfile or Cartfile specified or found. Here are your options" SDK_OPTIONS.each_key { |k| .choice k } .prompt = "What would you like to do?" end @sdk_integration_mode = SDK_OPTIONS[selected] case sdk_integration_mode when :cocoapods @podfile_path = File. "../Podfile", xcodeproj_path when :carthage @cartfile_path = File. "../Cartfile", xcodeproj_path @carthage_command = .carthage_command end end |
#validate_uri_scheme(options) ⇒ Object
128 129 130 131 |
# File 'lib/branch_io_cli/configuration/setup_configuration.rb', line 128 def validate_uri_scheme() # No validation at the moment. Just strips off any trailing :// @uri_scheme = uri_scheme_without_suffix .uri_scheme end |