Class: RailsDevelopmentBoost::LoadedFile::Files

Inherits:
Hash
  • Object
show all
Defined in:
lib/rails_development_boost/loaded_file.rb

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Files

Returns a new instance of Files.



6
7
8
9
# File 'lib/rails_development_boost/loaded_file.rb', line 6

def initialize(*args)
  @directories = {}
  super {|hash, file_path| hash[file_path] = LoadedFile.new(file_path)}
end

Instance Method Details

#[]=(file_path, loaded_file) ⇒ Object



11
12
13
14
# File 'lib/rails_development_boost/loaded_file.rb', line 11

def []=(file_path, loaded_file)
  (@directories[loaded_file.dirname] ||= Set.new) << loaded_file
  super
end

#constantsObject



63
64
65
66
67
# File 'lib/rails_development_boost/loaded_file.rb', line 63

def constants
  arr = []
  each_value {|file| arr.concat(file.constants)}
  arr
end

#delete(file_path) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/rails_development_boost/loaded_file.rb', line 16

def delete(file_path)
  if loaded_file = super
    dirname = loaded_file.dirname
    if @directories[dirname].delete(loaded_file).empty?
      @directories.delete(dirname)
    end
  end
  loaded_file
end

#find_files_in(filter_directories = nil) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/rails_development_boost/loaded_file.rb', line 43

def find_files_in(filter_directories = nil)
  if filter_directories
    arr = []
    @directories.each_pair do |dirname, files|
      arr.concat(files.to_a) if filter_directories.any? {|filter_directory| dirname.starts_with?(filter_directory)}
    end
    arr
  else
    values
  end
end

#schedule_decorator_file(file) ⇒ Object



59
60
61
# File 'lib/rails_development_boost/loaded_file.rb', line 59

def schedule_decorator_file(file)
  file.schedule_consts_for_unloading!
end

#schedule_modified_file(file) ⇒ Object



55
56
57
# File 'lib/rails_development_boost/loaded_file.rb', line 55

def schedule_modified_file(file)
  file.schedule_consts_for_unloading!
end

#stored?(file) ⇒ Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/rails_development_boost/loaded_file.rb', line 69

def stored?(file)
  key?(file.path) && self[file.path] == file
end

#unload_modified!(filter_directories = nil) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/rails_development_boost/loaded_file.rb', line 26

def unload_modified!(filter_directories = nil)
  unloaded_something = false
  find_files_in(filter_directories).each do |file|
    if file.changed?
      schedule_modified_file(file)
      unloaded_something = true
    end
  end
  if unloaded_something
    values.each do |file|
      schedule_decorator_file(file) if file.decorator_like?
    end
  end
  ActiveSupport::Dependencies.process_consts_scheduled_for_removal
  unloaded_something
end