Class: BranchIOCLI::Configuration::Configuration
- Inherits:
-
Object
- Object
- BranchIOCLI::Configuration::Configuration
- Defined in:
- lib/branch_io_cli/configuration/configuration.rb
Direct Known Subclasses
ReportConfiguration, SetupConfiguration, ValidateConfiguration
Class Attribute Summary collapse
-
.current ⇒ Object
Returns the value of attribute current.
Instance Attribute Summary collapse
-
#cartfile_path ⇒ Object
readonly
Returns the value of attribute cartfile_path.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#pod_repo_update ⇒ Object
readonly
Returns the value of attribute pod_repo_update.
-
#podfile ⇒ Object
readonly
Returns the value of attribute podfile.
-
#podfile_path ⇒ Object
readonly
Returns the value of attribute podfile_path.
-
#sdk_integration_mode ⇒ Object
readonly
Returns the value of attribute sdk_integration_mode.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
-
#workspace ⇒ Object
readonly
Returns the value of attribute workspace.
-
#workspace_path ⇒ Object
readonly
Returns the value of attribute workspace_path.
-
#xcodeproj ⇒ Object
readonly
Returns the value of attribute xcodeproj.
-
#xcodeproj_path ⇒ Object
readonly
Returns the value of attribute xcodeproj_path.
Instance Method Summary collapse
- #bridging_header_path ⇒ Object
- #bridging_header_required? ⇒ Boolean
- #helper ⇒ Object
-
#initialize(options) ⇒ Configuration
constructor
A new instance of Configuration.
- #log ⇒ Object
-
#modules_enabled? ⇒ Boolean
TODO: How many of these can vary by configuration?.
- #open_podfile(path) ⇒ Object
- #print_identification(command) ⇒ Object
- #swift_version ⇒ Object
- #uses_frameworks? ⇒ Boolean
- #validate_buildfile_at_path(buildfile_path, filename) ⇒ Object
- #validate_buildfile_path(buildfile_path, filename) ⇒ Object
- #validate_options ⇒ Object
- #validate_target(allow_extensions = true) ⇒ Object
-
#validate_xcodeproj_path ⇒ Object
1.
Constructor Details
#initialize(options) ⇒ Configuration
Returns a new instance of Configuration.
24 25 26 27 28 29 30 31 32 |
# File 'lib/branch_io_cli/configuration/configuration.rb', line 24 def initialize() @options = @pod_repo_update = .pod_repo_update Configuration.current = self print_identification self.class.name.sub(/^.*::(.*?)Configuration$/, '\1').downcase log end |
Class Attribute Details
.current ⇒ Object
Returns the value of attribute current.
9 10 11 |
# File 'lib/branch_io_cli/configuration/configuration.rb', line 9 def current @current end |
Instance Attribute Details
#cartfile_path ⇒ Object (readonly)
Returns the value of attribute cartfile_path.
18 19 20 |
# File 'lib/branch_io_cli/configuration/configuration.rb', line 18 def cartfile_path @cartfile_path end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
12 13 14 |
# File 'lib/branch_io_cli/configuration/configuration.rb', line 12 def @options end |
#pod_repo_update ⇒ Object (readonly)
Returns the value of attribute pod_repo_update.
22 23 24 |
# File 'lib/branch_io_cli/configuration/configuration.rb', line 22 def pod_repo_update @pod_repo_update end |
#podfile ⇒ Object (readonly)
Returns the value of attribute podfile.
16 17 18 |
# File 'lib/branch_io_cli/configuration/configuration.rb', line 16 def podfile @podfile end |
#podfile_path ⇒ Object (readonly)
Returns the value of attribute podfile_path.
17 18 19 |
# File 'lib/branch_io_cli/configuration/configuration.rb', line 17 def podfile_path @podfile_path end |
#sdk_integration_mode ⇒ Object (readonly)
Returns the value of attribute sdk_integration_mode.
19 20 21 |
# File 'lib/branch_io_cli/configuration/configuration.rb', line 19 def sdk_integration_mode @sdk_integration_mode end |
#target ⇒ Object (readonly)
Returns the value of attribute target.
15 16 17 |
# File 'lib/branch_io_cli/configuration/configuration.rb', line 15 def target @target end |
#workspace ⇒ Object (readonly)
Returns the value of attribute workspace.
20 21 22 |
# File 'lib/branch_io_cli/configuration/configuration.rb', line 20 def workspace @workspace end |
#workspace_path ⇒ Object (readonly)
Returns the value of attribute workspace_path.
21 22 23 |
# File 'lib/branch_io_cli/configuration/configuration.rb', line 21 def workspace_path @workspace_path end |
#xcodeproj ⇒ Object (readonly)
Returns the value of attribute xcodeproj.
13 14 15 |
# File 'lib/branch_io_cli/configuration/configuration.rb', line 13 def xcodeproj @xcodeproj end |
#xcodeproj_path ⇒ Object (readonly)
Returns the value of attribute xcodeproj_path.
14 15 16 |
# File 'lib/branch_io_cli/configuration/configuration.rb', line 14 def xcodeproj_path @xcodeproj_path end |
Instance Method Details
#bridging_header_path ⇒ Object
191 192 193 194 195 196 197 198 199 200 |
# File 'lib/branch_io_cli/configuration/configuration.rb', line 191 def bridging_header_path return @bridging_header_path if @bridging_header_path return nil unless target path = helper. target, "SWIFT_OBJC_BRIDGING_HEADER", "Release" return nil unless path @bridging_header_path = File. path, File.dirname(xcodeproj_path) @bridging_header_path end |
#bridging_header_required? ⇒ Boolean
175 176 177 178 179 180 |
# File 'lib/branch_io_cli/configuration/configuration.rb', line 175 def bridging_header_required? return false unless swift_version # If there is a Podfile and use_frameworks! is not present for this # target, we need a bridging header. podfile && !uses_frameworks? end |
#helper ⇒ Object
54 55 56 |
# File 'lib/branch_io_cli/configuration/configuration.rb', line 54 def helper Helper::BranchHelper end |
#log ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/branch_io_cli/configuration/configuration.rb', line 38 def log say <<EOF <%= color('Configuration:', [CYAN, BOLD, UNDERLINE]) %> EOF # subclass implementation follows end |
#modules_enabled? ⇒ Boolean
TODO: How many of these can vary by configuration?
184 185 186 187 188 189 |
# File 'lib/branch_io_cli/configuration/configuration.rb', line 184 def modules_enabled? return nil unless target setting = target.resolved_build_setting("CLANG_ENABLE_MODULES")["Release"] return nil unless setting setting == "YES" end |
#open_podfile(path) ⇒ Object
140 141 142 143 144 145 146 147 |
# File 'lib/branch_io_cli/configuration/configuration.rb', line 140 def open_podfile(path) @podfile = Pod::Podfile.from_file path @podfile_path = path true rescue RuntimeError => e say e. false end |
#print_identification(command) ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/branch_io_cli/configuration/configuration.rb', line 46 def print_identification(command) say <<EOF <%= color("branch_io #{command} v. #{VERSION}", BOLD) %> EOF end |
#swift_version ⇒ Object
202 203 204 205 206 207 208 |
# File 'lib/branch_io_cli/configuration/configuration.rb', line 202 def swift_version return @swift_version if @swift_version return nil unless target @swift_version = target.resolved_build_setting("SWIFT_VERSION")["Release"] @swift_version end |
#uses_frameworks? ⇒ Boolean
168 169 170 171 172 173 |
# File 'lib/branch_io_cli/configuration/configuration.rb', line 168 def uses_frameworks? return nil unless podfile target_definition = podfile.target_definition_list.find { |t| t.name == target.name } return nil unless target_definition target_definition.uses_frameworks? end |
#validate_buildfile_at_path(buildfile_path, filename) ⇒ Object
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/branch_io_cli/configuration/configuration.rb', line 149 def validate_buildfile_at_path(buildfile_path, filename) valid = buildfile_path =~ %r{/?#{filename}$} say "#{filename} path must end in /#{filename}." unless valid if valid valid = File.exist? buildfile_path say "#{buildfile_path} not found." unless valid end if filename == "Podfile" && open_podfile(buildfile_path) true elsif filename == "Cartfile" @cartfile_path = buildfile_path true else false end end |
#validate_buildfile_path(buildfile_path, filename) ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/branch_io_cli/configuration/configuration.rb', line 121 def validate_buildfile_path(buildfile_path, filename) # Disable Podfile/Cartfile update if --no-add-sdk is present return unless sdk_integration_mode.nil? # No --podfile or --cartfile option if buildfile_path.nil? # Check for Podfile/Cartfile next to workspace or project buildfile_path = File. "../#{filename}", (workspace_path || xcodeproj_path) return unless File.exist? buildfile_path end # Validate. Prompt if not valid. while !buildfile_path || !validate_buildfile_at_path(buildfile_path, filename) buildfile_path = ask "Please enter the path to your #{filename}: " end @sdk_integration_mode = filename == "Podfile" ? :cocoapods : :carthage end |
#validate_options ⇒ Object
34 35 36 |
# File 'lib/branch_io_cli/configuration/configuration.rb', line 34 def # implemented in subclasses end |
#validate_target(allow_extensions = true) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/branch_io_cli/configuration/configuration.rb', line 93 def validate_target(allow_extensions = true) non_test_targets = xcodeproj.targets.reject(&:test_target_type?) raise "No non-test target found in project" if non_test_targets.empty? valid_targets = non_test_targets.reject { |t| !allow_extensions && t.extension_target_type? } begin target = helper.target_from_project xcodeproj, .target # If a test target was explicitly specified. raise "Cannot use test targets" if target.test_target_type? # If an extension target was explicitly specified for validation. raise "Extension targets not allowed for this command" if !allow_extensions && target.extension_target_type? @target = target rescue StandardError => e say e. choice = choose do || valid_targets.each { |t| .choice t.name } .prompt = "Which target do you wish to use? " end @target = xcodeproj.targets.find { |t| t.name = choice } end end |
#validate_xcodeproj_path ⇒ Object
-
Look for options.xcodeproj.
-
If not specified, look for projects under . (excluding anything in Pods or Carthage folder).
-
If none or more than one found, prompt the user.
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 87 88 89 90 91 |
# File 'lib/branch_io_cli/configuration/configuration.rb', line 61 def validate_xcodeproj_path if .xcodeproj path = .xcodeproj else all_xcodeproj_paths = Dir[File.(File.join(".", "**/*.xcodeproj"))] # find an xcodeproj (ignoring the Pods and Carthage folders) # TODO: Improve this filter xcodeproj_paths = all_xcodeproj_paths.select do |p| valid = true Pathname.new(p).each_filename do |f| valid = false && break if f == "Carthage" || f == "Pods" end valid end 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 @xcodeproj_path = path return rescue StandardError => e say e. path = nil end end end |