Class: ReloaderGem

Inherits:
Object
  • Object
show all
Defined in:
lib/reloader_gem.rb,
lib/reloader_gem/version.rb

Constant Summary collapse

VERSION =
"0.2.2"

Instance Method Summary collapse

Constructor Details

#initialize(gem_name_path, time = 0.5) ⇒ ReloaderGem

Returns a new instance of ReloaderGem.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/reloader_gem.rb', line 9

def initialize(gem_name_path, time = 0.5)
  @logger = Logger.new(STDOUT)

  if gem_name_path.split("/").last == gem_name_path
    @gem_name = gem_name_path
    @gem_path = Gem::Specification.find_by_name(@gem_name).gem_dir
  else
    @gem_name = gem_name_path.split("/").last
    @gem_path = gem_name_path
  end

  @check_sum = md5_gem
  @time = time
  @load_files =[]
end

Instance Method Details

#listenObject

listen the gem



26
27
28
29
30
31
32
33
34
# File 'lib/reloader_gem.rb', line 26

def listen
  load_files
  Thread.new do
    while true
      sleep @time
      update_files
    end
  end
end

#load(regexp) ⇒ Object

load all files from gem which match into variable regexp



37
38
39
40
# File 'lib/reloader_gem.rb', line 37

def load(regexp)
  @load_files += Dir[File.join(@gem_path, regexp)]
  self
end