cocoapods-try 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 59846a9b4b264d248b3179fbd131845ad5e8c105
4
+ data.tar.gz: fd0b200c55f3009cb0f4bd9d06d29122d0e8decb
5
+ SHA512:
6
+ metadata.gz: c453c8f582e5680eadb629a994fae354718f7ecffa39ca9054a9f6aa30aa2ad690ffceb2af0bd6c4b466bea5e2ef61312f5d73b7eec6136cd7d0d9896f970ef9
7
+ data.tar.gz: 4aeb31d49f8005375f06b8826e0641ce94169e401bd33a8f9656a6f0dadfd832ba3cd10aba095c3b44364f325b4f55674278da1922d7df82ff0b4b2a633a2c65
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.travis.yml ADDED
@@ -0,0 +1,11 @@
1
+ language: objective-c
2
+ env:
3
+ # This is what 10.8.x comes with and we want to support that.
4
+ - RVM_RUBY_VERSION=system NOEXEC_DISABLE=1 RUBY_VERSION_SPECIFIC='sudo gem install bundler --no-ri --no-rdoc' GIT_AUTHOR_NAME=CocoaPods GIT_AUTHOR_EMAIL=cocoapods@example.com PYTHONPATH=/usr/local/lib/python2.7/site-packages
5
+ - RVM_RUBY_VERSION=1.8.7-p358 NOEXEC_DISABLE=1 RUBY_VERSION_SPECIFIC='sudo ln -s /usr/bin/llvm-gcc-4.2 /usr/bin/gcc-4.2' SSL_CERT_FILE=/usr/local/share/cacert.pem GIT_AUTHOR_NAME=CocoaPods GIT_AUTHOR_EMAIL=cocoapods@example.com PYTHONPATH=/usr/local/lib/python2.7/site-packages
6
+ before_install:
7
+ - curl http://curl.haxx.se/ca/cacert.pem -o /usr/local/share/cacert.pem
8
+ - sh -c 'if [ "$RVM_RUBY_VERSION" != "system" ]; then rvm install $RVM_RUBY_VERSION --without-tcl --without-tk; fi'
9
+ - source ~/.rvm/scripts/rvm && rvm use $RVM_RUBY_VERSION
10
+ install: eval $RUBY_VERSION_SPECIFIC && bundle install --path ./travis_bundle_dir
11
+ script: bundle exec rake specs
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ # Cocoapods::Try Changelog
2
+
3
+ ## Master
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ group :development do
6
+ gem 'cocoapods'
7
+ gem 'bacon'
8
+ gem 'mocha-on-bacon'
9
+ gem 'mocha', '~> 0.11.4'
10
+ gem 'rake'
11
+ gem 'prettybacon', :git => 'https://github.com/irrationalfab/PrettyBacon.git', :branch => 'master'
12
+ end
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 CocoaPods Dev Team
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,15 @@
1
+ # Cocoapods try
2
+
3
+ [![Build Status](https://travis-ci.org/CocoaPods/cocoapods-try.png?branch=master)](https://travis-ci.org/CocoaPods/cocoapods-try)
4
+
5
+ CocoaPods plugin which allows to quickly try the demo project of a Pod.
6
+
7
+ ## Installation
8
+
9
+ $ git clone THIS_REPO_URL
10
+ $ cd THIS_REPO
11
+ $ rake install
12
+
13
+ ## Usage
14
+
15
+ $ pod try POD_NAME
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ def specs(dir)
4
+ FileList["spec/#{dir}/*_spec.rb"].shuffle.join(' ')
5
+ end
6
+
7
+ desc "Runs all the specs"
8
+ task :specs do
9
+ sh "bundle exec bacon #{specs('**')}"
10
+ end
11
+
12
+ task :default => :specs
@@ -0,0 +1,21 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'cocoapods_try.rb'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "cocoapods-try"
8
+ spec.version = CocoapodsTry::VERSION
9
+ spec.authors = ["CocoaPods Dev Team"]
10
+ spec.summary = %q{CocoaPods plugin which allows to quickly try the demo project of a Pod.}
11
+ spec.homepage = "https://github.com/cocoapods/cocoapods-try"
12
+ spec.license = "MIT"
13
+
14
+ spec.files = `git ls-files`.split($/)
15
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
+ spec.require_paths = ["lib"]
18
+
19
+ spec.add_development_dependency "bundler", "~> 1.3"
20
+ spec.add_development_dependency "rake"
21
+ end
@@ -0,0 +1 @@
1
+ require 'pod/command/try'
@@ -0,0 +1,3 @@
1
+ module CocoapodsTry
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,218 @@
1
+ module Pod
2
+ class Command
3
+
4
+ # The pod try command.
5
+ #
6
+ class Try < Command
7
+ self.summary = "Try a Pod!"
8
+
9
+ self.description = <<-DESC
10
+ Donwloads the Pod with the given NAME and opens its project.
11
+ DESC
12
+
13
+ self.arguments = 'NAME'
14
+
15
+ def initialize(argv)
16
+ @name = argv.shift_argument
17
+ super
18
+ end
19
+
20
+ def validate!
21
+ super
22
+ help! "A Pod name is required." unless @name
23
+ end
24
+
25
+ def run
26
+ spec = spec_with_name(@name)
27
+ update_specs_repos
28
+ UI.title "Trying #{spec.name}" do
29
+ pod_dir = install_pod(spec, TRY_TMP_DIR)
30
+ proj = pick_demo_project(pod_dir)
31
+ file = install_podfile(proj)
32
+ if file
33
+ open_project(file)
34
+ else
35
+ UI.puts "Unable to locate a project for #{spec.name}"
36
+ end
37
+ end
38
+ end
39
+
40
+ public
41
+
42
+ # Helpers
43
+ #-----------------------------------------------------------------------#
44
+
45
+ # @return [Pathname]
46
+ #
47
+ TRY_TMP_DIR = Pathname.new('/tmp/CocoaPods/Try')
48
+
49
+ # Returns the specification of the last version of the Pod with the given
50
+ # name.
51
+ #
52
+ # @param [String] name
53
+ # The name of the pod.
54
+ #
55
+ # @return [Specification] The specification.
56
+ #
57
+ def spec_with_name(name)
58
+ set = SourcesManager.search(Dependency.new(name))
59
+ if set
60
+ set.specification.root
61
+ else
62
+ raise Informative, "Unable to find a specification for `#{name}`"
63
+ end
64
+ end
65
+
66
+ # Installs the specification in the given directory.
67
+ #
68
+ # @param [Specification] The specification of the Pod.
69
+ # @param [Pathname] The directory of the sandbox where to install the
70
+ # Pod.
71
+ #
72
+ # @return [Pathname] The path where the Pod was installed
73
+ #
74
+ def install_pod(spec, dir)
75
+ sandbox = Sandbox.new(dir)
76
+ specs = { :ios => spec, :osx => spec }
77
+ installer = Installer::PodSourceInstaller.new(sandbox, specs)
78
+ installer.aggressive_cache = config.aggressive_cache?
79
+ installer.install!
80
+ TRY_TMP_DIR + spec.name
81
+ end
82
+
83
+ # Picks a project suitable for the demo purposes in the given directory.
84
+ # To decide the project simple heuristics are used according to the name,
85
+ # if no project is found this method raises and `Informative` otherwise
86
+ # if more than one project is found the choice is presented to the user.
87
+ #
88
+ # @param [#to_s] dir
89
+ # The path where to look for projects.
90
+ #
91
+ # @return [String] The path of the project.
92
+ #
93
+ def pick_demo_project(dir)
94
+ glob_match = Dir.glob("#{dir}/**/*.xcodeproj")
95
+ glob_match = glob_match.reject { |p| p.include?('Pods.xcodeproj') }
96
+ if glob_match.count == 0
97
+ raise Informative, "Unable to find any project in the source files" \
98
+ "of the Pod: `#{dir}`"
99
+ elsif glob_match.count == 1
100
+ glob_match.first
101
+ elsif (selection = filter_array(glob_match, "demo")).count == 1
102
+ selection.first
103
+ elsif (selection = filter_array(glob_match, "example")).count == 1
104
+ selection.first
105
+ else
106
+ message = "Which project would you like to open"
107
+ selection_array = glob_match.map do |p|
108
+ Pathname.new(p).relative_path_from(dir).to_s
109
+ end
110
+ index = choose_from_array(selection_array, message)
111
+ glob_match[index]
112
+ end
113
+ end
114
+
115
+ # Performs a CocoaPods installation for the given project if Podfile is found.
116
+ # Shells out to avoid issues with the config of the process running the
117
+ # try command.
118
+ #
119
+ # @return [String] proj
120
+ # The path of the project.
121
+ #
122
+ # @return [String] The path of the file to open, in other words the
123
+ # workspace of the installation or the given project.
124
+ #
125
+ def install_podfile(proj)
126
+ return unless proj
127
+ dirname = Pathname.new(proj).dirname
128
+ podfile = dirname + 'Podfile'
129
+ if podfile.exist?
130
+ Dir.chdir(dirname) do
131
+ perform_cocoapods_installation
132
+ proj.chomp(File.extname(proj.to_s)) + '.xcworkspace'
133
+ end
134
+ else
135
+ proj
136
+ end
137
+ end
138
+
139
+ public
140
+
141
+ # Private Helpers
142
+ #-----------------------------------------------------------------------#
143
+
144
+ # @return [void] Updates the specs repo unless disabled by the config.
145
+ #
146
+ def update_specs_repos
147
+ unless config.skip_repo_update?
148
+ UI.section 'Updating spec repositories' do
149
+ SourcesManager.update
150
+ end
151
+ end
152
+ end
153
+
154
+ # Opens the project at the given path.
155
+ #
156
+ # @return [String] path
157
+ # The path of the project.
158
+ #
159
+ # @return [void]
160
+ #
161
+ def open_project(path)
162
+ UI.puts "Opening '#{path}'"
163
+ `open "#{path}"`
164
+ end
165
+
166
+ # Selects the entries in the given array which includes the given string
167
+ # (case insensitive check).
168
+ #
169
+ # @param [Array] array
170
+ # The array to filter.
171
+ #
172
+ # @param [String] string
173
+ # The string that should be used to filter the array.
174
+ #
175
+ # @return [Array] The selection.
176
+ #
177
+ def filter_array(array, string)
178
+ array.select { |p| p.downcase.include?(string.downcase) }
179
+ end
180
+
181
+ # Presents a choice among the elements of an array to the user.
182
+ #
183
+ # @param [Array<#to_s>] array
184
+ # The list of the elements among which the user should make his
185
+ # choice.
186
+ #
187
+ # @param [String] message
188
+ # The message to display to the user.
189
+ #
190
+ # @return [Fixnum] The index of the chosen array item.
191
+ #
192
+ # @todo This method was duplicated from the spec subcommands
193
+ #
194
+ def choose_from_array(array, message)
195
+ array.each_with_index do |item, index|
196
+ UI.puts "#{ index + 1 }: #{ item }"
197
+ end
198
+ UI.puts "#{message} [1-#{array.count}]?"
199
+ index = STDIN.gets.chomp.to_i - 1
200
+ if index < 0 || index > array.count
201
+ raise Informative, "#{ index + 1 } is invalid [1-#{array.count}]"
202
+ else
203
+ index
204
+ end
205
+ end
206
+
207
+ # @return [void] Performs a CocoaPods installation in the working
208
+ # directory.
209
+ #
210
+ def perform_cocoapods_installation
211
+ UI.puts `pod install`
212
+ end
213
+
214
+ #-------------------------------------------------------------------#
215
+
216
+ end
217
+ end
218
+ end
@@ -0,0 +1,118 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+
3
+ module Pod
4
+ describe Command::Try do
5
+
6
+ #-------------------------------------------------------------------------#
7
+
8
+ describe "CLAide" do
9
+ it "registers it self" do
10
+ Command.parse(%w{ try }).should.be.instance_of Command::Try
11
+ end
12
+
13
+ it "presents the help if no name is provided" do
14
+ command = Pod::Command.parse(['try'])
15
+ should.raise CLAide::Help do
16
+ command.validate!
17
+ end.message.should.match /A Pod name is required/
18
+ end
19
+
20
+ it "runs" do
21
+ Config.instance.skip_repo_update = false
22
+ command = Pod::Command.parse(['try', 'ARAnalytics'])
23
+ Installer::PodSourceInstaller.any_instance.expects(:install!)
24
+ command.expects(:update_specs_repos)
25
+ command.expects(:pick_demo_project).returns("/tmp/Proj.xcodeproj")
26
+ command.expects(:open_project).with('/tmp/Proj.xcodeproj')
27
+ command.run
28
+ end
29
+ end
30
+
31
+ #-------------------------------------------------------------------------#
32
+
33
+ describe "Helpers" do
34
+
35
+ before do
36
+ @sut = Pod::Command.parse(['try'])
37
+ end
38
+
39
+ it "returns the spec with the given name" do
40
+ spec = @sut.spec_with_name('ARAnalytics')
41
+ spec.name.should == "ARAnalytics"
42
+ end
43
+
44
+ it "installs the pod" do
45
+ Installer::PodSourceInstaller.any_instance.expects(:install!)
46
+ spec = stub(:name => 'ARAnalytics')
47
+ path = @sut.install_pod(spec, '/tmp/CocoaPods/Try')
48
+ path.should == Pathname.new("/tmp/CocoaPods/Try/ARAnalytics")
49
+ end
50
+
51
+ describe "#pick_demo_project" do
52
+ it "raises if no demo project could be found" do
53
+ projects = []
54
+ Dir.stubs(:glob).returns(projects)
55
+ should.raise Informative do
56
+ @sut.pick_demo_project(stub())
57
+ end.message.should.match /Unable to find any project/
58
+ end
59
+
60
+ it "picks a demo project" do
61
+ projects = ['Demo.xcodeproj']
62
+ Dir.stubs(:glob).returns(projects)
63
+ path = @sut.pick_demo_project(stub())
64
+ path.should == "Demo.xcodeproj"
65
+ end
66
+
67
+ it "is not case sensitive" do
68
+ projects = ['demo.xcodeproj']
69
+ Dir.stubs(:glob).returns(projects)
70
+ path = @sut.pick_demo_project(stub())
71
+ path.should == "demo.xcodeproj"
72
+ end
73
+
74
+ it "considers also projects named example" do
75
+ projects = ['Example.xcodeproj']
76
+ Dir.stubs(:glob).returns(projects)
77
+ path = @sut.pick_demo_project(stub())
78
+ path.should == "Example.xcodeproj"
79
+ end
80
+
81
+ it "returns the project if only one is found" do
82
+ projects = ['Lib.xcodeproj']
83
+ Dir.stubs(:glob).returns(projects)
84
+ path = @sut.pick_demo_project(stub())
85
+ path.should == "Lib.xcodeproj"
86
+ end
87
+
88
+ it "asks the user which project would like to open if not a single suitable one is found" do
89
+ projects = ['Lib_1.xcodeproj', 'Lib_2.xcodeproj']
90
+ Dir.stubs(:glob).returns(projects)
91
+ @sut.stubs(:choose_from_array).returns(0)
92
+ path = @sut.pick_demo_project(stub(:cleanpath=>''))
93
+ path.should == "Lib_1.xcodeproj"
94
+ end
95
+ end
96
+
97
+ describe "#install_podfile" do
98
+ it "returns the original project if no Podfile could be found" do
99
+ Pathname.any_instance.stubs(:exist?).returns(false)
100
+ proj = "/tmp/Project.xcodeproj"
101
+ path = @sut.install_podfile(proj)
102
+ path.should == proj
103
+ end
104
+
105
+ it "performs an installation and returns the path of the Podfile" do
106
+ Pathname.any_instance.stubs(:exist?).returns(true)
107
+ proj = "/tmp/Project.xcodeproj"
108
+ @sut.expects(:perform_cocoapods_installation)
109
+ path = @sut.install_podfile(proj)
110
+ path.should == "/tmp/Project.xcworkspace"
111
+ end
112
+ end
113
+ end
114
+
115
+ #-------------------------------------------------------------------------#
116
+
117
+ end
118
+ end
@@ -0,0 +1,47 @@
1
+ require 'pathname'
2
+ ROOT = Pathname.new(File.expand_path('../../', __FILE__))
3
+ $:.unshift((ROOT + 'lib').to_s)
4
+ $:.unshift((ROOT + 'spec').to_s)
5
+
6
+ require 'bundler/setup'
7
+ require 'bacon'
8
+ require 'mocha-on-bacon'
9
+ require 'pretty_bacon'
10
+ require 'cocoapods'
11
+
12
+ require 'cocoapods_plugin'
13
+
14
+ #-----------------------------------------------------------------------------#
15
+
16
+ module Pod
17
+
18
+ # Disable the wrapping so the output is deterministic in the tests.
19
+ #
20
+ UI.disable_wrap = true
21
+
22
+ # Redirects the messages to an internal store.
23
+ #
24
+ module UI
25
+ @output = ''
26
+ @warnings = ''
27
+
28
+ class << self
29
+ attr_accessor :output
30
+ attr_accessor :warnings
31
+
32
+ def puts(message = '')
33
+ @output << "#{message}\n"
34
+ end
35
+
36
+ def warn(message = '', actions = [])
37
+ @warnings << "#{message}\n"
38
+ end
39
+
40
+ def print(message)
41
+ @output << message
42
+ end
43
+ end
44
+ end
45
+ end
46
+
47
+ #-----------------------------------------------------------------------------#
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cocoapods-try
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - CocoaPods Dev Team
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-02 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.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description:
42
+ email:
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - .gitignore
48
+ - .travis.yml
49
+ - CHANGELOG.md
50
+ - Gemfile
51
+ - LICENSE
52
+ - README.md
53
+ - Rakefile
54
+ - cocoapods-docs.gemspec
55
+ - lib/cocoapods_plugin.rb
56
+ - lib/cocoapods_try.rb
57
+ - lib/pod/command/try.rb
58
+ - spec/command/try_spec.rb
59
+ - spec/spec_helper.rb
60
+ homepage: https://github.com/cocoapods/cocoapods-try
61
+ licenses:
62
+ - MIT
63
+ metadata: {}
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - '>='
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ requirements: []
79
+ rubyforge_project:
80
+ rubygems_version: 2.0.3
81
+ signing_key:
82
+ specification_version: 4
83
+ summary: CocoaPods plugin which allows to quickly try the demo project of a Pod.
84
+ test_files:
85
+ - spec/command/try_spec.rb
86
+ - spec/spec_helper.rb