fagin 1.1.2 → 1.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/fagin.rb +7 -29
  3. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 26beff62045a06ff5b1e59d879fe414dbb9df099a54d0126474e97c1fa54aef3
4
- data.tar.gz: 785b94eebc7d224438cf6692f7cc10f627e8f68f4ac6cafc959de66a0ac32931
3
+ metadata.gz: 4ec627f1c90e140159c4542b062be31ab8a8830cd717d8779713dec262232190
4
+ data.tar.gz: ab6c12883739989c0be041efd35140aa9762d3bf1773414efee64a4299e7d16d
5
5
  SHA512:
6
- metadata.gz: b9890956cd578cbe58f29f4bc3a96f6690fe2239795cd75456da9b3667ff2206769a0a580c1c7bce00e44713396a8cd0d5abc4aab4ac1e5aaf1f7b61180b67e3
7
- data.tar.gz: 49eb85eca76538c1142d1d44809a5ef6cd590c9370b26e233251f1f8f2996cbeb577b0245287f1f39c50275965751be28ac82f28072247974bb798585e52d61d
6
+ metadata.gz: c8a714340c867111b18a04c7afc2ee8eef242f9a5d673d1ffc9c447e2922cec61355c74ddb5b56bcba612d1f09ea31b1f72d00e1331f1c5d1698e7445cc88881
7
+ data.tar.gz: 30e35bf695755e4971778d285577ab7820787196d69d190907c916cdf02e37a08741e75bc0154d59981623d38f9ff90c13eb423e8b41647edffae171281538e1
@@ -1,14 +1,16 @@
1
1
  require "pathname"
2
2
 
3
3
  class Fagin
4
- def self.find_children(parent, dir)
4
+ def self.find_children(parent, dir, recursive = false)
5
5
  children = Hash.new
6
6
  path = Pathname.new(dir).expand_path
7
7
  return children if (!path.exist?)
8
8
 
9
- %x(
10
- \grep -EHos "^class +.+ *< *#{parent}" #{path}/*.rb
11
- ).each_line do |line|
9
+ pattern = "\"^class +[^ ]+ *< *#{parent}\""
10
+ cmd = "grep -EHors #{pattern} #{path}"
11
+ cmd += "/*.rb" if (!recursive)
12
+
13
+ %x(#{cmd}).each_line do |line|
12
14
  line.match(/^([^:]+\.rb).+class\s+(\S+)\s*</) do |match|
13
15
  file = match[1]
14
16
  next if (file.nil? || file.empty?)
@@ -30,31 +32,7 @@ class Fagin
30
32
  end
31
33
 
32
34
  def self.find_children_recursively(parent, dir)
33
- children = Hash.new
34
- path = Pathname.new(dir).expand_path
35
- return children if (!path.exist?)
36
-
37
- %x(
38
- \grep -EHors "^class +.+ *< *#{parent}" #{path}
39
- ).each_line do |line|
40
- line.match(/^([^:]+\.rb).+class\s+(\S+)\s*</) do |match|
41
- file = match[1]
42
- next if (file.nil? || file.empty?)
43
- clas = match[2]
44
- next if (clas.nil? || clas.empty?)
45
- begin
46
- require_relative file
47
- child = clas.split("::").inject(Object) do |m, c|
48
- m.const_get(c)
49
- end
50
- children[clas] = child
51
- rescue NameError
52
- raise Error::UnknownChildClass.new(clas)
53
- end
54
- end
55
- end
56
-
57
- return children
35
+ return find_children(parent, dir, true)
58
36
  end
59
37
  end
60
38
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fagin
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miles Whittaker
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-04 00:00:00.000000000 Z
11
+ date: 2018-04-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -60,7 +60,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
60
60
  version: '0'
61
61
  requirements: []
62
62
  rubyforge_project:
63
- rubygems_version: 2.7.3
63
+ rubygems_version: 2.7.6
64
64
  signing_key:
65
65
  specification_version: 4
66
66
  summary: Dynamically load children classes