Module: Dapp::CoreExt::Pathname

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

Instance Method Summary collapse

Instance Method Details

#subpath_of(another_path) ⇒ Object



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

def subpath_of(another_path)
  another_cleanpath = ::Pathname.new(another_path).cleanpath

  return     unless subpath_of? another_path
  return '.' if cleanpath.to_s == another_cleanpath.to_s
  cleanpath.to_s.partition(another_cleanpath.to_s + '/').last
end

#subpath_of?(another_path) ⇒ Boolean

Returns:

  • (Boolean)


4
5
6
7
8
9
10
11
12
# 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
end