Module: MonkeyReloader

Defined in:
lib/monkey-reloader.rb,
lib/monkey-reloader/version.rb

Constant Summary collapse

VERSION =
'0.0.5'
@@hash =
'HEAD'
@@whitelist =
nil
@@blacklist =
nil

Class Method Summary collapse

Class Method Details

.blacklist(files = []) ⇒ Object



65
66
67
68
69
# File 'lib/monkey-reloader.rb', line 65

def blacklist(files = [])
  @@blacklist ||= Set.new

  expand_paths @@blacklist.merge parse_paths files
end

.config(opts = {}) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/monkey-reloader.rb', line 13

def config(opts = {})
  whitelist = opts[:whitelist]
  if !whitelist or whitelist.empty?
    raise ArgumentError.new 'whitelist expected'
  end

  blacklist = opts.key?(:blacklist) ? opts[:blacklist] : [
    # by default, block dangerous Rails behavior
    'bin',
    'config',
    'db',
    'log',
    'script',
    'spec',
  ].select {|dir| Dir.exists? dir}

  @@whitelist = Set.new
  self.whitelist whitelist

  @@blacklist = Set.new
  self.blacklist blacklist

  update_hash

  self
end

.loadObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/monkey-reloader.rb', line 40

def load
  # reload all changed files
  wlist = whitelist
  blist = blacklist

  files = changed_files.select do |file|
    wlist.include? file
  end.reject do |file|
    blist.include? file
  end

  update_hash
  pwd = Pathname.new Dir.pwd

  files.each do |file|
    Kernel.load file
  end
end

.whitelist(files = []) ⇒ Object



59
60
61
62
63
# File 'lib/monkey-reloader.rb', line 59

def whitelist(files = [])
  @@whitelist ||= Set.new

  expand_paths @@whitelist.merge parse_paths files
end