podmode 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1fc4643d12cf7b8ee78c6e93bcba96d95cddd394
4
+ data.tar.gz: 121a7639199cf119bf1bd93f1e2749969f1367a3
5
+ SHA512:
6
+ metadata.gz: d01f0cd860e85a198854377a6a4dbb849e6bf3bdddcc6fefbe6958c5c1fbf8beb006854ea63de4b421cf364c5af6b4a63c5d83d7b8cbe38281274cae7d280028
7
+ data.tar.gz: e1ba1a512bcdcf6c10bdc89bd674d030d25bb7c0ee6e64b4f05bcf26899fc1903cb63775560517580e6695f82468c4ab051ca2872a54c61757c0d33b2df4fbb0
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.0
5
+ before_install: gem install bundler -v 1.13.7
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Toine Heuvelmans
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,64 @@
1
+ # Podmode
2
+
3
+ Podmode is a small tool that allows you to easily specify a local directory for a development pod when using Cocoapods. You can dynamically switch between using the local project or checking out the project from its remote source url.
4
+
5
+ It allows for different configurations without needing to alter the Podfile. Across developers the local path will vary, and the CI server will likely need to check out the project from the server.
6
+
7
+ ## Installation
8
+
9
+ You can install the gem as follows:
10
+
11
+ $ gem install ./podmode-0.1.0.gem
12
+
13
+ You might need to install `dotenv` too:
14
+
15
+ $ gem install dotenv
16
+
17
+ ### Troubleshooting
18
+
19
+ It might be that you run into trouble when running podmode. Make sure the required directory is created, by executing:
20
+
21
+ ```bash
22
+ mkdir -p ~/.touchwonders/podmodes/
23
+ ```
24
+
25
+ ## Defining a Podmode for a local project
26
+
27
+ In the terminal, navigate to a project directory that contains a podspec. You can run `podmode` to see available options.
28
+
29
+ Run the following to create a `podmode` for your project:
30
+
31
+ ```bash
32
+ podmode create YourProject
33
+ ```
34
+
35
+ You'll be asked to specify a mode. Select 1: local.
36
+
37
+ You'll then be asked to specify the path. You can enter `.` to specify the current directory.
38
+
39
+ In the Podfile that needs to include your project, you can specify the podmode as follows:
40
+
41
+ ```
42
+ require 'podmode'
43
+ ...
44
+ pod 'YourProject', Podmode::Podmode.new('YourProject', 'git@gitlab.api-touchwonders.com:components/yourproject.git').options()
45
+ ...
46
+ ```
47
+
48
+ This will ensure the Podfile will target the local directory that you specified for your project.
49
+
50
+ ## Other modes
51
+
52
+ You can specify a different pod mode on creation or when editing an existing `podmode`.
53
+
54
+ ### Auto
55
+
56
+ Will use the git url specified in the Podfile (see above), using the default branch.
57
+
58
+ ### Branch
59
+
60
+ Will use the git url specified in the Podfile, using the branch specified in the `podmode`.
61
+
62
+ ### Tag
63
+
64
+ Will use the git url specified in the Podfile, using the tag specified in the `podmode`.
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "podmode"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/podmode ADDED
@@ -0,0 +1,183 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "cocoapods"
4
+ require "podmode"
5
+ require "fileutils"
6
+
7
+ module Podmode
8
+
9
+ def self.run()
10
+ action = ARGV[0]
11
+ action_method = action_method(action)
12
+ if action_method.nil?
13
+ help()
14
+ else
15
+ action_method.call()
16
+ end
17
+ end
18
+
19
+ def self.help()
20
+ puts "Specify one of the following actions:\n\n"
21
+ actions().each do |action_method, desc|
22
+ puts " #{String(action_method.name).ljust(10)}#{desc}"
23
+ end
24
+ end
25
+
26
+ def self.version()
27
+ puts ::Podmode::VERSION
28
+ end
29
+
30
+ # OPTIONS:
31
+
32
+ def self.list()
33
+ podmodes = available_podmodes()
34
+ if podmodes.size() == 0
35
+ puts " - No podmodes configured - "
36
+ else
37
+ podmodes.each do |podmode|
38
+ puts "- #{podmode[:name]}"
39
+ puts " path: #{podmode[:path]}"
40
+ puts " contents:"
41
+ podmode[:contents].lines.each { |l| puts (' ' * 10) + l }
42
+ puts "\n"
43
+ end
44
+ end
45
+ end
46
+
47
+ def self.create()
48
+ name = ARGV[1]
49
+ if name.nil?
50
+ puts "Required name attribute is missing. [podmode create NAME]"
51
+ return
52
+ end
53
+ name = name.strip
54
+ path = podmode_filepath(name)
55
+
56
+ if File.file?(path)
57
+ if Prompt::bool('Podmode file already exists, edit it?')
58
+ edit()
59
+ end
60
+ return
61
+ end
62
+ puts "Creating podmode for '#{name}'"
63
+ edit_podmode(name)
64
+ puts "Podmode created for '#{name}'"
65
+ print_contents(path)
66
+ end
67
+
68
+ def self.edit()
69
+ name = ARGV[1]
70
+ if name.nil?
71
+ puts "Required name attribute is missing. [podmode edit NAME]"
72
+ return
73
+ end
74
+ name = name.strip
75
+ path = podmode_filepath(name)
76
+
77
+ if File.file?(path) == false
78
+ if Prompt::bool('Podmode file does not exist, create it?')
79
+ create()
80
+ end
81
+ return
82
+ end
83
+
84
+ puts "Editing podmode for '#{name}'"
85
+ print_contents(path)
86
+ edit_podmode(name)
87
+ puts "Podmode edited for '#{name}'"
88
+ print_contents(path)
89
+ end
90
+
91
+ def self.remove()
92
+ name = ARGV[1]
93
+ if name.nil?
94
+ puts "Required name attribute is missing. [podmode remove NAME]"
95
+ return
96
+ end
97
+ name = name.strip
98
+ path = podmode_filepath(name)
99
+ if File.file?(path) == false
100
+ puts "No podmode file found for #{name}, nothing removed."
101
+ end
102
+ File.delete(path)
103
+ puts "Podmode removed for #{name}."
104
+ end
105
+
106
+ # ---------------
107
+
108
+ private
109
+
110
+ def self.actions()
111
+ return {method(:list) => "Lists currently configured podmodes",
112
+ method(:create) => "Creates a new podmode; [podmode create NAME]",
113
+ method(:edit) => "Edits an existing podmode; [podmode edit NAME]",
114
+ method(:remove) => "Removes an existing podmode; [podmode remove NAME]",
115
+ method(:help) => "Shows the available podmode actions",
116
+ method(:version) => "Prints the current version of Podmode"}
117
+ end
118
+
119
+ def self.action_method(action_name)
120
+ return if action_name.nil?
121
+ action_name = action_name.strip
122
+ actions().each do |action_method, desc|
123
+ if String(action_method.name) == action_name
124
+ return action_method
125
+ end
126
+ end
127
+ puts "Unknown action '#{action_name}'"
128
+ return nil
129
+ end
130
+
131
+ def self.available_podmodes()
132
+ dir = podmodes_dir()
133
+ podmodes = []
134
+ if File.directory?(dir)
135
+ Dir["#{dir}/*.podmode"].each do |podmode|
136
+ podmodes.push({name: File.basename(podmode, ".*"),
137
+ path: podmode,
138
+ contents: File.read(podmode)})
139
+ end
140
+ end
141
+ return podmodes
142
+ end
143
+
144
+ def self.podmode_filepath(name)
145
+ dir = podmodes_dir()
146
+ FileUtils::mkdir_p dir
147
+ return File.join(dir, "#{name.downcase}.podmode")
148
+ end
149
+
150
+ def self.edit_podmode(name)
151
+ puts "- Available modes:"
152
+ modes = ['auto', 'local', 'branch', 'tag']
153
+ modes.each_with_index {|mode, ind| puts " [#{ind}] #{mode}"}
154
+ mode = Prompt::index(modes, 'Select a mode')
155
+
156
+ content = []
157
+ content.push("#{name.upcase}_PODMODE=#{mode}")
158
+
159
+ case mode
160
+ when 'local'
161
+ path = Prompt::prompt('Specify the local path: ')
162
+ fullpath = File.expand_path(path.strip)
163
+ content.push("#{name.upcase}_PODMODE_PATH=\"#{fullpath}\"")
164
+ when 'branch'
165
+ branch = Prompt::prompt('Specify the branch to check out: ')
166
+ content.push("#{name.upcase}_PODMODE_BRANCH=#{branch.strip}")
167
+ when 'tag'
168
+ tag = Prompt::prompt('Specify the tag to check out: ')
169
+ content.push("#{name.upcase}_PODMODE_TAG=#{tag.strip}")
170
+ end
171
+
172
+ File.open(podmode_filepath(name), 'w') { |f| f.write(content.join("\n")) }
173
+ end
174
+
175
+ def self.print_contents(path)
176
+ Console::separator()
177
+ puts "Current contents:"
178
+ File.read(path).lines.each { |l| puts (' ' * 4) + l }
179
+ Console::separator()
180
+ end
181
+ end
182
+
183
+ Podmode::run()
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/lib/podmode.rb ADDED
@@ -0,0 +1,82 @@
1
+ require 'podmode/version'
2
+ require 'podmode/touchwonders'
3
+ require 'podmode/prompt'
4
+ require 'podmode/console'
5
+ require 'dotenv'
6
+
7
+ module Podmode
8
+
9
+ def self.podmodes_dir()
10
+ return File.join(Touchwonders::config_dir(), 'podmodes')
11
+ end
12
+
13
+ def self.for(name, git_url)
14
+ return ::Podmode::Podmode.new(name, git_url).options()
15
+ end
16
+
17
+ class Podmode
18
+ def initialize(name, git_url)
19
+ @name = name
20
+ @git_url = git_url
21
+ end
22
+
23
+ def options()
24
+ load()
25
+
26
+ options = {}
27
+ pod_mode = pod_mode()
28
+
29
+ if pod_mode.nil? || pod_mode.empty? || pod_mode == 'auto'
30
+ options[:git] = "ssh://#{@git_url}"
31
+ else
32
+ case pod_mode
33
+ when 'local'
34
+ options[:path] = pod_path()
35
+
36
+ when 'branch'
37
+ options[:git] = "ssh://#{@git_url}"
38
+ options[:branch] = pod_branch()
39
+
40
+ when 'tag'
41
+ options[:git] = "ssh://#{@git_url}"
42
+ options[:tag] = pod_tag()
43
+ end
44
+ end
45
+
46
+ return options
47
+ end
48
+
49
+ private
50
+
51
+ def load()
52
+ user_config = File.join(::Podmode.podmodes_dir(), "#{@name.downcase}.podmode")
53
+ if File.exist? user_config
54
+ puts "Reading #{user_config}"
55
+ Dotenv.load!(user_config)
56
+ end
57
+
58
+ if File.exist? '.env.local'
59
+ puts "Loading local environment variables from '.env.local'"
60
+ Dotenv.overload('.env.local')
61
+ end
62
+ end
63
+
64
+
65
+ def pod_mode()
66
+ return ENV["#{@name.upcase}_PODMODE"]
67
+ end
68
+
69
+ def pod_path
70
+ return ENV["#{@name.upcase}_PODMODE_PATH"]
71
+ end
72
+
73
+ def pod_branch
74
+ return ENV["#{@name.upcase}_PODMODE_BRANCH"]
75
+ end
76
+
77
+ def pod_tag
78
+ return ENV["#{@name.upcase}_PODMODE_TAG"]
79
+ end
80
+
81
+ end
82
+ end
@@ -0,0 +1,13 @@
1
+ require 'io/console'
2
+
3
+ module Console
4
+
5
+ def self.width
6
+ $stdin.winsize[1]
7
+ end
8
+
9
+ def self.separator(str='-')
10
+ puts str * width
11
+ end
12
+
13
+ end
@@ -0,0 +1,46 @@
1
+ module Prompt
2
+
3
+ def self.prompt(*args)
4
+ print(*args)
5
+ STDIN.gets.chomp
6
+ end
7
+
8
+ def self.bool(message)
9
+ message = message + " (y/n): "
10
+ input = prompt message
11
+ input = input.strip
12
+ return input.casecmp("y") == 0 || input.casecmp("yes") == 0
13
+ end
14
+
15
+ def self.integer(min, max, message)
16
+ input = prompt "> #{message}: "
17
+ input = input.strip.to_i
18
+ if input < min || input > max
19
+ puts "! Specified index #{input} is outside allowed range #{min}-#{max}"
20
+ return integer(min, max, message)
21
+ else
22
+ return input
23
+ end
24
+ end
25
+
26
+ def self.index(options_array, message)
27
+ selected_index = integer(0, options_array.size - 1, message)
28
+ puts "selected_index: #{selected_index}"
29
+ puts options_array.inspect
30
+ return options_array[selected_index]
31
+ end
32
+
33
+ def self.option(options_hash, message)
34
+ options_hash.each { |k,v| puts "[#{k}] #{v}" }
35
+ input = prompt "> #{message}: "
36
+ input = input.strip
37
+
38
+ selected_option = options_hash[input]
39
+ if selected_option.nil?
40
+ puts "! Specified option '#{input}' is not available"
41
+ return option(options_hash, message)
42
+ else
43
+ return selected_option
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,6 @@
1
+ module Touchwonders
2
+ # Will be moved to a shared "Touchwonders Toolchain" core library
3
+ def self.config_dir()
4
+ return ENV['TOUCHWONDERS_ROOT'] || File.join(ENV['HOME'], '.touchwonders')
5
+ end
6
+ end
@@ -0,0 +1,3 @@
1
+ module Podmode
2
+ VERSION = "0.2.0"
3
+ end
data/podmode-0.1.0.gem ADDED
Binary file
data/podmode.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'podmode/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "podmode"
8
+ spec.version = Podmode::VERSION
9
+ spec.authors = ["Toine Heuvelmans"]
10
+ spec.email = ["toine@touchwonders.com"]
11
+
12
+ spec.summary = "Helper for defining and interpreting Cocoapods dependency modes."
13
+ spec.description = "A dependency can be local or remote. If remote, it can be a specific branch, or a specific tag."
14
+ spec.license = "Nonstandard"
15
+ spec.homepage = "https://www.touchwonders.com"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "bin"
21
+ spec.executables << 'podmode'
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.13"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec", "~> 3.0"
27
+
28
+ spec.add_dependency "dotenv", "~> 2.2"
29
+ end
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: podmode
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Toine Heuvelmans
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-07-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.13'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.13'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: dotenv
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.2'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.2'
69
+ description: A dependency can be local or remote. If remote, it can be a specific
70
+ branch, or a specific tag.
71
+ email:
72
+ - toine@touchwonders.com
73
+ executables:
74
+ - podmode
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - ".gitignore"
79
+ - ".rspec"
80
+ - ".travis.yml"
81
+ - Gemfile
82
+ - LICENSE.txt
83
+ - README.md
84
+ - Rakefile
85
+ - bin/console
86
+ - bin/podmode
87
+ - bin/setup
88
+ - lib/podmode.rb
89
+ - lib/podmode/console.rb
90
+ - lib/podmode/prompt.rb
91
+ - lib/podmode/touchwonders.rb
92
+ - lib/podmode/version.rb
93
+ - podmode-0.1.0.gem
94
+ - podmode.gemspec
95
+ homepage: https://www.touchwonders.com
96
+ licenses:
97
+ - Nonstandard
98
+ metadata: {}
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ requirements: []
114
+ rubyforge_project:
115
+ rubygems_version: 2.5.1
116
+ signing_key:
117
+ specification_version: 4
118
+ summary: Helper for defining and interpreting Cocoapods dependency modes.
119
+ test_files: []