context_manager 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/context_manager.rb +12 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6c949e0399005d589108228f53c12555544354c15771ca99e95bc1df61fc0aaf
|
4
|
+
data.tar.gz: f5fea88f815233f4892b5cb99f0db01679fd00be69c0ac16ad77bdc569a74509
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fe990bfea33a17ee136885098ace0566ec07473b372d6ed211c04ad495171678ad95450a89904708f1fdefe5a9784877808d6a6659e0496f12196c40ae7ef20e
|
7
|
+
data.tar.gz: 271ab248e96eee551bcf66c2994cc85f38712d206d22e0c04bf714e9fdb487efe3cc82319db0411fb0f56be4e0b85d806bbf46044573b5b06629a4587a590d94
|
data/lib/context_manager.rb
CHANGED
@@ -1,12 +1,19 @@
|
|
1
|
+
class ContextNotFound < StandardError; end
|
2
|
+
|
1
3
|
def finish(&block)
|
2
|
-
Proc.new
|
3
|
-
block.call(obj)
|
4
|
-
end
|
4
|
+
Proc.new { |obj| block.call(obj) }
|
5
5
|
end
|
6
6
|
|
7
7
|
def with(*args)
|
8
|
-
|
9
|
-
|
8
|
+
begin
|
9
|
+
arg = args[0]
|
10
|
+
yield_obj = arg[0]
|
11
|
+
rescue
|
12
|
+
raise ContextNotFound, 'no context found'
|
13
|
+
end
|
14
|
+
|
15
|
+
raise ContextNotFound, 'no context found' if yield_obj.nil?
|
16
|
+
|
10
17
|
begin
|
11
18
|
yield yield_obj
|
12
19
|
ensure
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: context_manager
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Akash Gupta
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-06-
|
11
|
+
date: 2020-06-29 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Python like context manger in Ruby. Context managers allow you to allocate
|
14
14
|
and release resources precisely when you want to.
|