Class: RailsDevelopmentBoost::LoadedFile

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

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, constants = []) ⇒ LoadedFile

Returns a new instance of LoadedFile.



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

def initialize(path, constants=[])
  @path       = path
  @constants  = constants
  @mtime      = current_mtime
end

Class Attribute Details

.constants_to_filesObject (readonly)

Returns the value of attribute constants_to_files.



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

def constants_to_files
  @constants_to_files
end

Instance Attribute Details

#constantsObject

Returns the value of attribute constants.



9
10
11
# File 'lib/rails_development_boost/loaded_file.rb', line 9

def constants
  @constants
end

#pathObject

Returns the value of attribute path.



9
10
11
# File 'lib/rails_development_boost/loaded_file.rb', line 9

def path
  @path
end

Class Method Details

.each_file_with_const(const_name, &block) ⇒ Object



49
50
51
52
53
# File 'lib/rails_development_boost/loaded_file.rb', line 49

def self.each_file_with_const(const_name, &block)
  if files = constants_to_files[const_name]
    files.dup.each(&block)
  end
end

Instance Method Details

#add_constants(new_constants) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/rails_development_boost/loaded_file.rb', line 23

def add_constants(new_constants)
  new_constants.each do |new_constant|
    (constants_to_files[new_constant] ||= []) << self
  end
  @constants |= new_constants
  retrieve_associated_files.each {|file| file.add_constants(@constants)} if @associated_files
end

#associate_with(other_loaded_file) ⇒ Object



36
37
38
# File 'lib/rails_development_boost/loaded_file.rb', line 36

def associate_with(other_loaded_file)
  (@associated_files ||= []) << other_loaded_file
end

#changed?Boolean

Returns:

  • (Boolean)


18
19
20
21
# File 'lib/rails_development_boost/loaded_file.rb', line 18

def changed?
  previous_mtime, @mtime = @mtime, current_mtime
  previous_mtime != @mtime
end

#delete_constant(const_name) ⇒ Object



31
32
33
34
# File 'lib/rails_development_boost/loaded_file.rb', line 31

def delete_constant(const_name)
  delete_from_constants_to_files(const_name)
  @constants.delete(const_name)
end

#require_pathObject



45
46
47
# File 'lib/rails_development_boost/loaded_file.rb', line 45

def require_path
  @path.sub(/\.rb\Z/, '')
end

#retrieve_associated_filesObject



40
41
42
43
# File 'lib/rails_development_boost/loaded_file.rb', line 40

def retrieve_associated_files
  associated_files, @associated_files = @associated_files, nil
  associated_files
end

#stale!Object



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

def stale!
  @mtime = 0
  if associated_files = retrieve_associated_files
    associated_files.each(&:stale!)
  end
end