reloader_gem 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -20,6 +20,14 @@ Or install it yourself as:
20
20
 
21
21
  require "reloader_gem"
22
22
 
23
+ Reload gem name_of_gem
24
+
23
25
  ReloaderGem.new(name_of_gem)
24
26
 
25
- where name_of_gem is name of gem which you want modify
27
+ If you know full path into gem
28
+
29
+ ReloaderGem.new(path_of_gem)
30
+
31
+ Setting the frequency of checking Gemu (in seconds)
32
+
33
+ ReloaderGem.new(name_of_gem, 0.5)
@@ -1,3 +1,3 @@
1
1
  class ReloaderGem
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/lib/reloader_gem.rb CHANGED
@@ -6,10 +6,19 @@ require "logger"
6
6
 
7
7
  class ReloaderGem
8
8
 
9
- def initialize(gem_name, time = 0.5)
9
+ def initialize(gem_name_path, time = 0.5)
10
10
  @logger = Logger.new(STDOUT)
11
- @gem_name = gem_name
12
- @gem_dir = Gem::Specification.find_by_name(@gem_name).gem_dir
11
+
12
+ if gem_name_path.split("/").last == gem_name_path
13
+ @gem_name = gem_name_path
14
+ @gem_path = Gem::Specification.find_by_name(@gem_name).gem_dir
15
+ puts @gem_name
16
+ puts @gem_path
17
+ else
18
+ @gem_name = gem_name_path.split("/").last
19
+ @gem_path = gem_name_path
20
+ end
21
+
13
22
  @check_sum = md5_gem
14
23
  @time = time
15
24
  run
@@ -22,13 +31,7 @@ private
22
31
  while true
23
32
  sleep @time
24
33
  begin
25
- check_sum = md5_gem
26
- unless check_sum == @check_sum
27
- @check_sum = check_sum
28
- $".delete_if{|item| item.include?(@gem_name)}
29
- require @gem_name
30
- @logger.info "----- updated gem #{@gem_name} -----"
31
- end
34
+ require_gem if change_check_sum?
32
35
  rescue
33
36
  @logger.info "----- not updated gem #{@gem_name} -----"
34
37
  end
@@ -36,9 +39,22 @@ private
36
39
  end
37
40
  end
38
41
 
42
+ def require_gem
43
+ $".delete_if{|item| item.include?(@gem_name)}
44
+ require File.join(@gem_path, "lib", @gem_name)
45
+ @logger.info "----- updated gem #{@gem_name} -----"
46
+ end
47
+
48
+ def change_check_sum?
49
+ check_sum = md5_gem
50
+ return false if check_sum == @check_sum
51
+ @check_sum = check_sum
52
+ true
53
+ end
54
+
39
55
  def md5_gem
40
56
  result = ""
41
- Dir["#{@gem_dir}/**/*.rb"].each do |path|
57
+ Dir["#{@gem_path}/**/*.rb"].each do |path|
42
58
  result << Digest::MD5.hexdigest(File.read(path))
43
59
  end
44
60
  result
data/reloader_gem.gemspec CHANGED
@@ -6,7 +6,7 @@ Gem::Specification.new do |gem|
6
6
  gem.email = ["raglub.ruby@gmail.com"]
7
7
  gem.description = %q{Reload gem when we change content of gem}
8
8
  gem.summary = %q{Reload gem when we change content of gem}
9
- gem.date = "2012-08-08"
9
+ gem.date = "2012-08-17"
10
10
  gem.homepage = "https://github.com/raglub/reloader_gem"
11
11
 
12
12
  gem.files = `git ls-files`.split($\)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reloader_gem
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-08 00:00:00.000000000 Z
12
+ date: 2012-08-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: logger