fakefs 1.3.2 → 1.4.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
2
  SHA256:
3
- metadata.gz: 05aa1f68c0f9298802a4171ba6b109e53cb2e020b9b6f2973872ce4cc4de6ce1
4
- data.tar.gz: 566bdaeab08f35a081857a4a76170c6b94f29bf928735f81470a19e4280297e4
3
+ metadata.gz: e62fc76c0ca1c48b09e7b4051d5888a3f361b7f6e72434275bf3820d972c05d0
4
+ data.tar.gz: fc2e3377b5948b04302f06893fd4b961311699c597dfe431a9ab04046b488d67
5
5
  SHA512:
6
- metadata.gz: 25dd82ac5d99560aee6642ee5faea80ee35cf0b70610d6b1f7b3e4cd7369c78f9acf9fce6567ad4ae0409c82e388917a220f4acc2637875768df486127491cf9
7
- data.tar.gz: 8d087e11e9c7ba065bf07b4cff4ff51011ecf903fd830aa5ec51d8dcb2c18ded53c3cfbf38cc8226f7d4f46590bc3868fa902bfcc2011c1e19c1586868a920eb
6
+ metadata.gz: 3c43a34b04c1d010a783da8646dfff11d50892a15faa5660730e9d284b046dfdf921adbcaff550ca0b2a25bbc5537060b457f37e11c7d64aa6bb7271cd8975ae
7
+ data.tar.gz: e0523fab127204c4400921d2e1bc6bdbf8ed6c61b8c731707d92b8fa916e1c7320290c18546168bee757888dfd2ae3ad5953cb1b55557e9e5f40997428cb66d4
data/lib/fakefs/dir.rb CHANGED
@@ -117,10 +117,10 @@ module FakeFS
117
117
  Dir.open(dirname) { |file| yield file }
118
118
  end
119
119
 
120
- def self.glob(pattern, flags = 0, &block)
120
+ def self.glob(pattern, _flags = 0, flags: _flags, base: nil, &block) # rubocop:disable Lint/UnderscorePrefixedVariableName
121
+ pwd = FileSystem.normalize_path(base || Dir.pwd)
121
122
  matches_for_pattern = lambda do |matcher|
122
- [FileSystem.find(matcher, flags, true) || []].flatten.map do |e|
123
- pwd = Dir.pwd
123
+ [FileSystem.find(matcher, flags, true, dir: pwd) || []].flatten.map do |e|
124
124
  pwd_regex = %r{\A#{pwd.gsub('+') { '\+' }}/?}
125
125
  if pwd.match(%r{\A/?\z}) ||
126
126
  !e.to_s.match(pwd_regex)
@@ -20,12 +20,12 @@ module FakeFS
20
20
  fs.entries
21
21
  end
22
22
 
23
- def find(path, find_flags = 0, gave_char_class = false)
24
- parts = path_parts(normalize_path(path))
23
+ def find(path, find_flags = 0, gave_char_class = false, dir: nil)
24
+ parts = path_parts(normalize_path(path, dir: dir))
25
25
  return fs if parts.empty? # '/'
26
26
 
27
27
  entries = Globber.expand(path).flat_map do |pattern|
28
- parts = path_parts(normalize_path(pattern))
28
+ parts = path_parts(normalize_path(pattern, dir: dir))
29
29
  find_recurser(fs, parts, find_flags, gave_char_class).flatten
30
30
  end
31
31
 
@@ -100,11 +100,13 @@ module FakeFS
100
100
  Globber.path_components(path)
101
101
  end
102
102
 
103
- def normalize_path(path)
103
+ def normalize_path(path, dir: nil)
104
104
  if Pathname.new(path).absolute?
105
105
  RealFile.expand_path(path)
106
106
  else
107
- parts = dir_levels + [path]
107
+ dir ||= dir_levels
108
+ dir = Array(dir)
109
+ parts = dir + [path]
108
110
  RealFile.expand_path(parts.reduce do |base, part|
109
111
  Pathname(base) + part
110
112
  end.to_s)
@@ -909,11 +909,11 @@ module FakeFS
909
909
  # Pathname class
910
910
  class Pathname # * Dir *
911
911
  # See <tt>Dir.glob</tt>. Returns or yields Pathname objects.
912
- def self.glob(*args) # :yield: pathname
912
+ def self.glob(*args, **opts) # :yield: pathname
913
913
  if block_given?
914
- Dir.glob(*args) { |f| yield new(f) }
914
+ Dir.glob(*args, **opts) { |f| yield new(f) }
915
915
  else
916
- Dir.glob(*args).map { |f| new(f) }
916
+ Dir.glob(*args, **opts).map { |f| new(f) }
917
917
  end
918
918
  end
919
919
 
@@ -953,6 +953,14 @@ module FakeFS
953
953
  def opendir(&block) # :yield: dir
954
954
  Dir.open(@path, &block)
955
955
  end
956
+
957
+ def glob(pattern, flags = 0)
958
+ if block_given?
959
+ Dir.glob(pattern, flags: flags, base: self) { |f| yield join(f) }
960
+ else
961
+ Dir.glob(pattern, flags: flags, base: self).map { |f| join(f) }
962
+ end
963
+ end
956
964
  end
957
965
 
958
966
  # Pathname class
@@ -1,7 +1,7 @@
1
1
  module FakeFS
2
2
  # Version module
3
3
  module Version
4
- VERSION = '1.3.2'.freeze
4
+ VERSION = '1.4.0'.freeze
5
5
 
6
6
  def self.to_s
7
7
  VERSION
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fakefs
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.2
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Wanstrath
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2021-01-04 00:00:00.000000000 Z
15
+ date: 2021-10-21 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: bump
@@ -129,7 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
129
129
  - !ruby/object:Gem::Version
130
130
  version: '0'
131
131
  requirements: []
132
- rubygems_version: 3.1.3
132
+ rubygems_version: 3.2.16
133
133
  signing_key:
134
134
  specification_version: 4
135
135
  summary: A fake filesystem. Use it in your tests.