Method: FixtureTree#merge

Defined in:
lib/fixture_tree.rb

#merge(data) ⇒ Object

Merge the given directory hierarchy or file into this ‘FixtureTree`.

‘data` can be either a string or a hash. If it’s a hash, this ‘FixtureTree` will be created as a directory if it’s not already one and a file or directory created for each entry in the hash. Values can themselves be strings or hashes to create nested files or directories, respectively. If it’s a string, this ‘FixtureTree` will be created as a file whose contents are the specified string.



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/fixture_tree.rb', line 92

def merge(data)
  if data.is_a?(Hash)
    delete unless @path.directory?
    @path.mkpath

    data.each do |name, contents|
      join(name.to_s).merge(contents)
    end
  else
    delete
    @path.write(data)
  end

  self
end