logcabin 0.0.1 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6b2fb63c6e1a668540feb08448fe3cde4543a2ba
4
- data.tar.gz: c1d2b56bd6842d96465bc438fde829e563ae1ea8
3
+ metadata.gz: 78dfabf180182de5dd6875e7f2243daf68cbf8b3
4
+ data.tar.gz: f469c06d8306c37972d634d8e51de37858aca3d0
5
5
  SHA512:
6
- metadata.gz: 4b13f3472d15ce311aa057f0021720507ab9d6f2c5612a35cbd1a2c02836d9f14cace38b19d019cbec450fb533117e500d06a759ff522025be668d3361fc4d1f
7
- data.tar.gz: 3a608885cd6c708fa5c9aead8eeb613559dbe0c7f0116bdf375cc38f1fad5233a0822b92a56c2d775be64070606370107460ab2d37c73badeb2e0902f9c5aa4c
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
@@ -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 #{method} not found")
42
+ fail("Module #{name} not found")
41
43
  end
42
44
  end
43
45
  end
data/logcabin.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'logcabin'
3
- s.version = '0.0.1'
3
+ s.version = '0.0.3'
4
4
  s.date = Time.now.strftime('%Y-%m-%d')
5
5
 
6
6
  s.summary = 'Support dynamic loading of modules at runtime'
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.1
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-27 00:00:00.000000000 Z
11
+ date: 2015-12-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop