Method: Chef::ChefFS::FileSystem::Repository::BaseFile#initialize

Defined in:
lib/chef/chef_fs/file_system/repository/base_file.rb

#initialize(name, parent) ⇒ BaseFile

Returns a new instance of BaseFile.



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/chef/chef_fs/file_system/repository/base_file.rb', line 37

def initialize(name, parent)
  @parent = parent

  if %w{ .rb .json }.include? File.extname(name)
    name = File.basename(name, ".*")
  end

  file_path = "#{parent.file_path}/#{name}"

  Chef::Log.trace "BaseFile: Detecting file extension for #{name}"
  ext = File.exist?(file_path + ".rb") ? ".rb" : ".json"
  name += ext
  file_path += ext

  Chef::Log.trace "BaseFile: got a file path of #{file_path} for #{name}"
  @name = name
  @path = Chef::ChefFS::PathUtils.join(parent.path, name)
  @file_path = file_path
end