atomically 1.1.0 → 1.1.1
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 +5 -5
- data/.travis.yml +7 -0
- data/CHANGELOG.md +6 -0
- data/README.md +2 -2
- data/atomically.gemspec +2 -2
- data/gemfiles/6.0.makara.gemfile +17 -0
- data/lib/atomically/adapter_check_service.rb +18 -4
- data/lib/atomically/query_service.rb +5 -9
- data/lib/atomically/version.rb +1 -1
- metadata +8 -8
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 | 
            -
             | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 2 | 
            +
            SHA256:
         | 
| 3 | 
            +
              metadata.gz: 4785f6bc399158f874395e862ef07c1f945e78490b18e56c06fc903bdf32e139
         | 
| 4 | 
            +
              data.tar.gz: 6b14e38f5df25ffdb507c34a7b7fc099b42f112bb91c66f026a86e3302fe4169
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: de8c068d9f094983f16893e7157302e3c053c5095929f0eec3a790bfefa81f49a0bdbc5da9f6d56ec6d8b1fb4dc96266fb68745aae473beabc93000b6c14222e
         | 
| 7 | 
            +
              data.tar.gz: a963fbc7b93c3ccf240f0067b2e1355259076bcccb5e4caa22791f7ad515b468bd72d7d008fd5bdd1a59939f590e1dbc4e3b5dafcf3e20b2f0b592936486ada3
         | 
    
        data/.travis.yml
    CHANGED
    
    | @@ -21,6 +21,13 @@ gemfile: | |
| 21 21 | 
             
              - gemfiles/5.2.gemfile
         | 
| 22 22 | 
             
              - gemfiles/6.0.gemfile
         | 
| 23 23 | 
             
            matrix:
         | 
| 24 | 
            +
              include:
         | 
| 25 | 
            +
                - env: DB=makara_mysql
         | 
| 26 | 
            +
                  gemfile: gemfiles/6.0.makara.gemfile
         | 
| 27 | 
            +
                  rvm: 2.6
         | 
| 28 | 
            +
                - env: DB=makara_pg
         | 
| 29 | 
            +
                  gemfile: gemfiles/6.0.makara.gemfile
         | 
| 30 | 
            +
                  rvm: 2.6
         | 
| 24 31 | 
             
              exclude:
         | 
| 25 32 | 
             
                - gemfile: gemfiles/3.2.gemfile
         | 
| 26 33 | 
             
                  rvm: 2.6
         | 
    
        data/CHANGELOG.md
    CHANGED
    
    | @@ -1,5 +1,11 @@ | |
| 1 1 | 
             
            ## Change Log
         | 
| 2 2 |  | 
| 3 | 
            +
            ### [v1.1.0](https://github.com/khiav223577/atomically/compare/v1.0.6...v1.1.0) 2019/10/23
         | 
| 4 | 
            +
            - [#12](https://github.com/khiav223577/atomically/pull/12) Support pg (@khiav223577)
         | 
| 5 | 
            +
            - [#14](https://github.com/khiav223577/atomically/pull/14) Support Rails 6.0 (@khiav223577)
         | 
| 6 | 
            +
            - [#13](https://github.com/khiav223577/atomically/pull/13) Remove deprecated codeclimate-test-reporter gem (@khiav223577)
         | 
| 7 | 
            +
            - [#11](https://github.com/khiav223577/atomically/pull/11) Fix: Non-attribute arguments will be disallowed in Rails 6.0 (@khiav223577)
         | 
| 8 | 
            +
             | 
| 3 9 | 
             
            ### [v1.0.6](https://github.com/khiav223577/atomically/compare/v1.0.5...v1.0.6) 2019/01/28
         | 
| 4 10 | 
             
            - [#10](https://github.com/khiav223577/atomically/pull/10) `decrement_unsigned_counters` should be able to decrement the field to zero (@khiav223577)
         | 
| 5 11 |  | 
    
        data/README.md
    CHANGED
    
    | @@ -263,11 +263,11 @@ arena.atomically_close! | |
| 263 263 | 
             
            # => false (if race condition occurs)
         | 
| 264 264 | 
             
            ```
         | 
| 265 265 |  | 
| 266 | 
            -
            The return value can be used to prevent race condition and make sure some piece of code is executed once.
         | 
| 266 | 
            +
            The return value can be used to prevent race condition and make sure some piece of code is executed only once.
         | 
| 267 267 |  | 
| 268 268 | 
             
            ```rb
         | 
| 269 269 | 
             
            if arena.atomically_close!
         | 
| 270 | 
            -
              # Only one request can pass this check and  | 
| 270 | 
            +
              # Only one request can pass this check and execute the code here.
         | 
| 271 271 | 
             
              # You can send rewards, calculate ranking, or fire background job here.
         | 
| 272 272 | 
             
              # No need to worry about being invoked multiple times.
         | 
| 273 273 | 
             
              do_something
         | 
    
        data/atomically.gemspec
    CHANGED
    
    | @@ -9,8 +9,8 @@ Gem::Specification.new do |spec| | |
| 9 9 | 
             
              spec.authors       = ['khiav reoy']
         | 
| 10 10 | 
             
              spec.email         = ['mrtmrt15xn@yahoo.com.tw']
         | 
| 11 11 |  | 
| 12 | 
            -
              spec.summary       = ' | 
| 13 | 
            -
              spec.description   = ' | 
| 12 | 
            +
              spec.summary       = 'An ActiveRecord extension for writing commonly useful atomic SQL statements to avoid race condition.'
         | 
| 13 | 
            +
              spec.description   = 'An ActiveRecord extension for writing commonly useful atomic SQL statements to avoid race condition.'
         | 
| 14 14 | 
             
              spec.homepage      = 'https://github.com/khiav223577/atomically'
         | 
| 15 15 | 
             
              spec.license       = 'MIT'
         | 
| 16 16 |  | 
| @@ -0,0 +1,17 @@ | |
| 1 | 
            +
            source 'https://rubygems.org'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            gem 'activerecord', '~> 6.0.0'
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            group :test do
         | 
| 6 | 
            +
              case ENV['DB']
         | 
| 7 | 
            +
              when 'mysql'    ; gem 'mysql2', '0.5.1'
         | 
| 8 | 
            +
              when 'postgres' ; gem 'pg', '~> 0.18'
         | 
| 9 | 
            +
              end
         | 
| 10 | 
            +
              gem 'simplecov'
         | 
| 11 | 
            +
              gem 'pluck_all', '>= 2.0.4'
         | 
| 12 | 
            +
              gem 'timecop', '~> 0.9.1'
         | 
| 13 | 
            +
              gem 'update_all_scope', '~> 0.1.0'
         | 
| 14 | 
            +
              gem 'makara', '~> 0.4.1'
         | 
| 15 | 
            +
            end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
            gemspec path: '../'
         | 
| @@ -5,12 +5,26 @@ class Atomically::AdapterCheckService | |
| 5 5 | 
             
              end
         | 
| 6 6 |  | 
| 7 7 | 
             
              def pg?
         | 
| 8 | 
            -
                 | 
| 9 | 
            -
                return @klass.connection.is_a?(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter)
         | 
| 8 | 
            +
                possible_pg_klasses.any?{|s| @klass.connection.is_a?(s) }
         | 
| 10 9 | 
             
              end
         | 
| 11 10 |  | 
| 12 11 | 
             
              def mysql?
         | 
| 13 | 
            -
                 | 
| 14 | 
            -
             | 
| 12 | 
            +
                possible_mysql_klasses.any?{|s| @klass.connection.is_a?(s) }
         | 
| 13 | 
            +
              end
         | 
| 14 | 
            +
             | 
| 15 | 
            +
              private
         | 
| 16 | 
            +
             | 
| 17 | 
            +
              def possible_pg_klasses
         | 
| 18 | 
            +
                @possible_pg_klasses ||= [].tap do |result|
         | 
| 19 | 
            +
                  result << ActiveRecord::ConnectionAdapters::PostgreSQLAdapter if defined?(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter)
         | 
| 20 | 
            +
                  result << ActiveRecord::ConnectionAdapters::MakaraPostgreSQLAdapter if defined?(ActiveRecord::ConnectionAdapters::MakaraPostgreSQLAdapter)
         | 
| 21 | 
            +
                end
         | 
| 22 | 
            +
              end
         | 
| 23 | 
            +
             | 
| 24 | 
            +
              def possible_mysql_klasses
         | 
| 25 | 
            +
                @possible_mysql_klasses ||= [].tap do |result|
         | 
| 26 | 
            +
                  result << ActiveRecord::ConnectionAdapters::Mysql2Adapter if defined?(ActiveRecord::ConnectionAdapters::Mysql2Adapter)
         | 
| 27 | 
            +
                  result << ActiveRecord::ConnectionAdapters::MakaraMysql2Adapter if defined?(ActiveRecord::ConnectionAdapters::MakaraMysql2Adapter)
         | 
| 28 | 
            +
                end
         | 
| 15 29 | 
             
              end
         | 
| 16 30 | 
             
            end
         | 
| @@ -34,7 +34,7 @@ class Atomically::QueryService | |
| 34 34 | 
             
                end
         | 
| 35 35 |  | 
| 36 36 | 
             
                raw_when_sql = hash.map{|id, pay_count| "WHEN #{sanitize(id)} THEN #{sanitize(-pay_count)}" }.join("\n")
         | 
| 37 | 
            -
                no_var_in_sql = true if update_columns.size == 1 or  | 
| 37 | 
            +
                no_var_in_sql = true if update_columns.size == 1 or adapter_check_service.pg?
         | 
| 38 38 | 
             
                update_sqls = update_columns.map.with_index do |column, idx|
         | 
| 39 39 | 
             
                  if no_var_in_sql
         | 
| 40 40 | 
             
                    value = "(\nCASE #{quote_column(primary_key)}\n#{raw_when_sql}\nEND)"
         | 
| @@ -71,7 +71,7 @@ class Atomically::QueryService | |
| 71 71 | 
             
              end
         | 
| 72 72 |  | 
| 73 73 | 
             
              def update_all_and_get_ids(*args)
         | 
| 74 | 
            -
                if  | 
| 74 | 
            +
                if adapter_check_service.pg?
         | 
| 75 75 | 
             
                  scope = UpdateAllScope::UpdateAllScope.new(model: @model, relation: @relation.where(''))
         | 
| 76 76 | 
             
                  scope.update(*args)
         | 
| 77 77 | 
             
                  return @klass.connection.execute("#{scope.to_sql} RETURNING id", "#{@klass} Update All").map{|s| s['id'].to_i }
         | 
| @@ -89,17 +89,13 @@ class Atomically::QueryService | |
| 89 89 |  | 
| 90 90 | 
             
              private
         | 
| 91 91 |  | 
| 92 | 
            -
              def  | 
| 93 | 
            -
                Atomically::AdapterCheckService.new(@klass) | 
| 94 | 
            -
              end
         | 
| 95 | 
            -
             | 
| 96 | 
            -
              def db_is_mysql?
         | 
| 97 | 
            -
                Atomically::AdapterCheckService.new(@klass).mysql?
         | 
| 92 | 
            +
              def adapter_check_service
         | 
| 93 | 
            +
                @adapter_check_service ||= Atomically::AdapterCheckService.new(@klass)
         | 
| 98 94 | 
             
              end
         | 
| 99 95 |  | 
| 100 96 | 
             
              def on_duplicate_key_plus_sql(columns, conflict_target)
         | 
| 101 97 | 
             
                service = Atomically::OnDuplicateSqlService.new(@klass, columns)
         | 
| 102 | 
            -
                return service.mysql_quote_columns_for_plus.join(', ') if  | 
| 98 | 
            +
                return service.mysql_quote_columns_for_plus.join(', ') if adapter_check_service.mysql?
         | 
| 103 99 | 
             
                return {
         | 
| 104 100 | 
             
                  conflict_target: conflict_target,
         | 
| 105 101 | 
             
                  columns: service.pg_quote_columns_for_plus.join(', ')
         | 
    
        data/lib/atomically/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: atomically
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 1.1. | 
| 4 | 
            +
              version: 1.1.1
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - khiav reoy
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: exe
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2019- | 
| 11 | 
            +
            date: 2019-11-01 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: bundler
         | 
| @@ -184,8 +184,8 @@ dependencies: | |
| 184 184 | 
             
                - - "~>"
         | 
| 185 185 | 
             
                  - !ruby/object:Gem::Version
         | 
| 186 186 | 
             
                    version: 0.1.0
         | 
| 187 | 
            -
            description:  | 
| 188 | 
            -
              condition.
         | 
| 187 | 
            +
            description: An ActiveRecord extension for writing commonly useful atomic SQL statements
         | 
| 188 | 
            +
              to avoid race condition.
         | 
| 189 189 | 
             
            email:
         | 
| 190 190 | 
             
            - mrtmrt15xn@yahoo.com.tw
         | 
| 191 191 | 
             
            executables: []
         | 
| @@ -210,6 +210,7 @@ files: | |
| 210 210 | 
             
            - gemfiles/5.1.gemfile
         | 
| 211 211 | 
             
            - gemfiles/5.2.gemfile
         | 
| 212 212 | 
             
            - gemfiles/6.0.gemfile
         | 
| 213 | 
            +
            - gemfiles/6.0.makara.gemfile
         | 
| 213 214 | 
             
            - lib/atomically.rb
         | 
| 214 215 | 
             
            - lib/atomically/active_record/extension.rb
         | 
| 215 216 | 
             
            - lib/atomically/adapter_check_service.rb
         | 
| @@ -243,10 +244,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 243 244 | 
             
                - !ruby/object:Gem::Version
         | 
| 244 245 | 
             
                  version: '0'
         | 
| 245 246 | 
             
            requirements: []
         | 
| 246 | 
            -
             | 
| 247 | 
            -
            rubygems_version: 2.6.14
         | 
| 247 | 
            +
            rubygems_version: 3.0.3
         | 
| 248 248 | 
             
            signing_key: 
         | 
| 249 249 | 
             
            specification_version: 4
         | 
| 250 | 
            -
            summary:  | 
| 251 | 
            -
              condition.
         | 
| 250 | 
            +
            summary: An ActiveRecord extension for writing commonly useful atomic SQL statements
         | 
| 251 | 
            +
              to avoid race condition.
         | 
| 252 252 | 
             
            test_files: []
         |