Class: VagrantPlugins::Fsevents::Paths
- Inherits:
-
Object
- Object
- VagrantPlugins::Fsevents::Paths
- Defined in:
- lib/vagrant-fsevents/paths.rb
Overview
Logic for paths to watch and ignore
Instance Attribute Summary collapse
-
#ignore ⇒ Object
readonly
Returns the value of attribute ignore.
-
#watch ⇒ Object
readonly
Returns the value of attribute watch.
Instance Method Summary collapse
-
#active_for_folder?(options) ⇒ Boolean
checks to ensure that a path watch is not completely disabled.
-
#add_folders_to_ignore(folders) ⇒ Object
Populates ‘@ignore` attribute from a single VM instance.
-
#add_folders_to_watch(machine, folders) ⇒ Object
Populates ‘@watch` attribute from a single VM instance.
-
#exclude_to_regexp(exclude) ⇒ Object
This is REALLY ghetto, but its a start.
-
#initialize ⇒ Paths
constructor
A new instance of Paths.
- #process(machine, folders) ⇒ Object
Constructor Details
#initialize ⇒ Paths
Returns a new instance of Paths.
8 9 10 11 |
# File 'lib/vagrant-fsevents/paths.rb', line 8 def initialize @watch = {} @ignore = [] end |
Instance Attribute Details
#ignore ⇒ Object (readonly)
Returns the value of attribute ignore.
6 7 8 |
# File 'lib/vagrant-fsevents/paths.rb', line 6 def ignore @ignore end |
#watch ⇒ Object (readonly)
Returns the value of attribute watch.
5 6 7 |
# File 'lib/vagrant-fsevents/paths.rb', line 5 def watch @watch end |
Instance Method Details
#active_for_folder?(options) ⇒ Boolean
checks to ensure that a path watch is not completely disabled
60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/vagrant-fsevents/paths.rb', line 60 def active_for_folder?() ( ( == true) || ( .respond_to?(:include?) && ( .include?(:modified) || .include?(:added) || .include?(:removed) ) ) ) end |
#add_folders_to_ignore(folders) ⇒ Object
Populates ‘@ignore` attribute from a single VM instance
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/vagrant-fsevents/paths.rb', line 36 def add_folders_to_ignore(folders) folders.values.each do |folder| folder.values.each do |opts| next unless active_for_folder?(opts[:fsevents]) Array(opts[:exclude]).each do |pattern| @ignore << exclude_to_regexp(pattern.to_s) end end end end |
#add_folders_to_watch(machine, folders) ⇒ Object
Populates ‘@watch` attribute from a single VM instance
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/vagrant-fsevents/paths.rb', line 19 def add_folders_to_watch(machine, folders) folders.values.each do |folder| folder.each do |id, opts| next unless active_for_folder? opts[:fsevents] hostpath = File.(opts[:hostpath], machine.env.root_path) hostpath = Vagrant::Util::Platform.fs_real_path(hostpath).to_s # Avoid creating a nested directory hostpath += '/' unless hostpath.end_with?('/') @watch[hostpath] = { id: id, machine: machine, opts: opts } end end end |
#exclude_to_regexp(exclude) ⇒ Object
This is REALLY ghetto, but its a start. We can improve and keep unit tests passing in the future.
50 51 52 53 54 55 56 57 |
# File 'lib/vagrant-fsevents/paths.rb', line 50 def exclude_to_regexp(exclude) exclude = exclude.gsub('**', '|||GLOBAL|||') exclude = exclude.gsub('*', '|||PATH|||') exclude = exclude.gsub('|||PATH|||', '[^/]*') exclude = exclude.gsub('|||GLOBAL|||', '.*') Regexp.new(exclude) end |
#process(machine, folders) ⇒ Object
13 14 15 16 |
# File 'lib/vagrant-fsevents/paths.rb', line 13 def process(machine, folders) add_folders_to_watch(machine, folders) add_folders_to_ignore(folders) end |