Class: Mentawai::Loader

Inherits:
Object
  • Object
show all
Defined in:
lib/mentawai/loader.rb

Instance Method Summary collapse

Constructor Details

#initialize(mentaPath = nil) ⇒ Loader

Returns a new instance of Loader.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/mentawai/loader.rb', line 4

def initialize(mentaPath = nil)
  if mentaPath then
    @file_mask = mentaPath + '/**/*.rb'
  else
    @file_mask = './Mentawai/**/*.rb'
  end
  
  puts "File mask: #{@file_mask}"
  @files = { }
  
  Dir.glob(@file_mask).each do |f|
    
    # Skip some files here...
    next if f =~ /loader\.rb$/
    next if f =~ /menta_handler\.rb$/
    next if f =~ /server\.rb$/
    next if f =~ /application\.rb$/
    
    @files[File.new(f)] = 0
  end
  
  raise "Cannot load Mentawai files: #{@file_mask}" if @files.size == 0
  
end

Instance Method Details

#files_countObject Also known as: size, length



35
36
37
# File 'lib/mentawai/loader.rb', line 35

def files_count
  @files.size
end

#reloadFilesObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/mentawai/loader.rb', line 42

def reloadFiles
  count = 0
  @files.each do |f,t|
    if t == 0 then
      puts "Loading #{f.path}" # first time
      load f.path
      count += 1
    elsif t != f.mtime
      puts "Reloading #{f.path}" # was modified
      load f.path
      count += 1
    end
    @files[f] = f.mtime # update modified time
  end
  count
end

#showFilesObject



29
30
31
32
33
# File 'lib/mentawai/loader.rb', line 29

def showFiles
  @files.each do |f,t|
    puts "#{f.path}: #{t}"
  end
end