Class: MPT::Wrap
Defined Under Namespace
Classes: Blank
Constant Summary collapse
- @@wrap_variables =
{}
- @@registry =
{}
Class Method Summary collapse
- .get(wrap_name, default = nil) ⇒ Object
- .get_from_registry(key) ⇒ Object
- .register(value) ⇒ Object
- .with(var = {}, &block) ⇒ Object
Class Method Details
.get(wrap_name, default = nil) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/wrap.rb', line 16 def get(wrap_name, default = nil) temp = @@wrap_variables[Thread.current.object_id] res = nil if !temp.blank? res = temp[wrap_name] unless temp[wrap_name].nil? end if res.nil? && !default.nil? res = default if default.instance_of?( Proc ) res = default.call end end res end |
.get_from_registry(key) ⇒ Object
42 43 44 |
# File 'lib/wrap.rb', line 42 def get_from_registry(key) @@registry[key] end |
.register(value) ⇒ Object
35 36 37 38 39 40 |
# File 'lib/wrap.rb', line 35 def register(value) @@uuid_generator ||= UUID.new key = @@uuid_generator.generate(:urn).to_s @@registry[key] = value key end |
.with(var = {}, &block) ⇒ Object
7 8 9 10 11 12 13 14 |
# File 'lib/wrap.rb', line 7 def with(var ={}, &block) thread_id = Thread.current.object_id @@wrap_variables[thread_id]||={} temp = @@wrap_variables[thread_id].dup @@wrap_variables[thread_id].merge!(var) yield @@wrap_variables[thread_id] = temp end |