reloader_gem 0.1.2 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -22,12 +22,16 @@ Or install it yourself as:
22
22
 
23
23
  Reload gem name_of_gem
24
24
 
25
- ReloaderGem.new(name_of_gem)
25
+ ReloaderGem.new(name_of_gem).listen
26
26
 
27
27
  If you know full path into gem
28
28
 
29
- ReloaderGem.new(path_of_gem)
29
+ ReloaderGem.new(path_of_gem).listen
30
30
 
31
31
  Setting the frequency of checking Gemu (in seconds)
32
32
 
33
- ReloaderGem.new(name_of_gem, 0.5)
33
+ ReloaderGem.new(name_of_gem, 0.5).listen
34
+
35
+ Load the files defined in gem but not 'require'
36
+
37
+ ReloaderGem.new(path_of_gem, 0.1).load("lib/reloader_gem_spec/*.rb").listen
data/lib/reloader_gem.rb CHANGED
@@ -19,37 +19,60 @@ class ReloaderGem
19
19
 
20
20
  @check_sum = md5_gem
21
21
  @time = time
22
- run
22
+ @load_files =[]
23
23
  end
24
24
 
25
- private
26
-
27
- def run
25
+ # listen the gem
26
+ def listen
27
+ load_files
28
28
  Thread.new do
29
29
  while true
30
30
  sleep @time
31
- begin
32
- require_gem if change_check_sum?
33
- rescue
34
- @logger.info "----- not updated gem #{@gem_name} -----"
35
- end
31
+ update_files
36
32
  end
37
33
  end
38
34
  end
39
35
 
36
+ # load all files from gem which match into variable regexp
37
+ def load(regexp)
38
+ @load_files += Dir[File.join(@gem_path, regexp)]
39
+ self
40
+ end
41
+
42
+ private
43
+
44
+ # if the gem is changed, require gem and load files?
45
+ def update_files
46
+ return unless changed_gem?
47
+ require_gem
48
+ load_files
49
+ rescue
50
+ @logger.info "----- not updated gem #{@gem_name} -----"
51
+ end
52
+
53
+ # remove old version of gem and require a new version this gem
40
54
  def require_gem
41
55
  $".delete_if{|item| item.include?(@gem_name)}
42
56
  require File.join(@gem_path, "lib", @gem_name)
43
57
  @logger.info "----- updated gem #{@gem_name} -----"
44
58
  end
45
59
 
46
- def change_check_sum?
60
+ # load all files defined in variable @load_files
61
+ def load_files
62
+ @load_files.each do |path|
63
+ Kernel::load path
64
+ end
65
+ end
66
+
67
+ # is new version of gem?
68
+ def changed_gem?
47
69
  check_sum = md5_gem
48
70
  return false if check_sum == @check_sum
49
71
  @check_sum = check_sum
50
72
  true
51
73
  end
52
74
 
75
+ # count check sum for declared the gem
53
76
  def md5_gem
54
77
  result = ""
55
78
  Dir["#{@gem_path}/**/*.rb"].each do |path|
@@ -1,3 +1,3 @@
1
1
  class ReloaderGem
2
- VERSION = "0.1.2"
2
+ VERSION = "0.2.2"
3
3
  end
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-17"
9
+ gem.date = "2012-09-17"
10
10
  gem.homepage = "https://github.com/raglub/reloader_gem"
11
11
 
12
12
  gem.files = `git ls-files`.split($\)
@@ -0,0 +1,52 @@
1
+ # encoding: utf-8
2
+
3
+ require 'reloader_gem'
4
+
5
+ def set_method(value = "0.0.3")
6
+ file_path = File.expand_path("../reloader_gem_spec/lib/reloader_gem_spec/load_file.rb", __FILE__)
7
+ context = <<EOF
8
+ module ReloaderGemSpec
9
+ def self.test
10
+ "#{value}"
11
+ end
12
+ end
13
+ EOF
14
+ File.write(file_path, context)
15
+ end
16
+
17
+ def set_version(version = "0.0.1")
18
+ file_path = File.expand_path("../reloader_gem_spec/lib/reloader_gem_spec/version.rb", __FILE__)
19
+ context = <<EOF
20
+ module ReloaderGemSpec
21
+ VERSION = "#{version}"
22
+ end
23
+ EOF
24
+ File.write(file_path, context)
25
+ end
26
+
27
+ set_version
28
+ set_method
29
+
30
+ require_relative 'reloader_gem_spec/lib/reloader_gem_spec.rb'
31
+
32
+ describe ReloaderGem do
33
+ before(:all) do
34
+ gem_path = File.expand_path("../reloader_gem_spec", __FILE__)
35
+ ReloaderGem.new(gem_path, 0.1).load("lib/reloader_gem_spec/load_file.rb").listen
36
+ end
37
+
38
+ it "should properly require gem reloader_gem_spec" do
39
+ ReloaderGemSpec::VERSION.should eql("0.0.1")
40
+ set_version("0.0.2")
41
+ sleep(0.5)
42
+ ReloaderGemSpec::VERSION.should eql("0.0.2")
43
+ end
44
+
45
+ it "should properly load files from gem" do
46
+ ReloaderGemSpec::test.should eql("0.0.3")
47
+ set_method("0.0.4")
48
+ sleep(0.5)
49
+ ReloaderGemSpec.test.should eql("0.0.4")
50
+ end
51
+
52
+ end
@@ -0,0 +1,7 @@
1
+ require_relative "reloader_gem_spec/version"
2
+
3
+ module ReloaderGemSpec
4
+ def run
5
+ "method run"
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ module ReloaderGemSpec
2
+ def self.test
3
+ "0.0.4"
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module ReloaderGemSpec
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,17 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'reloader_gem_spec/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "reloader_gem_spec"
8
+ gem.version = ReloaderGemSpec::VERSION
9
+ gem.authors = ["michal szyma"]
10
+ gem.email = ["raglub.ruby@gmail.com"]
11
+ gem.description = %q{Internal gem only for testing}
12
+ gem.summary = %q{Internal gem only for testing}
13
+ gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.require_paths = ["lib"]
17
+ end
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.2
4
+ version: 0.2.2
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-17 00:00:00.000000000 Z
12
+ date: 2012-09-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: logger
@@ -42,6 +42,11 @@ files:
42
42
  - lib/reloader_gem.rb
43
43
  - lib/reloader_gem/version.rb
44
44
  - reloader_gem.gemspec
45
+ - spec/reloader_gem_spec.rb
46
+ - spec/reloader_gem_spec/lib/reloader_gem_spec.rb
47
+ - spec/reloader_gem_spec/lib/reloader_gem_spec/load_file.rb
48
+ - spec/reloader_gem_spec/lib/reloader_gem_spec/version.rb
49
+ - spec/reloader_gem_spec/reloader_gem_spec.gemspec
45
50
  homepage: https://github.com/raglub/reloader_gem
46
51
  licenses: []
47
52
  post_install_message:
@@ -66,4 +71,9 @@ rubygems_version: 1.8.24
66
71
  signing_key:
67
72
  specification_version: 3
68
73
  summary: Reload gem when we change content of gem
69
- test_files: []
74
+ test_files:
75
+ - spec/reloader_gem_spec.rb
76
+ - spec/reloader_gem_spec/lib/reloader_gem_spec.rb
77
+ - spec/reloader_gem_spec/lib/reloader_gem_spec/load_file.rb
78
+ - spec/reloader_gem_spec/lib/reloader_gem_spec/version.rb
79
+ - spec/reloader_gem_spec/reloader_gem_spec.gemspec