io_request 1.2.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,29 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- io_request (1.2.0)
5
- json (~> 2.0)
6
- logger (~> 1.4)
7
- timeout-extensions (~> 0.1.1)
8
-
9
- GEM
10
- remote: https://rubygems.org/
11
- specs:
12
- json (2.3.0)
13
- logger (1.4.1)
14
- minitest (5.13.0)
15
- rake (13.0.1)
16
- timeout-extensions (0.1.1)
17
-
18
- PLATFORMS
19
- ruby
20
- x64-mingw32
21
-
22
- DEPENDENCIES
23
- bundler (~> 2.0)
24
- io_request!
25
- minitest (~> 5.0)
26
- rake (~> 13.0)
27
-
28
- BUNDLED WITH
29
- 2.0.2
@@ -1,49 +0,0 @@
1
- require "logger"
2
-
3
- module IORequest
4
- # @!group Logger
5
-
6
- # Default logger.
7
- @@logger = Logger.new($LOG_FILE || STDOUT,
8
- formatter: Proc.new do |severity, datetime, progname, msg|
9
- "[#{datetime}] #{severity} - #{progname}:\t #{msg}\n"
10
- end
11
- )
12
- @@logger.level = $DEBUG ? Logger::DEBUG : Logger::INFO
13
-
14
- # Setup new logger.
15
- #
16
- # @param logger [Logger, nil]
17
- def self.logger=(logger)
18
- @@logger = logger
19
- end
20
-
21
- # Access current logger.
22
- #
23
- # @return [Logger, nil]
24
- def self.logger
25
- @@logger
26
- end
27
-
28
- # Log message.
29
- def self.log(severity, message = nil, progname = nil)
30
- @@logger.log(severity, message, progname) if @@logger
31
- end
32
-
33
- # Log warning message.
34
- def self.warn(message = nil, progname = nil)
35
- @@logger.log(Logger::WARN, message, progname)
36
- end
37
-
38
- # Log info message.
39
- def self.info(message = nil, progname = nil)
40
- @@logger.log(Logger::INFO, message, progname)
41
- end
42
-
43
- # Log debug message.
44
- def self.debug(message = nil, progname = nil)
45
- @@logger.log(Logger::DEBUG, message, progname)
46
- end
47
-
48
- # @!endgroup
49
- end
@@ -1,104 +0,0 @@
1
- module IORequest
2
- # Utility methods.
3
- module Utility
4
- # Adds special method to identify object in log files.
5
- module WithProgName
6
- ##
7
- # Identifies object and thread it runs in.
8
- def prog_name
9
- self_class = self.class
10
- "#{self_class.name}##{object_id} in Thread##{Thread.current.object_id}"
11
- end
12
- end
13
-
14
- # Adds some methods to spawn new threads and join them.
15
- #
16
- # @note This module creates instance variables with prefix +@_MultiThread_+.
17
- module MultiThread
18
- private
19
-
20
- # @return [Array<Thread>] array of running threads
21
- def running_threads
22
- @_MultiThread_threads ||= []
23
- end
24
-
25
- # Runs block with provided arguments forwarded as arguments in separate thread.
26
- #
27
- # All the inline args will be passed to block.
28
- #
29
- # @param thread_name [String] thread name.
30
- #
31
- # @return [Thread]
32
- def in_thread(*args, name: nil, &block)
33
- @_MultiThread_threads ||= []
34
- @_MultiThread_mutex ||= Mutex.new
35
- # Synchronizing addition/deletion of new threads. That's important
36
- @_MultiThread_mutex.synchronize do
37
- new_thread = Thread.new(*args) do |*in_args|
38
- begin
39
- block.call(*in_args)
40
- ensure
41
- @_MultiThread_mutex.synchronize do
42
- @_MultiThread_threads.delete(Thread.current)
43
- end
44
- end
45
- end
46
- @_MultiThread_threads << new_thread
47
- new_thread.name = name if name
48
- new_thread
49
- end
50
- end
51
-
52
- # For each running thread.
53
- def each_thread(&block)
54
- @_MultiThread_threads ||= []
55
-
56
- @_MultiThread_threads.each(&block)
57
- end
58
-
59
- # Kills each thread.
60
- def kill_threads
61
- each_thread(&:kill)
62
- each_thread(&:join)
63
- end
64
-
65
- # Joins each thread.
66
- def join_threads
67
- each_thread(&:join)
68
- end
69
- end
70
- end
71
- end
72
-
73
- # Extending Hash class.
74
- class Hash
75
- # Use this on JSON objects to turn all the +String+ keys of hash to symbols.
76
- #
77
- # @param depth [Integer] maximum amount of hashes to handle. This is just a
78
- # simple way to protect from infinite loop.
79
- #
80
- # @return [self]
81
- def symbolize_keys!(depth = 1000)
82
- queue = [self]
83
- count = 0
84
- while h = queue.shift
85
- h.transform_keys! { |key| key.is_a?(String) ? key.to_sym : key }
86
- h.each_value { |v| queue.push(v) if v.is_a?(Hash) }
87
- count += 1
88
- break if count >= depth
89
- end
90
- self
91
- end
92
-
93
- # Whether provided hash is included into this one.
94
- #
95
- # @param other [Hash]
96
- #
97
- # @return [Boolean]
98
- def contains?(other)
99
- other.keys.all? do |key|
100
- other[key] == self[key]
101
- end
102
- end
103
- end
104
-