Class: RuVim::ConfigLoader
- Inherits:
-
Object
- Object
- RuVim::ConfigLoader
- Defined in:
- lib/ruvim/config_loader.rb
Constant Summary collapse
- SAFE_FILETYPE_RE =
/\A[a-zA-Z0-9_+-]+\z/.freeze
Instance Method Summary collapse
-
#initialize(command_registry:, ex_registry:, keymaps:, command_host:) ⇒ ConfigLoader
constructor
A new instance of ConfigLoader.
- #load_default! ⇒ Object
- #load_file(path, editor: nil, filetype: nil) ⇒ Object
- #load_ftplugin!(editor, buffer) ⇒ Object
Constructor Details
#initialize(command_registry:, ex_registry:, keymaps:, command_host:) ⇒ ConfigLoader
Returns a new instance of ConfigLoader.
7 8 9 10 11 12 |
# File 'lib/ruvim/config_loader.rb', line 7 def initialize(command_registry:, ex_registry:, keymaps:, command_host:) @command_registry = command_registry @ex_registry = ex_registry @keymaps = keymaps @command_host = command_host end |
Instance Method Details
#load_default! ⇒ Object
14 15 16 17 18 19 |
# File 'lib/ruvim/config_loader.rb', line 14 def load_default! path = xdg_config_path return nil unless File.file?(path) load_file(path) end |
#load_file(path, editor: nil, filetype: nil) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/ruvim/config_loader.rb', line 21 def load_file(path, editor: nil, filetype: nil) dsl = ConfigDSL.new( command_registry: @command_registry, ex_registry: @ex_registry, keymaps: @keymaps, command_host: @command_host, editor: editor, filetype: filetype ) code = File.read(path) dsl.instance_eval(code, path, 1) path end |
#load_ftplugin!(editor, buffer) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/ruvim/config_loader.rb', line 35 def load_ftplugin!(editor, buffer) filetype = buffer.["filetype"].to_s return nil if filetype.empty? return nil if buffer.["__ftplugin_loaded__"] == filetype return nil unless safe_filetype_name?(filetype) path = ftplugin_path_for(filetype) return nil unless path && File.file?(path) load_file(path, editor:, filetype:) buffer.["__ftplugin_loaded__"] = filetype path end |