cocoapods-roulette 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a9a73ba49e7f849cabc4628bf920a7c2495c4a6c
4
- data.tar.gz: 81d34f157ce37a6765e613e972498fb48d7bf542
3
+ metadata.gz: d0511dbeb1992eb8e5b8df014f1be3ba72db5b9c
4
+ data.tar.gz: 1ed98d91e3415c5c411d954d96bf1d5f3b9484bb
5
5
  SHA512:
6
- metadata.gz: 0801fef52090894925620608fc494763def52bba5009066bf395a69ff79baf233f56e40fa4bac00877b8e018dea59abf953c9478608ca28f8b4e3b399133d4c3
7
- data.tar.gz: c25bc2201125164423f9514417ac3de46e8b5e3eb4c0bfe1ba6fca7514eed288ebef675d28b5bee84cbf7fd0b2855fd330cd2ea16e181543359eddf16f3e2ee9
6
+ metadata.gz: 34784c3b773040f887e23e3e1b13463612c9e91ac3395d6cd49af244a9633617398c7ebda0ab8f2c8415f88762c9ff0eb935d3f20b31cddef18a0e3ca36936dd
7
+ data.tar.gz: ba684568dba5230164b7560fb43187cd87008701b9818c9aef192d93c57ef896e686bf8a8f15d38396e377ad6d33edd2d143c8017c43e0b2660d75e50d7b2667
@@ -1 +1,2 @@
1
- require 'pod/command/roulette'
1
+ require 'pod/command/roulette'
2
+ require 'pod/command/roulettathon'
@@ -1,3 +1,3 @@
1
1
  class CocoapodsRoulette
2
- VERSION = "1.0.1"
3
- end
2
+ VERSION = "1.0.2"
3
+ end
@@ -0,0 +1,69 @@
1
+ # encoding: utf-8
2
+ module Pod
3
+ class Command
4
+ class Roulettathon < Command
5
+ self.summary = "An easy entrypoint for taking part in a Roulettathon"
6
+
7
+ self.description = <<-DESC
8
+ Only asks a few times before you have to settle for a podroulette configuration.
9
+ DESC
10
+
11
+ WINK = [0x1f609].pack("U*")
12
+ WEIRD_PROJECTS = %w(NotAGoodIdeaTableViewAspect)
13
+
14
+ def self.options
15
+ Roulette.options
16
+ end
17
+
18
+ attr_reader :roulette
19
+
20
+ def initialize(argv)
21
+ @roulette = Roulette.new argv
22
+
23
+ def @roulette.last_chance=(last_chance)
24
+ @last_chance = last_chance
25
+ end
26
+
27
+ def @roulette.yesno(question, default = false)
28
+ question = "#{question} [#{'LAST CHANCE!'.red}]" if @last_chance
29
+ super question, default
30
+ end
31
+
32
+ super
33
+ end
34
+
35
+ def tries
36
+ 3
37
+ end
38
+
39
+ def run
40
+ roulette.update_if_necessary!
41
+
42
+ UI.puts "Greetings, Roulettathon attendee!"
43
+ UI.puts
44
+ UI.puts "You have #{(tries.to_s + ' chances').green.underline} of finding you a project today."
45
+ UI.puts "If you reject your first #{tries - 1} chances you have to go with the last one,"
46
+ UI.puts "even if it's a #{WEIRD_PROJECTS.sample.magenta}. You've been warned! #{WINK}"
47
+ UI.puts
48
+
49
+ catch :done do
50
+ (tries - 1).downto(0).each do |remaining|
51
+ if remaining >= 1
52
+ roulette.last_chance = (remaining == 1)
53
+ roulette.next_round do |success, configuration|
54
+ if success or remaining.zero?
55
+ configuration.create
56
+ throw :done
57
+ end
58
+ end
59
+ else
60
+ configuration = roulette.next_configuration
61
+ roulette.announce configuration
62
+ configuration.create
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
@@ -7,21 +7,23 @@ module Pod
7
7
  self.description = <<-DESC
8
8
  Creates a new iOS project with three random pods.
9
9
  DESC
10
-
10
+
11
11
  def self.options
12
12
  [[
13
13
  "--update", "Run `pod repo update` before rouletting",
14
14
  ]].concat(super)
15
15
  end
16
16
 
17
+ EMOJIS = [0x1F602, 0x1F604, 0x1F60D, 0x1F61C, 0x1F62E, 0x1F62F, 0x1F633, 0x1F640].pack("U*").chars
18
+ THINGS = [0x1f37a, 0x1f378, 0x1f377, 0x1f354, 0x1f35d, 0x1f368, 0x1f36d, 0x1f36c].pack("U*").chars
19
+
17
20
  def initialize(argv)
18
21
  @update = argv.flag?('update')
19
22
  super
20
23
  end
21
24
 
22
- def clear_prev_line(value = nil)
25
+ def clear_prev_line
23
26
  print "\r\e[A\e[K"
24
- value
25
27
  end
26
28
 
27
29
  def yesno(question, default = false)
@@ -30,11 +32,13 @@ module Pod
30
32
  answer = UI.gets.chomp
31
33
 
32
34
  if answer.empty?
33
- clear_prev_line default
35
+ clear_prev_line
36
+ default
34
37
  elsif /^y$/i =~ answer
35
- clear_prev_line true
38
+ clear_prev_line
39
+ true
36
40
  elsif /^n$/i =~ answer
37
- clear_prev_line false
41
+ false
38
42
  else
39
43
  UI.puts "Please answer with 'y' or 'n'.".red
40
44
  yesno question, default
@@ -59,27 +63,64 @@ module Pod
59
63
  end
60
64
  end
61
65
 
62
- def humanize_pod_name(name)
63
- name = name.gsub /(^|\W)(\w)/ do |match|
64
- Regexp.last_match[2].upcase
65
- end
66
- name = name.gsub /[^a-z]/i, ''
67
- name.gsub /^[A-Z]*([A-Z][^A-Z].*)$/, '\1'
66
+ def all_specs
67
+ @all_specs ||= Pod::SourcesManager.master.first.pod_sets
68
68
  end
69
69
 
70
- def tweet_text(project_name)
71
- random_emoji = [0x1F602, 0x1F604, 0x1F60D, 0x1F61C, 0x1F62E, 0x1F62F, 0x1F633, 0x1F640].pack("U*").split("").sample
72
- "#{random_emoji} got '#{project_name}' from `pod roulette` by @sirlantis and @hbehrens - fun stuff from @uikonf"
70
+ def run
71
+ update_if_necessary!
72
+
73
+ catch :done do
74
+ while true do
75
+ next_round do |success, configration|
76
+ if success
77
+ configration.create
78
+ throw :done
79
+ else
80
+ # continue forever
81
+ end
82
+ end
83
+ end
84
+ end
73
85
  end
74
86
 
75
- def pod_file_content(project_name, specs)
76
- s = "platform :ios, '7.0'\n\n"
87
+ class Configuration
88
+ attr_reader :specs
89
+
90
+ def initialize(specs)
91
+ @specs = specs
92
+ end
93
+
94
+ def name
95
+ specs.map do |spec|
96
+ self.class.humanize_pod_name spec.name
97
+ end.join ''
98
+ end
99
+
100
+ def create
101
+ UI.puts "\nPerfect, your project will use"
102
+ UI.puts (specs.map(&:name).join ", ") + "."
103
+ UI.puts "Just a few more questions before we start:\n\n"
104
+
105
+ if create_project
106
+ sleep 0.1 # make sure all output from liftoff has been flushed
107
+ UI.puts "\n\n" + tweet_text(name) + "\n\n"
108
+ end
109
+ end
77
110
 
78
- specs.each do |spec|
79
- pod = Pod::Specification::Set::Presenter.new spec
80
- s += "pod '#{pod.name}', '~> #{pod.version}'\n"
111
+ def tweet_text(project_name)
112
+ random_emoji = EMOJIS.sample
113
+ "#{random_emoji} got '#{name}' from `pod roulette` by @sirlantis and @hbehrens - fun stuff from @uikonf"
81
114
  end
82
- s+= <<END
115
+
116
+ def pod_file_content
117
+ s = "platform :ios, '7.0'\n\n"
118
+
119
+ specs.each do |spec|
120
+ pod = Pod::Specification::Set::Presenter.new spec
121
+ s += "pod '#{pod.name}', '~> #{pod.version}'\n"
122
+ end
123
+ s+= <<END
83
124
 
84
125
  target :unit_tests, :exclusive => true do
85
126
  link_with 'UnitTests'
@@ -90,71 +131,80 @@ target :unit_tests, :exclusive => true do
90
131
  end
91
132
 
92
133
  END
93
- end
94
-
95
- def create_liftoff_templates(project_name, specs)
96
- path = '.liftoff/templates'
97
- FileUtils.mkdir_p path
98
- File.open(path+'/Podfile', 'w') do |f|
99
- f.puts pod_file_content(project_name, specs)
100
134
  end
101
- end
102
135
 
103
- def create_project(project_name, specs)
104
- create_liftoff_templates project_name, specs
105
- system "liftoff", "-n", project_name, '--cocoapods', '--strict-prompts', out: $stdout, in: $stdin
106
- end
136
+ def create_liftoff_templates
137
+ # should we use Dir.home?
138
+ path = File.join '.liftoff', 'templates'
139
+ FileUtils.mkdir_p path
107
140
 
108
- def run
109
- update_if_necessary!
141
+ File.open(File.join(path, 'Podfile'), 'w') do |f|
142
+ f.puts pod_file_content
143
+ end
144
+ end
110
145
 
111
- @all_specs = Pod::SourcesManager.all_sets
146
+ def create_project
147
+ create_liftoff_templates
148
+ system "liftoff", "-n", name, '--cocoapods', '--strict-prompts', out: $stdout, in: $stdin
149
+ end
112
150
 
113
- catch :done do
114
- while true do
115
- next_round
151
+ def self.humanize_pod_name(name)
152
+ name = name.gsub /(^|\W)(\w)/ do |match|
153
+ Regexp.last_match[2].upcase
116
154
  end
155
+ name = name.gsub /[^a-z]/i, ''
156
+ name.gsub /^[A-Z]*([A-Z][^A-Z].*)$/, '\1'
117
157
  end
118
158
  end
119
159
 
120
- def next_round
121
-
122
- picked_specs = []
123
- # yes, this looks ugly but filtering all_specs before takes 10s on a MBP 2011
124
- while picked_specs.length < 3
125
- picked_spec = @all_specs.sample
126
- unless picked_specs.include? picked_spec
127
- if picked_spec.specification.available_platforms.map(&:name).include?(:ios)
128
- picked_specs << picked_spec
160
+ def random_specs
161
+ [].tap do |picked_specs|
162
+ # yes, this looks ugly but filtering all_specs before takes 10s on a MBP 2011
163
+ while picked_specs.length < 3
164
+ picked_spec = all_specs.sample
165
+ unless picked_specs.include? picked_spec
166
+ if picked_spec.specification.available_platforms.map(&:name).include?(:ios)
167
+ picked_specs << picked_spec
168
+ end
129
169
  end
130
170
  end
131
171
  end
172
+ end
173
+
174
+ def next_configuration
175
+ Configuration.new random_specs
176
+ end
132
177
 
133
- project_name = picked_specs.map do |random_spec|
134
- humanize_pod_name random_spec.name
135
- end.join ''
178
+ def announce(configration)
179
+ UI.puts "\n\n"
136
180
 
137
- UI.puts "\n" + project_name.green
181
+ 20.times do |n|
182
+ clear_prev_line
183
+ line = (0..(configration.name.size/2)).map { THINGS.sample }
184
+ UI.puts line.join(" ")
185
+ sleep 0.02
186
+ end
138
187
 
139
- if yesno "Are you happy with that project?"
140
- UI.puts "\nPerfect, your project will use"
141
- UI.puts (picked_specs.map(&:name).join ", ") + "."
142
- UI.puts "Just a few more questions before we start:\n\n"
188
+ clear_prev_line
189
+ UI.puts configration.name.green
190
+ end
143
191
 
144
- if create_project project_name, picked_specs
145
- sleep 0.1 # make sure all output from liftoff has been flushed
146
- UI.puts "\n\n" + tweet_text(project_name) + "\n\n"
147
- end
192
+ def next_round
193
+ raise "requires block" unless block_given?
194
+
195
+ configration = next_configuration
196
+ announce configration
148
197
 
149
- throw :done
198
+ if yesno "Are you happy with that project?"
199
+ yield true, configration
150
200
  else
151
201
  clear_prev_line
152
202
  clear_prev_line
153
- UI.puts project_name.cyan
203
+ UI.puts configration.name.cyan
204
+ yield false, configration
154
205
  end
155
-
156
206
  end
157
-
207
+
158
208
  def update_if_necessary!
159
209
  Repo.new(ARGV.new(["update"])).run if @update
160
210
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cocoapods-roulette
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Heiko Behrens
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-05-17 00:00:00.000000000 Z
12
+ date: 2014-10-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -50,6 +50,7 @@ extra_rdoc_files: []
50
50
  files:
51
51
  - lib/cocoapods_plugin.rb
52
52
  - lib/cocoapods_roulette.rb
53
+ - lib/pod/command/roulettathon.rb
53
54
  - lib/pod/command/roulette.rb
54
55
  - LICENSE
55
56
  homepage: http://sirlantis.github.io/cocoapods-roulette/