Skip to content

Commit 93633c4

Browse files
authored
Merge pull request #5 from X140Yu/cocoapods-plugin
Closes #2
2 parents d1ae203 + 42e5cdb commit 93633c4

File tree

10 files changed

+59
-24
lines changed

10 files changed

+59
-24
lines changed

cocoapods-dependency.gemspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
lib = File.expand_path('lib', __dir__)
22
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3-
require 'cocoapods/dependency/version'
3+
require 'cocoapods-dependency/version'
44

55
Gem::Specification.new do |spec|
66
spec.name = 'cocoapods-dependency'
7-
spec.version = Cocoapods::Dependency::VERSION
7+
spec.version = CocoapodsDependency::VERSION
88
spec.authors = ['Xinyu Zhao']
99
spec.email = ['[email protected]']
1010

lib/cocoapods-dependency.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
require 'cocoapods-dependency/version'

lib/cocoapods/analyze.rb renamed to lib/cocoapods-dependency/analyze.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
require 'cocoapods'
22
require 'pathname'
33

4-
module Cocoapods
4+
module CocoapodsDependency
55
#
66
# Analyze the project using cocoapods
77
#
8-
class DependencyAnalyzer
8+
class Analyzer
99
def self.analyze(podfile_dir_path)
1010
path = Pathname.new(podfile_dir_path)
1111
raise 'absolute path is needed' unless path.absolute?
12+
1213
Dir.chdir(podfile_dir_path) do
1314
analyze_with_podfile(
1415
path,
@@ -24,9 +25,11 @@ def self.podfile_dependencies(podfile)
2425
children_definitions = td.recursive_children
2526
children_definitions.each do |cd|
2627
dependencies_hash_array = cd.send(:get_hash_value, 'dependencies')
27-
next if dependencies_hash_array.count == 0
28+
next if dependencies_hash_array.count.zero?
29+
2830
dependencies_hash_array.each do |item|
2931
next if item.class.name != 'Hash'
32+
3033
item.each do |name, _|
3134
res.push name
3235
end
@@ -78,6 +81,7 @@ def self.analyze_with_podfile(_podfile_dir_path, podfile, lockfile = nil)
7881

7982
def self.find_dependencies(name, map, res, dependencies_map, root_name)
8083
return unless map[name]
84+
8185
map[name].each do |k|
8286
find_dependencies(k.name, map, res, dependencies_map, root_name)
8387
dependency = dependencies_map[k.name.split('/')[0]]

lib/cocoapods-dependency/command.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
require 'cocoapods-dependency/command/dependency'
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
require 'cocoapods-dependency/analyze'
2+
require 'pp'
3+
module Pod
4+
class Command
5+
6+
class Dependency < Command
7+
self.summary = 'Analyzes the dependencies of any cocoapods projects.'
8+
9+
self.description = <<-DESC
10+
Analyzes the dependencies of any cocoapods projects. Subspecs are properly handled.
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+
verify_podfile_exists!
23+
end
24+
25+
def run
26+
pp CocoapodsDependency::Analyzer.analyze_with_podfile(nil, config.podfile)
27+
end
28+
end
29+
end
30+
end

lib/cocoapods-dependency/version.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# :nocov:
2+
module CocoapodsDependency
3+
VERSION = "0.1.0"
4+
end

lib/cocoapods/dependency/version.rb

Lines changed: 0 additions & 6 deletions
This file was deleted.

lib/cocoapods_plugin.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
require 'cocoapods-dependency/command'

spec/cocoapods/dependency_spec.rb

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
RSpec.describe Cocoapods::Dependency do
1+
RSpec.describe 'CocoapodsDependency' do
22
it 'has a version number' do
3-
expect(Cocoapods::Dependency::VERSION).not_to be nil
3+
expect(CocoapodsDependency::VERSION).not_to be nil
44
end
55

66
it 'no podfile exists in path will raise error' do
7-
expect { Cocoapods::DependencyAnalyzer.analyze(Pathname.new('/')) }.to raise_error(/No Podfile exists/)
7+
expect { CocoapodsDependency::Analyzer.analyze(Pathname.new('/')) }.to raise_error(/No Podfile exists/)
88
end
99

1010
it 'generate custom podfile' do
@@ -27,7 +27,7 @@
2727
end
2828

2929
expect(
30-
Cocoapods::DependencyAnalyzer.analyze_with_podfile(Pathname.new('/'), podfile)
30+
CocoapodsDependency::Analyzer.analyze_with_podfile(Pathname.new('/'), podfile)
3131
).to eq('Masonry' => [])
3232
end
3333

@@ -46,7 +46,7 @@
4646
}
4747

4848
expect(
49-
Cocoapods::DependencyAnalyzer.analyze_with_podfile(Pathname.new('/'), podfile)
49+
CocoapodsDependency::Analyzer.analyze_with_podfile(Pathname.new('/'), podfile)
5050
).to eq(res_map)
5151
end
5252

@@ -64,7 +64,7 @@
6464
}
6565

6666
expect(
67-
Cocoapods::DependencyAnalyzer.analyze_with_podfile(Pathname.new('/'), podfile)
67+
CocoapodsDependency::Analyzer.analyze_with_podfile(Pathname.new('/'), podfile)
6868
).to eq(res_map)
6969
end
7070

@@ -82,7 +82,7 @@
8282
}
8383

8484
expect(
85-
Cocoapods::DependencyAnalyzer.analyze_with_podfile(Pathname.new('/'), podfile)
85+
CocoapodsDependency::Analyzer.analyze_with_podfile(Pathname.new('/'), podfile)
8686
).to eq(res_map)
8787
end
8888

@@ -101,7 +101,7 @@
101101
}
102102

103103
expect(
104-
Cocoapods::DependencyAnalyzer.analyze_with_podfile(Pathname.new('/'), podfile)
104+
CocoapodsDependency::Analyzer.analyze_with_podfile(Pathname.new('/'), podfile)
105105
).to eq(res_map)
106106
end
107107

@@ -122,7 +122,7 @@
122122
}
123123

124124
expect(
125-
Cocoapods::DependencyAnalyzer.analyze_with_podfile(Pathname.new('/'), podfile)
125+
CocoapodsDependency::Analyzer.analyze_with_podfile(Pathname.new('/'), podfile)
126126
).to eq(res_map)
127127
end
128128

@@ -146,7 +146,7 @@
146146
}
147147

148148
expect(
149-
Cocoapods::DependencyAnalyzer.analyze_with_podfile(Pathname.new('/'), podfile)
149+
CocoapodsDependency::Analyzer.analyze_with_podfile(Pathname.new('/'), podfile)
150150
).to eq(res_map)
151151
end
152152

@@ -167,7 +167,7 @@
167167
}
168168

169169
expect(
170-
Cocoapods::DependencyAnalyzer.analyze_with_podfile(Pathname.new('/'), podfile)
170+
CocoapodsDependency::Analyzer.analyze_with_podfile(Pathname.new('/'), podfile)
171171
).to eq(res_map)
172172
end
173173

@@ -190,7 +190,7 @@
190190
}
191191

192192
expect(
193-
Cocoapods::DependencyAnalyzer.analyze_with_podfile(Pathname.new('/'), podfile)
193+
CocoapodsDependency::Analyzer.analyze_with_podfile(Pathname.new('/'), podfile)
194194
).to eq(res_map)
195195
end
196196
end

spec/spec_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Coveralls.wear!
33

44
require 'bundler/setup'
5-
require 'cocoapods/analyze'
5+
require 'cocoapods-dependency/analyze'
66

77
RSpec.configure do |config|
88
# Enable flags like --only-failures and --next-failure

0 commit comments

Comments
 (0)