conventional_extensions 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/conventional_extensions/loader.rb +11 -9
- data/lib/conventional_extensions/version.rb +1 -1
- data/lib/conventional_extensions.rb +6 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 10071e280679d17703caf2d303edbe063cd04f8899ebc40a990412f23465fe31
|
4
|
+
data.tar.gz: c2aca1a4cb4536d2b14e454aaca6b26c3c90c70e67b5ed59e4fe533ae9901d74
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: de54d07c7645e960afad9ea1c23925135fa2884e0af195ec201cba7fdfe4dd66e79c1a7542d6a8db5664e0227c6b3ec3e0f201db2377bb4035610d57a66e5ea1
|
7
|
+
data.tar.gz: e2f06c3aefedb9d7f0fe0338876d15a4b1030c7f3bf9ab3a683bf3b11ad7c066eed8fbeca57eab5bfb47a0bbaa2c0fbd775a69f4fc44df32077cd0e02f6f928c
|
data/Gemfile.lock
CHANGED
@@ -1,9 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "set"
|
4
|
+
|
3
5
|
class ConventionalExtensions::Loader
|
4
6
|
def initialize(klass, path)
|
5
7
|
@klass, @name = klass, klass.name
|
6
|
-
@directory_name = File.join path.
|
8
|
+
@directory_name = File.join path.chomp(".rb"), "extensions/"
|
9
|
+
|
10
|
+
@loaded = Set.new
|
7
11
|
end
|
8
12
|
|
9
13
|
def load(*extensions)
|
@@ -21,14 +25,12 @@ class ConventionalExtensions::Loader
|
|
21
25
|
end
|
22
26
|
|
23
27
|
def load_one(extension)
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
$LOADED_FEATURES << extension
|
31
|
-
@klass.class_eval contents, extension, 0
|
28
|
+
if @loaded.add?(extension)
|
29
|
+
if contents = File.read(extension) and contents.match?(/\s*class #{@name}/)
|
30
|
+
::Kernel.load extension
|
31
|
+
else
|
32
|
+
@klass.class_eval contents, extension, 0
|
33
|
+
end
|
32
34
|
end
|
33
35
|
end
|
34
36
|
end
|
@@ -6,7 +6,12 @@ module ConventionalExtensions
|
|
6
6
|
Object.extend self # We're enriching object itself, so any object can call `load_extensions`.
|
7
7
|
|
8
8
|
def load_extensions(*extensions)
|
9
|
-
|
9
|
+
loader_defined_before_entrance = defined?(@loader)
|
10
|
+
|
11
|
+
@loader ||= Loader.new(self, caller_locations(1, 1).first.path)
|
12
|
+
@loader.load(*extensions)
|
13
|
+
ensure
|
14
|
+
@loader = nil unless loader_defined_before_entrance
|
10
15
|
end
|
11
16
|
alias load_extension load_extensions
|
12
17
|
|