Class: ProjectGen::PodDirCopyCleaner
- Inherits:
-
Object
- Object
- ProjectGen::PodDirCopyCleaner
- Defined in:
- lib/cocoapods-project-gen/gen/pod/pod_copy_cleaner.rb
Instance Method Summary collapse
- #copy(source, destination, specs_by_platform) ⇒ Object
-
#copy_and_clean(root, sandbox) ⇒ Void
Copies the ‘source` directory to `destination`, cleaning the directory of any files unused by `spec`.
- #group_subspecs_by_platform(spec) ⇒ Object
-
#initialize(podspecs) ⇒ PodDirCopyCleaner
constructor
A new instance of PodDirCopyCleaner.
Constructor Details
#initialize(podspecs) ⇒ PodDirCopyCleaner
Returns a new instance of PodDirCopyCleaner.
3 4 5 |
# File 'lib/cocoapods-project-gen/gen/pod/pod_copy_cleaner.rb', line 3 def initialize(podspecs) @podspecs = podspecs end |
Instance Method Details
#copy(source, destination, specs_by_platform) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/cocoapods-project-gen/gen/pod/pod_copy_cleaner.rb', line 34 def copy(source, destination, specs_by_platform) path_list = Pod::Sandbox::PathList.new(source) file_accessors = specs_by_platform.flat_map do |platform, specs| specs.flat_map do |spec| Pod::Sandbox::FileAccessor.new(path_list, spec.consumer(platform)) end end used_files = Pod::Sandbox::FileAccessor.all_files(file_accessors) used_files.each do |path| path = Pathname(path) n_path = destination.join(path.relative_path_from(source)) n_path.dirname.mkpath FileUtils.cp_r(path, n_path.dirname) end end |
#copy_and_clean(root, sandbox) ⇒ Void
Copies the ‘source` directory to `destination`, cleaning the directory of any files unused by `spec`.
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/cocoapods-project-gen/gen/pod/pod_copy_cleaner.rb', line 12 def copy_and_clean(root, sandbox) @podspecs.each do |spec| destination = root + spec.name source = sandbox.pod_dir(spec.name) specs_by_platform = group_subspecs_by_platform(spec) destination.parent.mkpath FileUtils.rm_rf(destination) copy(source, destination, specs_by_platform) end end |
#group_subspecs_by_platform(spec) ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/cocoapods-project-gen/gen/pod/pod_copy_cleaner.rb', line 23 def group_subspecs_by_platform(spec) specs_by_platform = {} [spec, *spec.recursive_subspecs].each do |ss| ss.available_platforms.each do |platform| specs_by_platform[platform] ||= [] specs_by_platform[platform] << ss end end specs_by_platform end |