multiconnect 0.1.6 → 0.1.7
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.
- checksums.yaml +4 -4
 - data/lib/multiconnect.rb +1 -0
 - data/lib/multiconnect/connectable.rb +2 -2
 - data/lib/multiconnect/connection/base.rb +15 -4
 - data/lib/multiconnect/error.rb +1 -1
 - data/lib/multiconnect/error/{unsuccessful_request_error.rb → unsuccessful_request.rb} +1 -1
 - data/lib/multiconnect/version.rb +1 -1
 - metadata +3 -3
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 333b43e952689988a4e0d2cdd741ae0bd70527f5
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 374ee1846bc9181dfb572c14eca7fe50e73d98f2
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 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 
     | 
| 
      
 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:: 
     | 
| 
      
 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 
     | 
| 
      
 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  
     | 
| 
       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
         
     | 
    
        data/lib/multiconnect/error.rb
    CHANGED
    
    
    
        data/lib/multiconnect/version.rb
    CHANGED
    
    
    
        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. 
     | 
| 
      
 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- 
     | 
| 
      
 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/ 
     | 
| 
      
 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
         
     |