Class: Vimmer::Settings
- Inherits:
-
Object
- Object
- Vimmer::Settings
- Defined in:
- lib/vimmer/settings.rb
Instance Method Summary collapse
- #[](key) ⇒ Object
- #add_plugin(name, path) ⇒ Object
- #config_file ⇒ Object
- #config_root ⇒ Object
- #create_default_config_file! ⇒ Object
- #create_vimmer_home! ⇒ Object
- #defaults ⇒ Object
-
#initialize ⇒ Settings
constructor
A new instance of Settings.
- #load_config(config_file) ⇒ Object
- #plugin_store_file ⇒ Object
- #plugins ⇒ Object
- #read_from_manifest ⇒ Object
- #remove_plugin(name) ⇒ Object
- #write_default_config_file ⇒ Object
- #write_to_manifest(hash) ⇒ Object
Constructor Details
#initialize ⇒ Settings
Returns a new instance of Settings.
8 9 10 |
# File 'lib/vimmer/settings.rb', line 8 def initialize @config = defaults.merge(load_config(config_file)) end |
Instance Method Details
#[](key) ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/vimmer/settings.rb', line 13 def [](key) value = File.(@config[key.to_s]) if value && File.exists?(value) Pathname.new(value) else value end end |
#add_plugin(name, path) ⇒ Object
54 55 56 57 58 59 |
# File 'lib/vimmer/settings.rb', line 54 def add_plugin(name, path) existing_plugins = plugins.dup existing_plugins.merge!(name => path) write_to_manifest(existing_plugins) end |
#config_file ⇒ Object
23 24 25 |
# File 'lib/vimmer/settings.rb', line 23 def config_file config_root.join("config") end |
#config_root ⇒ Object
31 32 33 |
# File 'lib/vimmer/settings.rb', line 31 def config_root Pathname.new(ENV['VIMMER_HOME'] || File.join(Gem.user_home, ".vimmer")) end |
#create_default_config_file! ⇒ Object
41 42 43 44 45 |
# File 'lib/vimmer/settings.rb', line 41 def create_default_config_file! return if File.exist?(config_file.to_s) write_default_config_file @config = load_config(config_file) end |
#create_vimmer_home! ⇒ Object
36 37 38 |
# File 'lib/vimmer/settings.rb', line 36 def create_vimmer_home! FileUtils.mkdir_p(config_root.to_s) end |
#defaults ⇒ Object
97 98 99 |
# File 'lib/vimmer/settings.rb', line 97 def defaults { "bundle_path" => "~/.vim/bundle" } end |
#load_config(config_file) ⇒ Object
87 88 89 90 91 92 93 94 |
# File 'lib/vimmer/settings.rb', line 87 def load_config(config_file) config_file = File.(config_file) if config_file && File.exist?(config_file.to_s) YAML.load_file(config_file) else {} end end |
#plugin_store_file ⇒ Object
27 28 29 |
# File 'lib/vimmer/settings.rb', line 27 def plugin_store_file @plugin_store_file ||= config_root.join("plugins.yml") end |
#plugins ⇒ Object
68 69 70 71 72 73 74 |
# File 'lib/vimmer/settings.rb', line 68 def plugins @plugins = if !File.exist?(plugin_store_file.to_s) write_to_manifest({}) end read_from_manifest end |
#read_from_manifest ⇒ Object
77 78 79 |
# File 'lib/vimmer/settings.rb', line 77 def read_from_manifest YAML.load_file(plugin_store_file.to_s) end |
#remove_plugin(name) ⇒ Object
61 62 63 64 65 66 |
# File 'lib/vimmer/settings.rb', line 61 def remove_plugin(name) existing_plugins = plugins.dup existing_plugins.delete(name) write_to_manifest(existing_plugins) end |
#write_default_config_file ⇒ Object
47 48 49 50 51 |
# File 'lib/vimmer/settings.rb', line 47 def write_default_config_file File.open(config_file.to_s, "w") do |f| f << "bundle_path: ~/.vim/bundle" end end |
#write_to_manifest(hash) ⇒ Object
81 82 83 84 85 |
# File 'lib/vimmer/settings.rb', line 81 def write_to_manifest(hash) File.open(plugin_store_file.to_s, "w") do |f| f << hash.to_yaml end end |