multiconnect 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 982d7e46c526c7ecaf2cc6338cfc132d21708500
4
- data.tar.gz: 173e9f83db38b1eeab4ae87323395116bf4618e5
3
+ metadata.gz: 333b43e952689988a4e0d2cdd741ae0bd70527f5
4
+ data.tar.gz: 374ee1846bc9181dfb572c14eca7fe50e73d98f2
5
5
  SHA512:
6
- metadata.gz: 08c24753cfb9b98c271d8c7195717d6e4b33fc1e1cf60c52c06f30075d409806e164747e3c4669ef3dca965ecb0b2aea6d8ebdd2f936546b5161a23941315c71
7
- data.tar.gz: 37b42b22474463876f4f98c3b34ce137e7f1aa0c58585d4e1d6cebcca4dfc5bcb4cfe79c45f7c22c5a297460988fbe2301e1086e9db8192f2a1327164fa4d81e
6
+ metadata.gz: bad26cf1719c35130ceee33b1b8d204ca355e5e1d441dadfe217ea76615f63db4eef23b4622da016529015efb0077490333dd0e15fe458527e838534d065cdb0
7
+ data.tar.gz: 2f57e806733e7f5ff31d95b425f33fa11df56d72ee0ad41f36050a841ecd33626d31f1050b2671392b3963aaf62e90d53cc578bae6e7e3f1990ce876fb257959
data/lib/multiconnect.rb CHANGED
@@ -3,6 +3,7 @@ require 'active_support'
3
3
  require 'active_support/concern'
4
4
  require 'active_support/core_ext/class/attribute'
5
5
  require 'active_support/core_ext/module/delegation'
6
+ require 'active_support/core_ext/object/blank'
6
7
 
7
8
  module Multiconnect
8
9
  autoload :Connection, 'multiconnect/connection'
@@ -15,13 +15,13 @@ module Multiconnect
15
15
  self._connections = [connection_class.new(options)] + _connections
16
16
  end
17
17
 
18
- def request(action, *args, &default)
18
+ def request(action, *args)
19
19
  self._connections.each do |connection|
20
20
  result = connection.execute(action, *args)
21
21
  return result if result.success?
22
22
  end
23
23
 
24
- raise Multiconnect::Error::UnsuccessfulRequestError.new( class: self, action: action )
24
+ raise Multiconnect::Error::UnsuccessfulRequest.new( class: self, action: action )
25
25
  end
26
26
  end
27
27
  end
@@ -6,7 +6,8 @@ module Multiconnect
6
6
 
7
7
  def initialize(options = {})
8
8
  self.client = options.fetch :client, nil
9
- @except = Array(options.fetch :except, [])
9
+ @except = Array(options.fetch :except, []).map(&:to_sym)
10
+ @only = Array(options.fetch :only, []).map(&:to_sym)
10
11
  end
11
12
 
12
13
  def request(action, *args)
@@ -18,16 +19,26 @@ module Multiconnect
18
19
  end
19
20
 
20
21
  def execute(action, *args)
21
- if @except.include? action
22
- Result.new
23
- else
22
+ if allowed?(action)
24
23
  Result.new status: Result::SUCCESS, data: request(action, *args), connection: self.class
24
+ else
25
+ Result.new
25
26
  end
26
27
 
27
28
  rescue => e
28
29
  report_error(e)
29
30
  Result.new
30
31
  end
32
+
33
+ private
34
+
35
+ def allowed?(action)
36
+ action = action.to_sym
37
+ allowed_by_only = @only.blank? || ( @only.present? && @only.include?( action ) )
38
+ allowed_by_except = !@except.include?(action)
39
+
40
+ allowed_by_only && allowed_by_except
41
+ end
31
42
  end
32
43
  end
33
44
  end
@@ -1,5 +1,5 @@
1
1
  module Multiconnect
2
2
  module Error
3
- autoload :UnsuccessfulRequestError, 'multiconnect/error/unsuccessful_request_error'
3
+ autoload :UnsuccessfulRequest, 'multiconnect/error/unsuccessful_request'
4
4
  end
5
5
  end
@@ -1,6 +1,6 @@
1
1
  module Multiconnect
2
2
  module Error
3
- class UnsuccessfulRequestError < StandardError
3
+ class UnsuccessfulRequest < StandardError
4
4
  def initialize(opts = {})
5
5
  @class = opts.fetch :class, nil
6
6
  @action = opts.fetch :action, nil
@@ -1,3 +1,3 @@
1
1
  module Multiconnect
2
- VERSION = "0.1.6"
2
+ VERSION = "0.1.7"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: multiconnect
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Greg Orlov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-03-24 00:00:00.000000000 Z
11
+ date: 2016-03-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -116,7 +116,7 @@ files:
116
116
  - lib/multiconnect/connection/base.rb
117
117
  - lib/multiconnect/connection/result.rb
118
118
  - lib/multiconnect/error.rb
119
- - lib/multiconnect/error/unsuccessful_request_error.rb
119
+ - lib/multiconnect/error/unsuccessful_request.rb
120
120
  - lib/multiconnect/version.rb
121
121
  - multiconnect.gemspec
122
122
  homepage: https://github.com/gaorlov/multiconnect