fagin 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 86024e067d071e5dfba0399915702f7f9f696675
4
+ data.tar.gz: 89857e493aa49706671a144c7a480c19da2b9282
5
+ SHA512:
6
+ metadata.gz: c00c88f3985c5f35fcf3e090d1088e346299d75e76737ccc6ec231d22e7cbc42676d5722b632fad7afe585ceab6578eef5530f7acb9631a609d004a862356622
7
+ data.tar.gz: b18b4f962b6d949a46f49e3b5fbfde4e766ffbd92444964edf8eab46913c644c82bfc5d8b8c7965fbcd74b59bbd3de281dccf45f0a82d946c3264b5dd6fa7533
data/lib/fagin.rb ADDED
@@ -0,0 +1,35 @@
1
+ require "pathname"
2
+
3
+ class Fagin
4
+ def self.find_children(parent, dir)
5
+ children = Hash.new
6
+ path = Pathname.new(dir).expand_path
7
+
8
+ Dir["#{path}/*.rb"].each do |file|
9
+ require_relative file
10
+
11
+ %x(
12
+ \grep -E "^class .+ \< #{parent}" #{file} | \
13
+ awk '{print $2}'
14
+ ).each_line do |clas|
15
+ next if (clas.nil?)
16
+ clas.strip!
17
+ next if (clas.nil?)
18
+
19
+ child = nil
20
+ begin
21
+ child = clas.split("::").inject(Object) do |m, c|
22
+ m.const_get(c)
23
+ end.new
24
+ rescue NameError => e
25
+ raise Error::UnknownChildClassError.new(clas)
26
+ end
27
+ children[clas] = child if (child)
28
+ end
29
+ end
30
+
31
+ return children
32
+ end
33
+ end
34
+
35
+ require "fagin/error"
@@ -0,0 +1,4 @@
1
+ class Fagin::Error < RuntimeError
2
+ end
3
+
4
+ require "fagin/error/unknown_child_class_error"
@@ -0,0 +1,7 @@
1
+ require "fagin/error.rb"
2
+
3
+ class Fagin::Error::UnknownChildClassError < Fagin::Error
4
+ def initialize(clas = "")
5
+ super("Unknown child class #{clas}!")
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,47 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fagin
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Miles Whittaker
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-11-06 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Dynamically load children classes for a specified parent class from a
14
+ specified directory.
15
+ email: mjwhitta@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/fagin.rb
21
+ - lib/fagin/error.rb
22
+ - lib/fagin/error/unknown_child_class_error.rb
23
+ homepage: http://mjwhitta.github.io/fagin
24
+ licenses:
25
+ - GPL-3.0
26
+ metadata: {}
27
+ post_install_message:
28
+ rdoc_options: []
29
+ require_paths:
30
+ - lib
31
+ required_ruby_version: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ required_rubygems_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ requirements: []
42
+ rubyforge_project:
43
+ rubygems_version: 2.4.5.1
44
+ signing_key:
45
+ specification_version: 4
46
+ summary: Dynamically load children classes
47
+ test_files: []