lib/git_compound/component/destination.rb in git_compound-0.0.9 vs lib/git_compound/component/destination.rb in git_compound-0.0.10

- old
+ new

@@ -5,41 +5,43 @@ # Component destination # class Destination attr_reader :path - def initialize(path, component) + def initialize(component_path, component) raise CompoundSyntaxError, 'Destination cannot be empty' if - path.nil? || path.empty? + component_path.nil? || component_path.empty? raise CompoundSyntaxError, 'Destination should contain at least one directory' unless - Pathname.new(path).each_filename.count > 0 + Pathname.new(component_path).each_filename.count > 0 - @path = path @component = component + @path = expand_path(component_path) end - def expanded_path - pathname = Pathname.new(@path) - - unless pathname.absolute? - ancestor_paths = @component.ancestors.map(&:destination_path) - pathname = Pathname.new('.').join(*ancestor_paths) + pathname - end - - Pathname.new("./#{pathname}").cleanpath.to_s + '/' - end - def exists? - FileTest.exist?(expanded_path) + FileTest.exist?(@path) end def repository destination_repository = - Repository::RepositoryLocal.new(expanded_path) + Repository::RepositoryLocal.new(@path) yield destination_repository if block_given? destination_repository + end + + private + + def expand_path(component_path) + pathname = Pathname.new(component_path) + + unless pathname.absolute? + ancestor_paths = @component.ancestors.map(&:path) + pathname = Pathname.new('.').join(*ancestor_paths) + pathname + end + + Pathname.new("./#{pathname}").cleanpath.to_s + '/' end end end end