Method: RDoc.home

Defined in:
lib/rdoc.rb

.homeObject

Searches and returns the directory for settings.

  1. $HOME/.rdoc directory, if it exists.

  2. The rdoc directory under the path specified by the XDG_DATA_HOME environment variable, if it is set.

  3. $HOME/.local/share/rdoc directory.

Other than the home directory, the containing directory will be created automatically.



132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/rdoc.rb', line 132

def self.home
  rdoc_dir = begin
              File.expand_path('~/.rdoc')
            rescue ArgumentError
            end

  if File.directory?(rdoc_dir)
    rdoc_dir
  else
    require 'fileutils'
    begin
      # XDG
      xdg_data_home = ENV["XDG_DATA_HOME"] || File.join(File.expand_path("~"), '.local', 'share')
      unless File.exist?(xdg_data_home)
        FileUtils.mkdir_p xdg_data_home
      end
      File.join xdg_data_home, "rdoc"
    rescue Errno::EACCES
    end
  end
end