lib/chef_fs/config.rb
def server_path(file_path)
      pwd = File.expand_path(Dir.pwd)
      absolute_path = ChefFS::PathUtils.realest_path(File.expand_path(file_path, pwd))

      # Check all object paths (cookbooks_dir, data_bags_dir, etc.)
      object_paths.each_pair do |name, paths|
        paths.each do |path|
          realest_path = ChefFS::PathUtils.realest_path(path)
          if absolute_path[0,realest_path.length] == realest_path &&
            (absolute_path.length == realest_path.length ||
              absolute_path[realest_path.length,1] =~ /#{PathUtils.regexp_path_separator}/)
            relative_path = ChefFS::PathUtils::relative_to(absolute_path, realest_path)
            return relative_path == '.' ? "/#{name}" : "/#{name}/#{relative_path}"
          end
        end
      end

      # Check chef_repo_path
      Array(@chef_config[:chef_repo_path]).flatten.each do |chef_repo_path|
        realest_chef_repo_path = ChefFS::PathUtils.realest_path(chef_repo_path)
        if absolute_path == realest_chef_repo_path
          return '/'
        end
      end

      nil
    end
def server_path(file_path)
      pwd = File.expand_path(Dir.pwd)
      absolute_path = ChefFS::PathUtils.realest_path(File.expand_path(file_path, pwd))

      # Check all object paths (cookbooks_dir, data_bags_dir, etc.)
      object_paths.each_pair do |name, paths|
        paths.each do |path|
          realest_path = ChefFS::PathUtils.realest_path(path)
          if absolute_path[0,realest_path.length] == realest_path &&
            (absolute_path.length == realest_path.length ||
              absolute_path[realest_path.length,1] =~ /#{PathUtils.regexp_path_separator}/)
            relative_path = ChefFS::PathUtils::relative_to(absolute_path, realest_path)
            return relative_path == '.' ? "/#{name}" : "/#{name}/#{relative_path}"
          end
        end
      end

      # Check chef_repo_path
      Array(@chef_config[:chef_repo_path]).flatten.each do |chef_repo_path|
        realest_chef_repo_path = ChefFS::PathUtils.realest_path(chef_repo_path)
        if absolute_path == realest_chef_repo_path
          return '/'
        end
      end

      nil
    end
Returns the given real path's location relative to the server root.

 If chef_repo is /home/jkeiser/chef_repo,
 and pwd is /home/jkeiser/chef_repo/cookbooks,
 server_path('blah') == '/cookbooks/blah'
 server_path('../roles/blah.json') == '/roles/blah'
 server_path('../../readme.txt') == nil
 server_path('*/*ab*') == '/cookbooks/*/*ab*'
 server_path('/home/jkeiser/chef_repo/cookbooks/blah') == '/cookbooks/blah'
 server_path('/home/*/chef_repo/cookbooks/blah') == nil

 If there are multiple paths (cookbooks, roles, data bags, etc. can all
 have separate paths), and cwd+the path reaches into one of them, we will
 return a path relative to that.  Otherwise we will return a path to
 chef_repo.

 Globs are allowed as well, but globs outside server paths are NOT
 (presently) supported.  See above examples.  TODO support that.

 If the path does not reach into ANY specified directory, nil is returned.