Class: Chef::ChefFS::FileSystem::PairLister

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/chef/chef_fs/file_system.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pattern, a_root, b_root) ⇒ PairLister


175
176
177
178
179
# File 'lib/chef/chef_fs/file_system.rb', line 175

def initialize(pattern, a_root, b_root)
  @pattern = pattern
  @a_root = a_root
  @b_root = b_root
end

Instance Attribute Details

#a_rootObject (readonly)

Returns the value of attribute a_root


182
183
184
# File 'lib/chef/chef_fs/file_system.rb', line 182

def a_root
  @a_root
end

#b_rootObject (readonly)

Returns the value of attribute b_root


183
184
185
# File 'lib/chef/chef_fs/file_system.rb', line 183

def b_root
  @b_root
end

#patternObject (readonly)

Returns the value of attribute pattern


181
182
183
# File 'lib/chef/chef_fs/file_system.rb', line 181

def pattern
  @pattern
end

Instance Method Details

#eachObject


185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# File 'lib/chef/chef_fs/file_system.rb', line 185

def each
  # Make sure everything on the server is also on the filesystem, and diff
  found_paths = Set.new
  Chef::ChefFS::FileSystem.list(a_root, pattern).each do |a|
    found_paths << a.display_path
    b = Chef::ChefFS::FileSystem.resolve_path(b_root, a.display_path)
    yield [ a, b ]
  end

  # Check the outer regex pattern to see if it matches anything on the
  # filesystem that isn't on the server
  Chef::ChefFS::FileSystem.list(b_root, pattern).each do |b|
    if !found_paths.include?(b.display_path)
      a = Chef::ChefFS::FileSystem.resolve_path(a_root, b.display_path)
      yield [ a, b ]
    end
  end
end