context_manager 1.0.0 → 1.0.1

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 (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/context_manager.rb +12 -5
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 218b8bb99a2ee8ad8d4fb1ae717500e616ce786925076a7b247b9eb6ebf97e6a
4
- data.tar.gz: ad418f6035243b0027f047b3a9d047420c64c4fbbc563b02eef24cbf458230ab
3
+ metadata.gz: 6c949e0399005d589108228f53c12555544354c15771ca99e95bc1df61fc0aaf
4
+ data.tar.gz: f5fea88f815233f4892b5cb99f0db01679fd00be69c0ac16ad77bdc569a74509
5
5
  SHA512:
6
- metadata.gz: eb7e9b8b02d03e24556dc1633eca40f20b3a059fb7dc7f8353c314d9599bff6a46c8775f182f86328da4832e9aff5c2564008999a3439f4749ebbc2c5ae45911
7
- data.tar.gz: 96ba1db6680455ebb3f8d0244233b3e93cc074c7a580532c8fab307a2c9d252e85dcfd2e008fd0ca5d150cce178313a18ccfea97c4c744283fb62ce7fbcc4e96
6
+ metadata.gz: fe990bfea33a17ee136885098ace0566ec07473b372d6ed211c04ad495171678ad95450a89904708f1fdefe5a9784877808d6a6659e0496f12196c40ae7ef20e
7
+ data.tar.gz: 271ab248e96eee551bcf66c2994cc85f38712d206d22e0c04bf714e9fdb487efe3cc82319db0411fb0f56be4e0b85d806bbf46044573b5b06629a4587a590d94
@@ -1,12 +1,19 @@
1
+ class ContextNotFound < StandardError; end
2
+
1
3
  def finish(&block)
2
- Proc.new do |obj|
3
- block.call(obj)
4
- end
4
+ Proc.new { |obj| block.call(obj) }
5
5
  end
6
6
 
7
7
  def with(*args)
8
- arg = args[0]
9
- yield_obj = arg[0]
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.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-27 00:00:00.000000000 Z
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.