sequence_on 0.0.6 → 0.2.0
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/lib/sequence_on/sequenced_on.rb +13 -5
- metadata +5 -5
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 | 
            -
             | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 2 | 
            +
            SHA256:
         | 
| 3 | 
            +
              metadata.gz: 88ab0f24b916de10df5233ca70498ba208c16bfc897d5a447c8ba25e139459c7
         | 
| 4 | 
            +
              data.tar.gz: 5935cd630d7b537a7affc6ac6cccd5249ed4bf5c1b943b51f7c51a1ca899ad1a
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 4d4d4912ee560896ec44bc5a22d86ed5ccd8c32653796361a088880961d15379a55a3b8462eea07f5042ce9d0bf5b3cd3d9a0ef89a3ce55209180924723b461b
         | 
| 7 | 
            +
              data.tar.gz: e2f05f07fc501ad02c7c24b8f82c80e34ccdfbf1a9102a0227094bb7e646a3c0ae6af358fb634be3156eb0af87a1900936901d7c5ddaae82a170148422982f36
         | 
| @@ -22,20 +22,28 @@ module SequenceOn | |
| 22 22 | 
             
                  def generate_sequence_id
         | 
| 23 23 | 
             
                    return if self.sequential_id
         | 
| 24 24 | 
             
                    options = self.class.sequence_options
         | 
| 25 | 
            -
                    self.class. | 
| 26 | 
            -
                     | 
| 27 | 
            -
             | 
| 25 | 
            +
                    scope = self.class.class_exec(self, &options[:lmd])
         | 
| 26 | 
            +
                    lock_candidates = scope.values
         | 
| 27 | 
            +
                    lock_key = Digest::MD5.hexdigest(lock_candidates.join).unpack('L').join
         | 
| 28 | 
            +
             | 
| 29 | 
            +
                    self.class.connection.execute("SELECT pg_advisory_xact_lock('#{self.class.table_name}'::regclass::integer, #{lock_key})", "sequence_on") if postgresql?
         | 
| 30 | 
            +
                    last_record = if self.persisted?
         | 
| 31 | 
            +
                                    self.class
         | 
| 32 | 
            +
                                      .unscoped
         | 
| 33 | 
            +
                                      .where(scope).
         | 
| 28 34 | 
             
                                      order("#{options[:column]} DESC").
         | 
| 29 35 | 
             
                                      where("NOT id = ?", self.id).
         | 
| 30 36 | 
             
                                      first
         | 
| 31 37 | 
             
                                  else
         | 
| 32 | 
            -
                                    self.class | 
| 38 | 
            +
                                    self.class
         | 
| 39 | 
            +
                                      .unscoped
         | 
| 40 | 
            +
                                      .where(scope).
         | 
| 33 41 | 
             
                                      order("#{options[:column]} DESC").
         | 
| 34 42 | 
             
                                      first
         | 
| 35 43 | 
             
                                  end
         | 
| 36 44 |  | 
| 37 45 | 
             
                    self.sequential_id = if last_record
         | 
| 38 | 
            -
                                           last_record.send(options[:column]) + 1
         | 
| 46 | 
            +
                                           (last_record.send(options[:column]) || 0) + 1
         | 
| 39 47 | 
             
                                         else
         | 
| 40 48 | 
             
                                           options[:start_at]
         | 
| 41 49 | 
             
                                         end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,15 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: sequence_on
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.0 | 
| 4 | 
            +
              version: 0.2.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Jeremy SEBAN
         | 
| 8 | 
            +
            - Antonis Tzorvas
         | 
| 8 9 | 
             
            autorequire: 
         | 
| 9 10 | 
             
            bindir: bin
         | 
| 10 11 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date:  | 
| 12 | 
            +
            date: 2021-04-05 00:00:00.000000000 Z
         | 
| 12 13 | 
             
            dependencies:
         | 
| 13 14 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 15 | 
             
              name: activesupport
         | 
| @@ -70,7 +71,7 @@ require_paths: | |
| 70 71 | 
             
            - lib
         | 
| 71 72 | 
             
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 72 73 | 
             
              requirements:
         | 
| 73 | 
            -
              - - " | 
| 74 | 
            +
              - - ">="
         | 
| 74 75 | 
             
                - !ruby/object:Gem::Version
         | 
| 75 76 | 
             
                  version: '2.3'
         | 
| 76 77 | 
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| @@ -79,8 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 79 80 | 
             
                - !ruby/object:Gem::Version
         | 
| 80 81 | 
             
                  version: '0'
         | 
| 81 82 | 
             
            requirements: []
         | 
| 82 | 
            -
             | 
| 83 | 
            -
            rubygems_version: 2.4.5
         | 
| 83 | 
            +
            rubygems_version: 3.0.8
         | 
| 84 84 | 
             
            signing_key: 
         | 
| 85 85 | 
             
            specification_version: 4
         | 
| 86 86 | 
             
            summary: Flexible acts_as_sequenced replacement
         |