xcmv 0.1.4 → 1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: 2ec7f0a82d4f04cfe7fa5139d44b6a76956bf33a5c1f956dbe57a56e4d63d1b7
4
- data.tar.gz: 4c3daaf0db05a66544caf04edb17b812e668c93ece61783c24f485316e46154b
2
+ SHA1:
3
+ metadata.gz: 456870dbe3e27ce5b5a643e968015b80d9e4db00
4
+ data.tar.gz: 3afa9566039e0b74f5bf2781540e6012aedd8963
5
5
  SHA512:
6
- metadata.gz: 4a60864ae7c5a0e86b707a1227818e83f8e899340839dca9a7014424d57583920b0aa07d441e2eca6fa73c6b3a6969d72b663cc643360a93131560d57f3fd509
7
- data.tar.gz: 413984587827cedc8350cd9179fdd3a23392a162896ba44ec624d9fe64fc577421a13d452fa81b7fbf1b63acba1319c942203f7af4911378ecafe036c7fd35f8
6
+ metadata.gz: 29d8ca18f07edebe74a993404eb291c07cfd0c34d56290f0f0a4b153f11d748fcb072be3a84f3687b235de352d8e6b05d614dc47513f2042d88d8868130178d6
7
+ data.tar.gz: 7725808f9f589869d8d262db3d7ec6d17e843a7a98f3819932e71448ba9c1322b7fa1c1d41f2fae1e9c26d773872984222950c2136ca090b9c89867b5b9088bb
data/bin/xcmv CHANGED
@@ -50,14 +50,12 @@ ARGV.map!{ |a| Pathname.new(a) }
50
50
  dst = ARGV.pop
51
51
  if dst.directory?
52
52
  ARGV.each do |src|
53
- dst_file = dst + src.basename
54
- XcodeMove.mv(XcodeMove::File.new(src), XcodeMove::File.new(dst_file), options)
53
+ XcodeMove.mv(src, dst, options)
55
54
  end
56
55
  else
57
- if ARGV.count > 2
56
+ if ARGV.count > 2 || ARGV[0].directory?
58
57
  abort "Error: moving more than one file to #{dst}\n" + parser.help
59
58
  end
60
59
  src = ARGV[0]
61
- XcodeMove.mv(XcodeMove::File.new(src), XcodeMove::File.new(dst), options)
62
- end
63
-
60
+ XcodeMove.mv(src, dst, options)
61
+ end
data/lib/xcmv/file.rb CHANGED
@@ -5,7 +5,7 @@ module XcodeMove
5
5
 
6
6
  def initialize(path)
7
7
  path = Pathname.new path
8
- @path = path.realdirpath
8
+ @path = path.expand_path
9
9
  end
10
10
 
11
11
  def project
@@ -19,11 +19,15 @@ module XcodeMove
19
19
  def header?
20
20
  path.extname == '.h'
21
21
  end
22
-
22
+
23
+ def with_dirname(root_path)
24
+ new_path = root_path + path.basename
25
+ self.class.new(new_path) # want to return the same kind of object
26
+ end
23
27
 
24
28
  # Traverses up from the `path` to enumerate over xcodeproj directories
25
29
  def reachable_projects
26
- path.ascend.find_all{ |p| p.directory? }.flat_map do |dir|
30
+ path.ascend.find_all{ |p| p.exist? and p.directory? }.flat_map do |dir|
27
31
  dir.children.select{ |p| p.extname == '.xcodeproj' }
28
32
  end
29
33
  end
@@ -95,4 +99,27 @@ module XcodeMove
95
99
  @pbx_file = project.files.find{ |f| f.real_path == path }
96
100
  end
97
101
  end
102
+
103
+ class Group < File
104
+ def initialize(path)
105
+ path = Pathname.new path
106
+ @path = path.expand_path
107
+ end
108
+
109
+ def remove_from_project
110
+ if not pbx_file.nil?
111
+ pbx_file.children.each do | c |
112
+ c.remove_from_project
113
+ end
114
+ pbx_file.remove_from_project
115
+ @pbx_file = nil
116
+ end
117
+ end
118
+
119
+ private
120
+
121
+ def pbx_load
122
+ @pbx_file = project.main_group.recursive_children.find { |g| g.respond_to?(:real_path) and g.real_path == path }
123
+ end
124
+ end
98
125
  end
data/lib/xcmv/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
 
2
2
  module XcodeMove
3
- VERSION = '0.1.4'
3
+ VERSION = '1.2.0'
4
4
  end
data/lib/xcmv.rb CHANGED
@@ -7,35 +7,58 @@ require_relative 'xcmv/version'
7
7
 
8
8
  module XcodeMove
9
9
 
10
- # Moves from one `XcodeMove::File` to another
10
+ # Moves from one `Pathname` to another
11
11
  def self.mv(src, dst, options)
12
- puts("#{src.path} => #{dst.path}")
12
+ src_file = src.directory? ? Group.new(src) : File.new(src)
13
+ dst_file = src_file.with_dirname(dst)
13
14
 
14
- # Remove files from xcodeproj (including dst if the file is being overwritten)
15
- if src.pbx_file
16
- src.remove_from_project
15
+ puts("#{src_file.path} => #{dst_file.path}")
16
+
17
+ project_mv(src_file, dst_file, options)
18
+ disk_mv(src_file, dst_file, options)
19
+ save(src_file, dst_file)
20
+ end
21
+
22
+ private
23
+
24
+ # Prepare the project file(s) for the move
25
+ def self.project_mv(src_file, dst_file, options)
26
+ if src_file.path.directory?
27
+ # Process all children first
28
+ children = src_file.path.children.map { |c| c.directory? ? Group.new(c) : File.new(c) }
29
+ children.each do | src_child |
30
+ dst_child = src_child.with_dirname(dst_file.path)
31
+ project_mv(src_child, dst_child, options)
32
+ end
17
33
  else
18
- warn("warning: #{src.path.basename} not found in #{src.project.path.basename}. moving anyway...")
19
- end
20
- if dst.pbx_file
21
- dst.remove_from_project
22
- end
34
+ # Remove old destination file reference if it exists
35
+ if dst_file.pbx_file
36
+ dst_file.remove_from_project
37
+ end
23
38
 
24
- # Add to the new xcodeproj
25
- dst.create_file_reference
26
- dst.add_to_targets(options[:targets], options[:headers])
39
+ # Add new destination file reference to the new xcodeproj
40
+ dst_file.create_file_reference
41
+ dst_file.add_to_targets(options[:targets], options[:headers])
42
+ end
27
43
 
28
- # Move the actual file
29
- if options[:git]
30
- mover = "git mv"
31
- else
32
- mover = "mv"
44
+ # Remove original directory/file from xcodeproj
45
+ if src_file.pbx_file
46
+ src_file.remove_from_project
47
+ else
48
+ warn("warning: #{src_file.path.realdirpath} not found in #{src_file.project.path.basename}. moving anyway...")
33
49
  end
34
- command = "#{mover} '#{src.path}' '#{dst.path}'"
50
+ end
51
+
52
+ # Move the src_file to the dst_file on disk
53
+ def self.disk_mv(src_file, dst_file, options)
54
+ mover = options[:git] ? "git mv" : "mv"
55
+ command = "#{mover} '#{src_file.path}' '#{dst_file.path}'"
35
56
  system(command) || abort
57
+ end
36
58
 
37
- # Save
38
- src.save_and_close
39
- dst.save_and_close
59
+ # Save the src_file and dst_file project files to disk
60
+ def self.save(src_file, dst_file)
61
+ src_file.save_and_close
62
+ dst_file.save_and_close
40
63
  end
41
64
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xcmv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elliott Williams
@@ -58,7 +58,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
58
58
  version: '0'
59
59
  requirements: []
60
60
  rubyforge_project:
61
- rubygems_version: 2.7.6
61
+ rubygems_version: 2.5.2.3
62
62
  signing_key:
63
63
  specification_version: 4
64
64
  summary: Xcode Move