Module: Dotify::Config
Constant Summary collapse
- DEFAULTS =
{ :dirname => '.dotify', :file => '.dotrc', :editor => 'vim', :ignore => { :dotify => %w[.DS_Store .git .gitmodule], :dotfiles => %w[.DS_Store .Trash .dropbox .dotify] } }.freeze
Instance Method Summary collapse
- #dirname ⇒ Object
- #editor ⇒ Object
- #file ⇒ Object
- #home(file_or_path = nil) ⇒ Object
- #ignore(what) ⇒ Object
- #installed? ⇒ Boolean
- #path(file_or_path = nil) ⇒ Object
- #retrieve ⇒ Object
Instance Method Details
#dirname ⇒ Object
20 21 22 |
# File 'lib/dotify/config.rb', line 20 def dirname @dirname ||= DEFAULTS[:dirname] end |
#editor ⇒ Object
38 39 40 |
# File 'lib/dotify/config.rb', line 38 def editor retrieve.fetch(:editor, DEFAULTS[:editor]) end |
#file ⇒ Object
59 60 61 |
# File 'lib/dotify/config.rb', line 59 def file File.join(home, DEFAULTS[:file]) end |
#home(file_or_path = nil) ⇒ Object
24 25 26 |
# File 'lib/dotify/config.rb', line 24 def home(file_or_path = nil) file_or_path.nil? ? user_home : File.join(user_home, file_or_path) end |
#ignore(what) ⇒ Object
42 43 44 |
# File 'lib/dotify/config.rb', line 42 def ignore(what) (retrieve.fetch(:ignore, {}).fetch(what, []) + DEFAULTS[:ignore].fetch(what, [])).uniq end |
#installed? ⇒ Boolean
34 35 36 |
# File 'lib/dotify/config.rb', line 34 def installed? File.exists?(path) && File.directory?(path) end |
#path(file_or_path = nil) ⇒ Object
28 29 30 31 32 |
# File 'lib/dotify/config.rb', line 28 def path(file_or_path = nil) joins = [self.home, dirname] joins << file_or_path unless file_or_path.nil? File.join *joins end |
#retrieve ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/dotify/config.rb', line 46 def retrieve return @hash if @hash.class == Hash if File.exists?(file) loaded = YAML.load_file(file) @hash = loaded == false ? {} : loaded else @hash = {} end symbolize_keys! @hash rescue TypeError {} end |