hyperloop-config 0.9.4 → 0.9.5
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/hyperloop-config.gemspec +1 -1
- data/lib/hyperloop-config.rb +2 -0
- data/lib/hyperloop/context.rb +31 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 95068ff66d67af089b732fc44f910fe3663f19f1
|
4
|
+
data.tar.gz: aaabff976a2d6a97edda22f99700d38568f49ba1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c8dfac20f0ae09fff156473d905e26b15f41c88fae4cde3a304d9f8187e83d866389f73c7484ec58b4f827efea657f104852a21adcd66b695513ec2a17a9ddad
|
7
|
+
data.tar.gz: 98185f221412cb3ee91b02f0659ae28f68a492596753243df95451a9e641956f989c41bc923d4b0b107e596a13f63cbd3c75051ca8d7f34be409bc241196d943
|
data/hyperloop-config.gemspec
CHANGED
data/lib/hyperloop-config.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
if RUBY_ENGINE == 'opal'
|
2
2
|
require 'hyperloop/client_stubs'
|
3
|
+
require 'hyperloop/context'
|
3
4
|
require 'hyperloop/on_client'
|
4
5
|
else
|
5
6
|
require 'opal'
|
6
7
|
require 'hyperloop/config_settings'
|
8
|
+
require 'hyperloop/context'
|
7
9
|
require 'hyperloop/imports'
|
8
10
|
require 'hyperloop/client_readers'
|
9
11
|
require 'hyperloop/on_client'
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Hyperloop
|
2
|
+
# Allows interactive systems to reset context to the state at boot. Any
|
3
|
+
# modules or classes that set context instance variables to hold things like
|
4
|
+
# call backs should use Hyperloop::Context.set_var(self, :@var_name) { .... }
|
5
|
+
# the provided block will be rerun and the instance variable re-initialized
|
6
|
+
# when the reset! method is called
|
7
|
+
module Context
|
8
|
+
# pass self, an instance var name (symbol) and a block
|
9
|
+
# if reset! has been called, then record the var and block for future resets
|
10
|
+
# then if var is currently empty it will be initialized with block
|
11
|
+
def self.set_var(ctx, var, &block)
|
12
|
+
@context_hash[ctx] ||= [var, block] if @context_hash
|
13
|
+
ctx.instance_variable_get(var) || ctx.instance_variable_set(var, yield)
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.reset!(reboot = true)
|
17
|
+
# if @context_hash is already initialized then reset all the instance
|
18
|
+
# vars using their corresponding blocks. Otherwise initialize
|
19
|
+
# @context_hash.
|
20
|
+
if @context_hash
|
21
|
+
@context_hash.each do |context, var_and_block|
|
22
|
+
var, block = var_and_block
|
23
|
+
context.instance_variable_set(var, block.call)
|
24
|
+
end
|
25
|
+
Hyperloop::Application::Boot.run if reboot
|
26
|
+
else
|
27
|
+
@context_hash = {}
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hyperloop-config
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- catmando
|
@@ -199,6 +199,7 @@ files:
|
|
199
199
|
- lib/hyperloop/client_readers.rb
|
200
200
|
- lib/hyperloop/client_stubs.rb
|
201
201
|
- lib/hyperloop/config_settings.rb
|
202
|
+
- lib/hyperloop/context.rb
|
202
203
|
- lib/hyperloop/imports.rb
|
203
204
|
- lib/hyperloop/on_client.rb
|
204
205
|
- lib/hyperloop/rail_tie.rb
|