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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7ae73a75b482203013f89eb32515cd611d1b198b8cedeba8681032185bf5f51a
4
- data.tar.gz: 6952f8616ad0e94edab0822888d02fd881468110d0d0546ba5117ab5ec1a6d27
3
+ metadata.gz: 10071e280679d17703caf2d303edbe063cd04f8899ebc40a990412f23465fe31
4
+ data.tar.gz: c2aca1a4cb4536d2b14e454aaca6b26c3c90c70e67b5ed59e4fe533ae9901d74
5
5
  SHA512:
6
- metadata.gz: 9d1afc244d40c11bb184d0bbed288eac9f2f134d64e0a3957b5f7d08b69892914ba32e764c643d89c3612256e90d74888a8b31a00ad6ec48ff62068ed9f5a4c6
7
- data.tar.gz: 22b5807a59e13c7a61bc7bebd6b91e7fac3617e2f3dc61d5119435c78a7a47eafc7540f46c00ca0b616f2f0151cce06300112b9df92e489b9481e9b65b874070
6
+ metadata.gz: de54d07c7645e960afad9ea1c23925135fa2884e0af195ec201cba7fdfe4dd66e79c1a7542d6a8db5664e0227c6b3ec3e0f201db2377bb4035610d57a66e5ea1
7
+ data.tar.gz: e2f06c3aefedb9d7f0fe0338876d15a4b1030c7f3bf9ab3a683bf3b11ad7c066eed8fbeca57eab5bfb47a0bbaa2c0fbd775a69f4fc44df32077cd0e02f6f928c
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- conventional_extensions (0.1.0)
4
+ conventional_extensions (0.2.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -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.match(/(?=\/extensions|\.rb)/).pre_match, "extensions/"
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
- contents = File.read extension
25
-
26
- case
27
- when contents.match?(/\s*class #{@name}/)
28
- require extension
29
- when !$LOADED_FEATURES.include?(extension)
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ConventionalExtensions
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  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
- Loader.new(self, caller_locations(1, 1).first.path).load(*extensions)
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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: conventional_extensions
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kasper Timm Hansen