fagin 1.0.3 → 1.1.0

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 +30 -4
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4e85299de076777cb9895bb61f2b289b2a1cb80071eb18398f1b66afdd8aaa44
4
- data.tar.gz: c8175e55fa69749b997187bb46f662abeef9d77546e94843cfa3c8cb2355283b
3
+ metadata.gz: 341dd1040e22d1cd15e631a07e8a4d513ce9cacf337de9497e95d194cd6375b2
4
+ data.tar.gz: 96ba74cbd13ee8248e3cadda9fe3aa3ea0bb904463f8f5b0968f9087ffc44f2c
5
5
  SHA512:
6
- metadata.gz: fcc61156707797a8e0f5bbfb2315d59d77968c474bfed2b2acb0fe668a9b3d090875b4c3e4cc0744267eeacbee2494bb6a4874bbf9d3d90e4c0312bdfd9de5fe
7
- data.tar.gz: 7c2ae8245c08b866adba6e2648d1a51004255a7a424ea2bc39d26e4b13acc8bbb7ec67b616d84b9b4f71a9327fe3541f5f083fac4e1447ba6f85316b2b927263
6
+ metadata.gz: 6d752c5e24b90cfeb21e1bf40f107612fd680ad6762363a7652b8542d054f132b145c3de685cdcaa3ff104f27b058842cf9490ab75467f1e2d4afafafede99ac
7
+ data.tar.gz: '019a92d36b3d2f3d4284e7c7a876cf4baa30b8c0287716b0dbb09af5f28738cc13f944d8b6fc120c209c2ccc666f7db13b908843f0ee111073851b2edf332661'
data/lib/fagin.rb CHANGED
@@ -4,17 +4,43 @@ class Fagin
4
4
  def self.find_children(parent, dir)
5
5
  children = Hash.new
6
6
  path = Pathname.new(dir).expand_path
7
+ return children if (!path.exist?)
7
8
 
8
- files = Dir["#{path}/*.rb"]
9
- return children if (files.empty?)
9
+ %x(
10
+ \grep -EHos "^class +.+ *< *#{parent}" #{path}/*.rb
11
+ ).each_line do |line|
12
+ clas = line.match(/class\s+(\S+)\s*</)[1]
13
+ next if (clas.nil? || clas.empty?)
14
+ file = line.match(/^([^:]+\.rb)/)[1]
15
+ next if (file.nil? || file.empty?)
16
+ begin
17
+ require_relative file
18
+ child = clas.split("::").inject(Object) do |m, c|
19
+ m.const_get(c)
20
+ end
21
+ children[clas] = child
22
+ rescue NameError
23
+ raise Error::UnknownChildClassError.new(clas)
24
+ end
25
+ end
26
+
27
+ return children
28
+ end
29
+
30
+ def self.find_children_recursively(parent, dir)
31
+ children = Hash.new
32
+ path = Pathname.new(dir).expand_path
33
+ return children if (!path.exist?)
10
34
 
11
35
  %x(
12
- \grep -EHo "^class +.+ *< *#{parent}" #{files.join(" ")}
36
+ \grep -EHors "^class +.+ *< *#{parent}" #{path}
13
37
  ).each_line do |line|
14
38
  clas = line.match(/class\s+(\S+)\s*</)[1]
15
39
  next if (clas.nil? || clas.empty?)
40
+ file = line.match(/^([^:]+\.rb)/)[1]
41
+ next if (file.nil? || file.empty?)
16
42
  begin
17
- require_relative line.match(/^([^:]+)/)[1]
43
+ require_relative file
18
44
  child = clas.split("::").inject(Object) do |m, c|
19
45
  m.const_get(c)
20
46
  end
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.0.3
4
+ version: 1.1.0
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-02-23 00:00:00.000000000 Z
11
+ date: 2018-03-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake