hyperloop-config 0.9.4 → 0.9.5

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: ffe4b5bd9cc7c465cb1e69c5b0f9b3e75396a2ca
4
- data.tar.gz: b67e50d847850c6461839cfd3837ef72292d45e2
3
+ metadata.gz: 95068ff66d67af089b732fc44f910fe3663f19f1
4
+ data.tar.gz: aaabff976a2d6a97edda22f99700d38568f49ba1
5
5
  SHA512:
6
- metadata.gz: f5a1701f17f8e2abfbc8ccb7b524619742301a92d8b35c42b4dc26aeef7ae78adc3d64f848ac3f820fc3bf61dbaf86d9048bdca76c90586958c706a6372ca723
7
- data.tar.gz: 8082481bafdea6fe5b0562633acd6e00327a5f970e2ff1afb5a7d82fc141327523bca3a2df688dd53260174118bd31ef6a1641fa426e62dc0941011df43c49b2
6
+ metadata.gz: c8dfac20f0ae09fff156473d905e26b15f41c88fae4cde3a304d9f8187e83d866389f73c7484ec58b4f827efea657f104852a21adcd66b695513ec2a17a9ddad
7
+ data.tar.gz: 98185f221412cb3ee91b02f0659ae28f68a492596753243df95451a9e641956f989c41bc923d4b0b107e596a13f63cbd3c75051ca8d7f34be409bc241196d943
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "hyperloop-config"
7
- spec.version = "0.9.4"
7
+ spec.version = "0.9.5"
8
8
  spec.authors = ["catmando"]
9
9
  spec.email = ["mitch@catprint.com"]
10
10
 
@@ -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
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