parallizer 0.4.1 → 0.4.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.
- data/Gemfile.lock +1 -1
 - data/README.md +24 -4
 - data/lib/parallizer.rb +10 -0
 - data/lib/parallizer/version.rb +1 -1
 - data/spec/parallizer_spec.rb +40 -6
 - metadata +2 -8
 
    
        data/Gemfile.lock
    CHANGED
    
    
    
        data/README.md
    CHANGED
    
    | 
         @@ -122,8 +122,8 @@ require 'net/http' 
     | 
|
| 
       122 
122 
     | 
    
         
             
            require 'parallizer'
         
     | 
| 
       123 
123 
     | 
    
         | 
| 
       124 
124 
     | 
    
         
             
            parallizer = Parallizer.new(Net::HTTP)
         
     | 
| 
       125 
     | 
    
         
            -
            parallizer.add.get('www.google.com', ' 
     | 
| 
       126 
     | 
    
         
            -
            parallizer.add.get('www.google.com', ' 
     | 
| 
      
 125 
     | 
    
         
            +
            parallizer.add.get('www.google.com', '/search?q=foo')
         
     | 
| 
      
 126 
     | 
    
         
            +
            parallizer.add.get('www.google.com', '/search?q=bar')
         
     | 
| 
       127 
127 
     | 
    
         
             
            http_service = parallizer.create_proxy
         
     | 
| 
       128 
128 
     | 
    
         
             
            ```
         
     | 
| 
       129 
129 
     | 
    
         | 
| 
         @@ -146,10 +146,30 @@ require 'net/http' 
     | 
|
| 
       146 
146 
     | 
    
         
             
            require 'parallizer'
         
     | 
| 
       147 
147 
     | 
    
         | 
| 
       148 
148 
     | 
    
         
             
            parallizer = Parallizer.new(Net::HTTP, :retries => 3)
         
     | 
| 
       149 
     | 
    
         
            -
            parallizer.add.get('www.google.com', ' 
     | 
| 
      
 149 
     | 
    
         
            +
            parallizer.add.get('www.google.com', '/search?q=foo')
         
     | 
| 
       150 
150 
     | 
    
         
             
            http_service = parallizer.create_proxy
         
     | 
| 
       151 
151 
     | 
    
         | 
| 
       152 
     | 
    
         
            -
            http_service.get('www.google.com', ' 
     | 
| 
      
 152 
     | 
    
         
            +
            http_service.get('www.google.com', '/search?q=foo') # Will be called up to 4 times
         
     | 
| 
      
 153 
     | 
    
         
            +
            ```
         
     | 
| 
      
 154 
     | 
    
         
            +
             
     | 
| 
      
 155 
     | 
    
         
            +
             
     | 
| 
      
 156 
     | 
    
         
            +
            ### Retrieve all results
         
     | 
| 
      
 157 
     | 
    
         
            +
             
     | 
| 
      
 158 
     | 
    
         
            +
            You can also execute all added methods in parallel and get all the results.
         
     | 
| 
      
 159 
     | 
    
         
            +
             
     | 
| 
      
 160 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 161 
     | 
    
         
            +
            require 'net/http'
         
     | 
| 
      
 162 
     | 
    
         
            +
            require 'parallizer'
         
     | 
| 
      
 163 
     | 
    
         
            +
             
     | 
| 
      
 164 
     | 
    
         
            +
            parallizer = Parallizer.new(Net::HTTP)
         
     | 
| 
      
 165 
     | 
    
         
            +
            parallizer.add.get('www.google.com', '/search?q=foo')
         
     | 
| 
      
 166 
     | 
    
         
            +
            parallizer.add.get('www.google.com', '/search?q=bar')
         
     | 
| 
      
 167 
     | 
    
         
            +
             
     | 
| 
      
 168 
     | 
    
         
            +
            call_results = parallizer.all_call_results
         
     | 
| 
      
 169 
     | 
    
         
            +
            # {
         
     | 
| 
      
 170 
     | 
    
         
            +
            #   [:get, 'www.google.com', '/search?q=foo'] => ...,
         
     | 
| 
      
 171 
     | 
    
         
            +
            #   [:get, 'www.google.com', '/search?q=foo'] => ...
         
     | 
| 
      
 172 
     | 
    
         
            +
            # }
         
     | 
| 
       153 
173 
     | 
    
         
             
            ```
         
     | 
| 
       154 
174 
     | 
    
         | 
| 
       155 
175 
     | 
    
         | 
    
        data/lib/parallizer.rb
    CHANGED
    
    | 
         @@ -69,6 +69,16 @@ class Parallizer 
     | 
|
| 
       69 
69 
     | 
    
         
             
                ::Parallizer::Proxy.new(client, call_infos)
         
     | 
| 
       70 
70 
     | 
    
         
             
              end
         
     | 
| 
       71 
71 
     | 
    
         | 
| 
      
 72 
     | 
    
         
            +
              def all_call_results
         
     | 
| 
      
 73 
     | 
    
         
            +
                proxy = create_proxy
         
     | 
| 
      
 74 
     | 
    
         
            +
             
     | 
| 
      
 75 
     | 
    
         
            +
                call_infos.keys.inject({}) do |result, method_name_and_args|
         
     | 
| 
      
 76 
     | 
    
         
            +
                  result[method_name_and_args] = proxy.send(*method_name_and_args)
         
     | 
| 
      
 77 
     | 
    
         
            +
             
     | 
| 
      
 78 
     | 
    
         
            +
                  result
         
     | 
| 
      
 79 
     | 
    
         
            +
                end
         
     | 
| 
      
 80 
     | 
    
         
            +
              end
         
     | 
| 
      
 81 
     | 
    
         
            +
             
     | 
| 
       72 
82 
     | 
    
         
             
              private
         
     | 
| 
       73 
83 
     | 
    
         | 
| 
       74 
84 
     | 
    
         
             
              def execute
         
     | 
    
        data/lib/parallizer/version.rb
    CHANGED
    
    
    
        data/spec/parallizer_spec.rb
    CHANGED
    
    | 
         @@ -3,21 +3,30 @@ require 'spec_helper' 
     | 
|
| 
       3 
3 
     | 
    
         
             
            describe Parallizer do
         
     | 
| 
       4 
4 
     | 
    
         
             
              class TestObject
         
     | 
| 
       5 
5 
     | 
    
         
             
                def a_method(arg)
         
     | 
| 
       6 
     | 
    
         
            -
                   
     | 
| 
      
 6 
     | 
    
         
            +
                  @a_method ||= {}
         
     | 
| 
      
 7 
     | 
    
         
            +
                  @a_method[arg] ||= rand(1..100)
         
     | 
| 
       7 
8 
     | 
    
         
             
                end
         
     | 
| 
       8 
9 
     | 
    
         | 
| 
       9 
10 
     | 
    
         
             
                def another_method
         
     | 
| 
      
 11 
     | 
    
         
            +
                  @another_method ||= rand(1..100)
         
     | 
| 
      
 12 
     | 
    
         
            +
                end
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
                def current_thread
         
     | 
| 
      
 15 
     | 
    
         
            +
                  Thread.current
         
     | 
| 
      
 16 
     | 
    
         
            +
                end
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
                def another_current_thread
         
     | 
| 
       10 
19 
     | 
    
         
             
                  Thread.current
         
     | 
| 
       11 
20 
     | 
    
         
             
                end
         
     | 
| 
       12 
21 
     | 
    
         
             
              end
         
     | 
| 
       13 
22 
     | 
    
         | 
| 
       14 
23 
     | 
    
         
             
              class AnotherTestObject
         
     | 
| 
       15 
24 
     | 
    
         
             
                def a_method
         
     | 
| 
       16 
     | 
    
         
            -
                   
     | 
| 
      
 25 
     | 
    
         
            +
                  @a_method ||= rand(1..100)
         
     | 
| 
       17 
26 
     | 
    
         
             
                end
         
     | 
| 
       18 
27 
     | 
    
         | 
| 
       19 
28 
     | 
    
         
             
                def another_method
         
     | 
| 
       20 
     | 
    
         
            -
                   
     | 
| 
      
 29 
     | 
    
         
            +
                  @another_method ||= rand(1..100)
         
     | 
| 
       21 
30 
     | 
    
         
             
                end
         
     | 
| 
       22 
31 
     | 
    
         
             
              end
         
     | 
| 
       23 
32 
     | 
    
         | 
| 
         @@ -90,6 +99,31 @@ describe Parallizer do 
     | 
|
| 
       90 
99 
     | 
    
         
             
                end
         
     | 
| 
       91 
100 
     | 
    
         
             
              end
         
     | 
| 
       92 
101 
     | 
    
         | 
| 
      
 102 
     | 
    
         
            +
              describe "#all_call_results" do
         
     | 
| 
      
 103 
     | 
    
         
            +
                before do
         
     | 
| 
      
 104 
     | 
    
         
            +
                  @client = TestObject.new
         
     | 
| 
      
 105 
     | 
    
         
            +
                  @parallizer = Parallizer.new(@client)
         
     | 
| 
      
 106 
     | 
    
         
            +
                end
         
     | 
| 
      
 107 
     | 
    
         
            +
                
         
     | 
| 
      
 108 
     | 
    
         
            +
                execute do
         
     | 
| 
      
 109 
     | 
    
         
            +
                  @results = @parallizer.all_call_results
         
     | 
| 
      
 110 
     | 
    
         
            +
                end
         
     | 
| 
      
 111 
     | 
    
         
            +
                
         
     | 
| 
      
 112 
     | 
    
         
            +
                context "gives all results" do
         
     | 
| 
      
 113 
     | 
    
         
            +
                  before do
         
     | 
| 
      
 114 
     | 
    
         
            +
                    @parallizer.add_call(:a_method, 'arg1')
         
     | 
| 
      
 115 
     | 
    
         
            +
                    @parallizer.add_call(:a_method, 'arg2')
         
     | 
| 
      
 116 
     | 
    
         
            +
                    @parallizer.add_call(:another_method)
         
     | 
| 
      
 117 
     | 
    
         
            +
                  end
         
     | 
| 
      
 118 
     | 
    
         
            +
                  
         
     | 
| 
      
 119 
     | 
    
         
            +
                  it "gives results in order executed" do
         
     | 
| 
      
 120 
     | 
    
         
            +
                    @results[[:a_method, 'arg1']].should == @client.a_method('arg1')
         
     | 
| 
      
 121 
     | 
    
         
            +
                    @results[[:a_method, 'arg2']].should == @client.a_method('arg2')
         
     | 
| 
      
 122 
     | 
    
         
            +
                    @results[[:another_method]].should == @client.another_method
         
     | 
| 
      
 123 
     | 
    
         
            +
                  end
         
     | 
| 
      
 124 
     | 
    
         
            +
                end
         
     | 
| 
      
 125 
     | 
    
         
            +
              end
         
     | 
| 
      
 126 
     | 
    
         
            +
             
     | 
| 
       93 
127 
     | 
    
         
             
              describe "#create_proxy" do
         
     | 
| 
       94 
128 
     | 
    
         
             
                before do
         
     | 
| 
       95 
129 
     | 
    
         
             
                  @client = TestObject.new
         
     | 
| 
         @@ -102,15 +136,15 @@ describe Parallizer do 
     | 
|
| 
       102 
136 
     | 
    
         | 
| 
       103 
137 
     | 
    
         
             
                context "with existing method on client" do
         
     | 
| 
       104 
138 
     | 
    
         
             
                  before do
         
     | 
| 
       105 
     | 
    
         
            -
                    @parallizer.add_call(: 
     | 
| 
      
 139 
     | 
    
         
            +
                    @parallizer.add_call(:current_thread)
         
     | 
| 
       106 
140 
     | 
    
         
             
                  end
         
     | 
| 
       107 
141 
     | 
    
         | 
| 
       108 
142 
     | 
    
         
             
                  it "should execute method with add_call in a separate thread" do
         
     | 
| 
       109 
     | 
    
         
            -
                    @proxy. 
     | 
| 
      
 143 
     | 
    
         
            +
                    @proxy.current_thread.should_not == Thread.current
         
     | 
| 
       110 
144 
     | 
    
         
             
                  end
         
     | 
| 
       111 
145 
     | 
    
         | 
| 
       112 
146 
     | 
    
         
             
                  it "should execute method not added with add_call in current thread" do
         
     | 
| 
       113 
     | 
    
         
            -
                    @proxy. 
     | 
| 
      
 147 
     | 
    
         
            +
                    @proxy.another_current_thread.should == Thread.current
         
     | 
| 
       114 
148 
     | 
    
         
             
                  end
         
     | 
| 
       115 
149 
     | 
    
         
             
                end
         
     | 
| 
       116 
150 
     | 
    
         | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: parallizer
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.4. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.4.2
         
     | 
| 
       5 
5 
     | 
    
         
             
              prerelease: 
         
     | 
| 
       6 
6 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       7 
7 
     | 
    
         
             
            authors:
         
     | 
| 
         @@ -9,7 +9,7 @@ authors: 
     | 
|
| 
       9 
9 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       10 
10 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       11 
11 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       12 
     | 
    
         
            -
            date: 2013- 
     | 
| 
      
 12 
     | 
    
         
            +
            date: 2013-07-30 00:00:00.000000000 Z
         
     | 
| 
       13 
13 
     | 
    
         
             
            dependencies:
         
     | 
| 
       14 
14 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       15 
15 
     | 
    
         
             
              name: celluloid
         
     | 
| 
         @@ -110,18 +110,12 @@ required_ruby_version: !ruby/object:Gem::Requirement 
     | 
|
| 
       110 
110 
     | 
    
         
             
              - - ! '>='
         
     | 
| 
       111 
111 
     | 
    
         
             
                - !ruby/object:Gem::Version
         
     | 
| 
       112 
112 
     | 
    
         
             
                  version: '0'
         
     | 
| 
       113 
     | 
    
         
            -
                  segments:
         
     | 
| 
       114 
     | 
    
         
            -
                  - 0
         
     | 
| 
       115 
     | 
    
         
            -
                  hash: 1172644731991110538
         
     | 
| 
       116 
113 
     | 
    
         
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         
     | 
| 
       117 
114 
     | 
    
         
             
              none: false
         
     | 
| 
       118 
115 
     | 
    
         
             
              requirements:
         
     | 
| 
       119 
116 
     | 
    
         
             
              - - ! '>='
         
     | 
| 
       120 
117 
     | 
    
         
             
                - !ruby/object:Gem::Version
         
     | 
| 
       121 
118 
     | 
    
         
             
                  version: '0'
         
     | 
| 
       122 
     | 
    
         
            -
                  segments:
         
     | 
| 
       123 
     | 
    
         
            -
                  - 0
         
     | 
| 
       124 
     | 
    
         
            -
                  hash: 1172644731991110538
         
     | 
| 
       125 
119 
     | 
    
         
             
            requirements: []
         
     | 
| 
       126 
120 
     | 
    
         
             
            rubyforge_project: parallizer
         
     | 
| 
       127 
121 
     | 
    
         
             
            rubygems_version: 1.8.25
         
     |