Module: Dapp::CoreExt::Pathname

Defined in:
lib/dapp/core_ext/pathname.rb

Instance Method Summary collapse

Instance Method Details

#subpath_of(another_path) ⇒ Object



15
16
17
18
# File 'lib/dapp/core_ext/pathname.rb', line 15

def subpath_of(another_path)
  return unless subpath_of? another_path
  cleanpath.to_s.partition(::Pathname.new(another_path).cleanpath.to_s + '/').last
end

#subpath_of?(another_path) ⇒ Boolean

Returns:

  • (Boolean)


4
5
6
7
8
9
10
11
12
13
# File 'lib/dapp/core_ext/pathname.rb', line 4

def subpath_of?(another_path)
  another_path_descends = []
  ::Pathname.new(another_path).cleanpath.descend {|d| another_path_descends << d}

  path_descends = []
  cleanpath.descend {|d| path_descends << d}

  (path_descends & another_path_descends) == another_path_descends &&
    (path_descends - another_path_descends).any?
end