Module: FunWith::Files::FilePathClassMethods
- Defined in:
- lib/fun_with/files/file_path_class_methods.rb
Instance Method Summary collapse
- #cache_dir(*args) ⇒ Object
- #config_dir(*args) ⇒ Object
-
#cwd(*args) ⇒ Object
args implicitly joined to cwd.
- #data_dir(*args) ⇒ Object
- #home(*args) ⇒ Object
- #pwd(*args) ⇒ Object
-
#root(*args) ⇒ Object
Honestly this is a token attempt at Windows compatibility.
- #xdg_get(str) ⇒ Object
Instance Method Details
#cache_dir(*args) ⇒ Object
25 26 27 |
# File 'lib/fun_with/files/file_path_class_methods.rb', line 25 def cache_dir( *args ) xdg_get('CACHE_HOME').fwf_filepath.join( *args ) end |
#config_dir(*args) ⇒ Object
17 18 19 |
# File 'lib/fun_with/files/file_path_class_methods.rb', line 17 def config_dir( *args ) xdg_get('CONFIG').fwf_filepath.join( *args ) end |
#cwd(*args) ⇒ Object
args implicitly joined to cwd
5 6 7 |
# File 'lib/fun_with/files/file_path_class_methods.rb', line 5 def cwd( *args ) Dir.pwd.fwf_filepath.join( *args ) end |
#data_dir(*args) ⇒ Object
21 22 23 |
# File 'lib/fun_with/files/file_path_class_methods.rb', line 21 def data_dir( *args ) xdg_get('DATA').fwf_filepath.join( *args ) end |
#home(*args) ⇒ Object
13 14 15 |
# File 'lib/fun_with/files/file_path_class_methods.rb', line 13 def home( *args ) Dir.home.fwf_filepath.join( *args ) end |
#pwd(*args) ⇒ Object
9 10 11 |
# File 'lib/fun_with/files/file_path_class_methods.rb', line 9 def pwd( *args ) self.cwd( *args ) end |
#root(*args) ⇒ Object
Honestly this is a token attempt at Windows compatibility. This could go wrong all sorts of ways, and hasn’t been tested on Windows. More to the point, when a Windows machine has multiple drives mounted, what do you even call the root?
50 51 52 53 54 55 56 |
# File 'lib/fun_with/files/file_path_class_methods.rb', line 50 def root( *args ) if self.home =~ /^[a-zA-Z]:/ self.home.to_s[0..3].fwf_filepath.join( *args ) else "/".fwf_filepath.join( *args ) end end |
#xdg_get(str) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/fun_with/files/file_path_class_methods.rb', line 29 def xdg_get( str ) if XDG.respond_to?( :"[]" ) XDG[str] else case str when "CONFIG" XDG::Environment.new.config_home when "DATA" XDG::Environment.new.data_home when "CACHE_HOME" XDG::Environment.new.cache_home else raise "Not sure what to do with XDG:#{str}" end end end |