monkey-reloader 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5743e94643dba7fb9fab7f37cbbcff4c17dc6aee
4
- data.tar.gz: 29a6ad7d9a71ab739c63ef481b29b54858148c0a
3
+ metadata.gz: 716dbb88b043f708ffe48d905278539914757e28
4
+ data.tar.gz: 82a60e131266fd7e18fe91c0fe457fc6a015c758
5
5
  SHA512:
6
- metadata.gz: 6396da66d132cfc23a020b943ed9a3ea71a0b15ed067818bf2d12e5140cbb7c91dc9b48975f1b6aad936362b3d2953f30ba80e3af9470f19c5b9dd2827b2f760
7
- data.tar.gz: 0dbce19a3933054b2e92014c1021f32ba3963b92b717d2f6c38c89889e6b818ed4884fdaef95ee15c9be0d46d10cf5dc7847d9b06ca174d3da16acb53e0d7a24
6
+ metadata.gz: 53597bcdc89edf732809b4ec440958adcc31042afc1d1c9aff7c7c82538c41b9394d0c1e2daad8c8e068f97b422c79744e72a364ba8b69937799ca42b5eb9694
7
+ data.tar.gz: 532dbb52c91ba348339385a96449c930db2c50479e770ddca0247c26799f7afda6dcf0259f85df4d4bd8c87cb59cb246da366971129844ed702df8d492dc5a9f
@@ -1,3 +1,3 @@
1
1
  module MonkeyReloader
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -1,46 +1,113 @@
1
+ require 'set'
2
+ require 'pathname'
3
+
4
+
1
5
  module MonkeyReloader
2
6
  class << self
3
7
 
8
+ @@hash = 'HEAD'
9
+ @@whitelist = nil
10
+ @@blacklist = nil
11
+
12
+
13
+ def init(whitelist = [], blacklist = [])
14
+ @@whitelist = Set.new
15
+ self.whitelist whitelist
16
+
17
+ @@blacklist = Set.new
18
+ self.blacklist blacklist
4
19
 
5
- def init(blacklist = [])
6
- @@blacklist = Array(blacklist)
7
20
  update_hash
8
21
 
9
- true
22
+ self
10
23
  end
11
24
 
12
25
  def load
13
- files = changed_files.reject do |file|
14
- @@blacklist.include? file
26
+ wlist = whitelist
27
+ blist = blacklist
28
+
29
+ files = changed_files.select do |file|
30
+ wlist.include? file
31
+ end.reject do |file|
32
+ blist.include? file
15
33
  end
34
+
16
35
  update_hash
36
+ pwd = Pathname.new Dir.pwd
17
37
 
18
38
  files.each do |file|
19
39
  Kernel.load file
40
+ end.map do |file|
41
+ # map back to relative pathnames for convenience
42
+ Pathname.new(file).relative_path_from(pwd).to_s
20
43
  end
21
44
  end
22
45
 
46
+ def whitelist(files = [])
47
+ @@whitelist ||= Set.new
48
+
49
+ expand_paths @@whitelist.merge parse_paths files
50
+ end
51
+
52
+ def blacklist(files = [])
53
+ @@blacklist ||= Set.new
54
+
55
+ expand_paths @@blacklist.merge parse_paths files
56
+ end
57
+
23
58
 
24
59
  private
25
60
 
61
+ def parse_paths(paths = [])
62
+ Array(paths).map do |path|
63
+ path = File.expand_path path
64
+
65
+ if path.include? '*'
66
+ path
67
+ elsif Dir.exists? path
68
+ "#{path}/**/*.rb"
69
+ elsif File.exists? path
70
+ unless /\.rb$/.match path
71
+ raise ArgumentError.new ".rb files only: #{path}"
72
+ end
73
+
74
+ path
75
+ else
76
+ raise ArgumentError.new "path not found: #{path}"
77
+ end
78
+ end
79
+ end
80
+
81
+ def expand_paths(paths = [])
82
+ # recalculate path expansions - caching will miss filesystem changes
83
+ Array(paths).map do |path|
84
+ Dir[path]
85
+ end.flatten
86
+ end
87
+
26
88
  def update_hash
89
+ # get current git branch hash
27
90
  @@hash = `git rev-parse HEAD`.strip
28
91
  end
29
92
 
30
93
  def changed_files
31
- files = []
94
+ # return a list of changed files
95
+
96
+ files = Set.new
32
97
  awk = "awk '{ print $2 }'"
33
98
 
34
99
  # find recent changes
35
- files += `git status -s | #{awk}`.split
100
+ files.merge `git status -s | #{awk}`.split
36
101
 
37
102
  # find committed changes if there was a branch change / rebase
38
- files += `git diff --name-status HEAD..#{@@hash} | #{awk}`.split
103
+ files.merge `git diff --name-status HEAD..#{@@hash} | #{awk}`.split
39
104
 
40
105
  # filter for ruby files and those that dissapeared during
41
106
  # a branch change
42
107
  files.select do |file|
43
108
  /\.rb$/.match file and File.exists? file
109
+ end.map do |file|
110
+ File.expand_path file
44
111
  end
45
112
  end
46
113
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: monkey-reloader
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Pepper
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-13 00:00:00.000000000 Z
11
+ date: 2016-12-14 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |2
14
14
  fast IRB reloading for non-conventional file naming, using git