modules 1.0.0 → 1.1.0

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.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/bin/modules +1 -1
  3. data/lib/interop.rb +7 -5
  4. data/lib/loader.rb +10 -4
  5. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7b24e09537c06c0166b2007e16a4ef95b349022d
4
- data.tar.gz: 4e9a764a755f36c527609b5038df6049a7e3c3f4
3
+ metadata.gz: f8b3e8df22cfbaf45a2aaca8d2a27f2f1408a962
4
+ data.tar.gz: 43bb05d97bf467b1723ff1f9afc36da59a373b7d
5
5
  SHA512:
6
- metadata.gz: 38c1e2d62347f91e6097f48c927f8ce48f818d22ea3621bd91aa87759c95695a79050182a683e266b45910426c5142c77ddf8253edfd7c93e5cdaaae52c6b181
7
- data.tar.gz: 32d64a48a41ec2f125255ead2d6e2c8e3de9ebe266aebbd508d3d718ea8d7ab3dd6a384fa005d737c484a3b8f7078c44a0752ee5ca6e14ce7469681b63626dc1
6
+ metadata.gz: 61ae2e1246455ba92b6ea0762b81d8b861eb0337e26a5c2beba6ab321e5c08bf02609d680cdcb0f92d1c5241d318f3ec8dfdb605c8c241f82f841e8bc045cfc9
7
+ data.tar.gz: 622e7875c5c4733b785508bee20bc6c0d0fedd20f822096b86b6e86b0355999fe0feb8ccca625f4a5d716a853ff31ed9d1b75a83cc5c08df5d1f6e15bbeac9df
@@ -16,7 +16,7 @@ def main
16
16
  end
17
17
 
18
18
  opts.on('-v', '--version') do
19
- puts '0.1.1'
19
+ puts '1.1.0'
20
20
  exit
21
21
  end
22
22
  end
@@ -8,7 +8,7 @@ module Interop
8
8
  # (Hash) map from module identifier to resolved module
9
9
  @cache = {}
10
10
 
11
- def self.import(id)
11
+ def self.import(id, opts={})
12
12
  if @cache.include?(id)
13
13
  DEBUG.call "Cache hit #{id}"
14
14
  return @cache[id]
@@ -17,14 +17,16 @@ module Interop
17
17
  DEBUG.call "Load #{id}"
18
18
  snapshot = Module.constants
19
19
  require id
20
- cleanly_load(Module.constants - snapshot)
20
+ cleanly_load(Module.constants - snapshot, opts)
21
21
  end
22
22
 
23
- def self.cleanly_load(targets)
23
+ def self.cleanly_load(targets, opts)
24
24
  DEBUG.call "Package definitions #{targets}"
25
25
  result = wrap_constants(targets)
26
- result.each_pair do |key, value|
27
- Object.send(:remove_const, key.to_sym) unless key.include?('::')
26
+ if !opts[:save_the_environment]
27
+ result.each_pair do |key, value|
28
+ Object.send(:remove_const, key.to_sym) unless key.include?('::')
29
+ end
28
30
  end
29
31
 
30
32
  result
@@ -13,6 +13,9 @@ module Loader
13
13
  # (String) path to the file currently being loaded
14
14
  @path = nil
15
15
 
16
+ # (Boolean) whether to purge constants added to global namespace on interop load
17
+ @save_the_environment = false
18
+
16
19
  def self.export(value)
17
20
  if @cache.include?(@path) && value.class == Hash
18
21
  # Special handling to enable multiple exports
@@ -24,7 +27,7 @@ module Loader
24
27
 
25
28
  def self.import(id, type=nil)
26
29
  if type == 'interop'
27
- return Interop.import(id)
30
+ return Interop.import(id, save_the_environment: @save_the_environment)
28
31
  end
29
32
 
30
33
  prev = @path
@@ -54,7 +57,7 @@ module Loader
54
57
  result = @cache[@path]
55
58
  else
56
59
  # Failover to external load.
57
- result = Interop.import(id)
60
+ result = Interop.import(id, save_the_environment: @save_the_environment)
58
61
  end
59
62
 
60
63
  @path = prev
@@ -77,8 +80,11 @@ module Loader
77
80
  end
78
81
 
79
82
  def self.config(opts)
80
- if opts.include?(:basepath)
81
- Loader.instance_variable_set :@basepath, opts[:basepath]
83
+ [
84
+ :basepath,
85
+ :save_the_environment,
86
+ ].each do |opt|
87
+ Loader.instance_variable_set("@#{opt}", opts[opt]) if opts.include?(opt)
82
88
  end
83
89
  end
84
90
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: modules
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gareth (Ari) Aye
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-26 00:00:00.000000000 Z
11
+ date: 2017-01-27 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A Ruby module loader inspired by the semantics of js modules
14
14
  email: gareth@alumni.middlebury.edu