context_manager 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/context_manager.rb +34 -0
- metadata +44 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 55124e68bf23d48b84945c4c0abaf29d8e1d23f865026556d777a2e3f5211ac6
|
4
|
+
data.tar.gz: 856971ffcc251efac451f0c9f4543013a230e159da619cb48793cf5ac5225f00
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2822c7dc69407d58f0fba4ed9b84841d862419554c45dd1611a9ede5638d99b510936a3996b96e6515164bf9d50d18440a3227f1f058e6de09002def0fcb65f1
|
7
|
+
data.tar.gz: e690502a61324cec2716cdf4d6b6d2683e4f9f4b0e9bb5caa46b329f08cca2f222603893ca5645dd87569680dd71d4ffe2240cb72c4746cf966d26685d344ad4
|
@@ -0,0 +1,34 @@
|
|
1
|
+
def after(&block)
|
2
|
+
Proc.new do |obj|
|
3
|
+
block.call(obj)
|
4
|
+
end
|
5
|
+
end
|
6
|
+
|
7
|
+
def with(*args)
|
8
|
+
arg = args[0]
|
9
|
+
yield_obj = arg[0]
|
10
|
+
begin
|
11
|
+
yield yield_obj
|
12
|
+
ensure
|
13
|
+
arg[1].call(yield_obj)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# # sample context manager
|
18
|
+
# def ctxmgr(filename)
|
19
|
+
# p "opening file.."
|
20
|
+
# f = File.open(filename)
|
21
|
+
# close_file = after do |file|
|
22
|
+
# p "closing a file.. #{file}"
|
23
|
+
# file.close
|
24
|
+
# end
|
25
|
+
|
26
|
+
# [f, close_file]
|
27
|
+
# end
|
28
|
+
|
29
|
+
# # usage
|
30
|
+
# with ctxmgr('filename.txt') do |e|
|
31
|
+
# p "file: #{e.read}"
|
32
|
+
# # p 'trying to read file, uh oh an exception occured'
|
33
|
+
# # raise 'akash'
|
34
|
+
# end
|
metadata
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: context_manager
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Akash Gupta
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-06-27 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Python like context manger in Ruby
|
14
|
+
email: akashsjhs@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/context_manager.rb
|
20
|
+
homepage: https://rubygems.org/gems/context_manager
|
21
|
+
licenses:
|
22
|
+
- MIT
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubyforge_project:
|
40
|
+
rubygems_version: 2.7.6
|
41
|
+
signing_key:
|
42
|
+
specification_version: 4
|
43
|
+
summary: Python like context manger in Ruby
|
44
|
+
test_files: []
|