maybe_client 1.1.2 → 1.2

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/maybe_client.rb +16 -6
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c41e9a00cc7897a59c9bce1373ee33ba4b7d52b5
4
- data.tar.gz: 423dc9007bb5c50459eabe16fb1e43b49832834f
3
+ metadata.gz: 4de8ef0b57f0b513d1864406a35f9acd709d8ce0
4
+ data.tar.gz: 88928a37c7299adee47b324de61fcfbcb395b06c
5
5
  SHA512:
6
- metadata.gz: 3301501ee83eb134fab9c4796d453cdffa83ac6a82821e143f704743e51b957bbbfcfec77f8de04f0396b694e65de3bba49147fb33dd88b5796566e1c61be8aa
7
- data.tar.gz: 7d22883a3f1c565765ca6685c84a990851143de8051ebad17c8dfa6b4c2925603de149e5c6b12c03e8b3935ba4e3b79f78e43a3072e4a2701de3238723f8e7bb
6
+ metadata.gz: 8255d97b3dd445d8d10e484c38f6f450391345ffebcf592e830d3296cba7464d0d6288420a737ad5a06de63bb55c893ee59d648e914d23d07099a37b485e4af8
7
+ data.tar.gz: 1aba696735ab9e9d5c20792719e3667c1c3524c5ce9e7c22dcd5af01511e92b6b9faed9c9afdecd327a9ffc2d8ab635be73368d86c9eae0e7bdb8074d9aa1603
data/lib/maybe_client.rb CHANGED
@@ -2,14 +2,12 @@ class MaybeClient
2
2
  DELAY = 60
3
3
 
4
4
  def initialize(client: nil, client_class: nil, connect_params: nil)
5
- raise ArgumentError.new('Either client or client_class has to be supplied') \
6
- if !client && !client_class
7
-
8
5
  @client = client
9
6
  @connect_params = connect_params
10
7
  @client_class = client_class
8
+ @should_initialize = !!@client_class
11
9
 
12
- initialize_client unless @client
10
+ initialize_client if client_initialization_needed?
13
11
  end
14
12
 
15
13
  def respond_to? method
@@ -19,8 +17,8 @@ class MaybeClient
19
17
  # Used to delegate everything to @client
20
18
  def method_missing(method, *args, &block)
21
19
  return if noop?
22
- initialize_client unless @client
23
- return if noop?
20
+ initialize_client if client_initialization_needed?
21
+ return if in_delay?
24
22
 
25
23
  # Raises NoMethodError
26
24
  super unless @client.respond_to? method
@@ -39,6 +37,14 @@ class MaybeClient
39
37
 
40
38
  private
41
39
  def noop?
40
+ no_client? || in_delay?
41
+ end
42
+
43
+ def no_client?
44
+ !@client && !@should_initialize
45
+ end
46
+
47
+ def in_delay?
42
48
  @fail_at && @fail_at + DELAY > Time.now
43
49
  end
44
50
 
@@ -50,6 +56,10 @@ class MaybeClient
50
56
  exception_handler(e)
51
57
  end
52
58
 
59
+ def client_initialization_needed?
60
+ !@client && @should_initialize
61
+ end
62
+
53
63
  def initialize_client
54
64
  begin
55
65
  @client = @client_class.new(@connect_params)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: maybe_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: '1.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Renra Gloser