Browse code

Trieda na nacitavanie modulov, testovaci modul

Cinan Rakosnik authored on 15/12/2012 at 00:54:36
Showing 7 changed files
... ...
@@ -1,5 +1,21 @@
1 1
 require_relative "rubysermon/version"
2
+require_relative "rubysermon/mod_loader"
3
+require_relative "rubysermon/mod_template"
2 4
 
3 5
 module Rubysermon
4
-  # Your code goes here...
6
+	class App
7
+
8
+		def initialize
9
+
10
+		end
11
+
12
+		private
13
+		def load_mod(mod_name)
14
+			begin
15
+				@loader = ModLoader.load mod_name
16
+			rescue ModLoaderException => e
17
+				$stderr = e.message
18
+			end
19
+		end
20
+	end
5 21
 end
6 22
new file mode 100644
... ...
@@ -0,0 +1,5 @@
0
+module Rubysermon
1
+	class Cpu < ModTemplate
2
+
3
+	end
4
+end
0 5
\ No newline at end of file
1 6
new file mode 100644
... ...
@@ -0,0 +1,18 @@
0
+module Rubysermon
1
+	class ModLoader
2
+
3
+		def self.load(new_class)
4
+			begin
5
+				require_relative 'mod/' + new_class.downcase
6
+
7
+				capitalized_class = new_class.capitalize
8
+				return (Rubysermon.const_get capitalized_class).new
9
+			rescue LoadError
10
+				raise ModLoaderException, "File module not found"
11
+			end
12
+		end
13
+
14
+	end
15
+
16
+	class ModLoaderException < Exception; end
17
+end
0 18
\ No newline at end of file
1 19
new file mode 100644
... ...
@@ -0,0 +1,7 @@
0
+module Rubysermon
1
+	class ModTemplate
2
+
3
+	end
4
+
5
+	class ModTemplateException < Exception; end
6
+end
0 7
\ No newline at end of file
1 8
new file mode 100644
... ...
@@ -0,0 +1,17 @@
0
+require_relative '../../test_helper.rb'
1
+
2
+class ModLoader_test < MiniTest::Unit::TestCase
3
+
4
+	def test_load_non_existing_file
5
+		assert_raises(Rubysermon::ModLoaderException) do
6
+			Rubysermon::ModLoader.load '_what_the_fuck_'
7
+		end
8
+	end
9
+
10
+	def test_load_existing_file
11
+		possible_mods = %w(cpu Cpu CPU)
12
+		possible_mods.each do |mod|
13
+			assert_equal((Rubysermon::ModLoader.load mod).class.to_s, 'Rubysermon::Cpu')
14
+		end
15
+	end
16
+end
0 17
\ No newline at end of file
1 18
new file mode 100644
... ...
@@ -0,0 +1,5 @@
0
+require_relative '../../test_helper.rb'
1
+
2
+class ModTemplate_test < MiniTest::Unit::TestCase
3
+
4
+end
0 5
\ No newline at end of file
1 6
new file mode 100644
... ...
@@ -0,0 +1,5 @@
0
+require_relative 'test_helper.rb'
1
+
2
+class Rubysermon_test < MiniTest::Unit::TestCase
3
+
4
+end
0 5
\ No newline at end of file