logcabin 0.0.1 → 0.0.3
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 +4 -4
- data/README.md +37 -0
- data/lib/logcabin/collection.rb +3 -1
- data/logcabin.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 78dfabf180182de5dd6875e7f2243daf68cbf8b3
|
4
|
+
data.tar.gz: f469c06d8306c37972d634d8e51de37858aca3d0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 46cc8adc143a1323e5f89308fed8e791d2f808030df61d28bf899798ef406965191884e60799fedb895e91bf60aba394b7ff668232797c0ca8e59338c177d5b4
|
7
|
+
data.tar.gz: 526caafd0a0d0ad491a852a0301af625fbd91d3d016e08586fcefa9f73aa6ae997ba2a538229dadf2791fd92c7703faeaa82d7952eecc2b0e7f3c6d102cea3d7
|
data/README.md
CHANGED
@@ -12,6 +12,43 @@ Support dynamic loading of modules at runtime
|
|
12
12
|
|
13
13
|
## Usage
|
14
14
|
|
15
|
+
Create a collection of modules with `collection = LogCabin.new(load_path: '/path/to/modules')`.
|
16
|
+
|
17
|
+
You can also pass in an array of paths as load_path.
|
18
|
+
|
19
|
+
You can then load a module and return it with `collection.find(:module_name)` (you can use a string or symbol for the name).
|
20
|
+
|
21
|
+
Modules should be children of LogCabin::Modules, like so:
|
22
|
+
|
23
|
+
```
|
24
|
+
module LogCabin
|
25
|
+
module Modules
|
26
|
+
module MyDynamicModule
|
27
|
+
def useful_function
|
28
|
+
puts "Hello world"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
```
|
34
|
+
|
35
|
+
This should go in the file "my_dynamic_module.rb", and would be loaded with `collection.find(:my_dynamic_module)`. This naming convention is required for modules, where an underscore in the filename matches with a capitalized letter in the module definition.
|
36
|
+
|
37
|
+
As an example usage, you can use LogCabin to dynamically extend instances of a class:
|
38
|
+
|
39
|
+
```
|
40
|
+
COLLECTION = LogCabin.new(load_path: '/path/to/my/dynamic/module')
|
41
|
+
|
42
|
+
class BoringClass
|
43
|
+
def initialize(cool_module)
|
44
|
+
extend COLLECTION.find(cool_module)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
x = BoringClass.new('my_dynamic_module')
|
49
|
+
x.useful_function >> puts "Hello World"
|
50
|
+
```
|
51
|
+
|
15
52
|
## Installation
|
16
53
|
|
17
54
|
gem install logcabin
|
data/lib/logcabin/collection.rb
CHANGED
@@ -18,6 +18,8 @@ module LogCabin
|
|
18
18
|
require file
|
19
19
|
class_name = parse_class_name(name)
|
20
20
|
@modules[name] = LogCabin::Modules.const_get(class_name)
|
21
|
+
rescue LoadError
|
22
|
+
raise("Error while loading #{name}")
|
21
23
|
end
|
22
24
|
|
23
25
|
private
|
@@ -37,7 +39,7 @@ module LogCabin
|
|
37
39
|
file_path = File.join(dir, "#{name}.rb")
|
38
40
|
return file_path if File.exist? file_path
|
39
41
|
end
|
40
|
-
fail("Module #{
|
42
|
+
fail("Module #{name} not found")
|
41
43
|
end
|
42
44
|
end
|
43
45
|
end
|
data/logcabin.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logcabin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Les Aker
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-12-
|
11
|
+
date: 2015-12-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubocop
|