factbase 0.0.43 → 0.0.44
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/factbase/rules.rb +6 -3
 - data/lib/factbase.rb +11 -3
 - data/test/test_factbase.rb +2 -1
 - metadata +1 -1
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 7942029d876a9fee77f167bb9e9d7311445e16fa38c9654dfd6eae231fb9c366
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 102f08927aafc6900d4563e90cbabb9311166307e1ca57a9bd4e484ff8be684a
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: d6877f4b3dbe627819256cda88214fd170e89e37521c2936daa0fed5a02b1450fc98157c53e92d2f38e48522dd617d901609ec1b23b96875abb68a7c231d5a47
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 482f13ec05d51bf726049ed44627ec2719ee17b1a5b387eb7ebb6ee98a760523702f9f81540e6e10ff2dc211a90321742c5796cb63ef9ee4aa64fa6777886b81
         
     | 
    
        data/lib/factbase/rules.rb
    CHANGED
    
    | 
         @@ -53,11 +53,14 @@ class Factbase::Rules 
     | 
|
| 
       53 
53 
     | 
    
         
             
              def txn(this = self, &)
         
     | 
| 
       54 
54 
     | 
    
         
             
                before = @check
         
     | 
| 
       55 
55 
     | 
    
         
             
                @check = Blind.new
         
     | 
| 
       56 
     | 
    
         
            -
                @fb.txn(this, &)
         
     | 
| 
      
 56 
     | 
    
         
            +
                modified = @fb.txn(this, &)
         
     | 
| 
       57 
57 
     | 
    
         
             
                @check = before
         
     | 
| 
       58 
     | 
    
         
            -
                 
     | 
| 
       59 
     | 
    
         
            -
                  @ 
     | 
| 
      
 58 
     | 
    
         
            +
                if modified
         
     | 
| 
      
 59 
     | 
    
         
            +
                  @fb.query('(always)').each do |f|
         
     | 
| 
      
 60 
     | 
    
         
            +
                    @check.it(f)
         
     | 
| 
      
 61 
     | 
    
         
            +
                  end
         
     | 
| 
       60 
62 
     | 
    
         
             
                end
         
     | 
| 
      
 63 
     | 
    
         
            +
                modified
         
     | 
| 
       61 
64 
     | 
    
         
             
              end
         
     | 
| 
       62 
65 
     | 
    
         | 
| 
       63 
66 
     | 
    
         
             
              def export
         
     | 
    
        data/lib/factbase.rb
    CHANGED
    
    | 
         @@ -79,7 +79,7 @@ require 'yaml' 
     | 
|
| 
       79 
79 
     | 
    
         
             
            # License:: MIT
         
     | 
| 
       80 
80 
     | 
    
         
             
            class Factbase
         
     | 
| 
       81 
81 
     | 
    
         
             
              # Current version of the gem (changed by .rultor.yml on every release)
         
     | 
| 
       82 
     | 
    
         
            -
              VERSION = '0.0. 
     | 
| 
      
 82 
     | 
    
         
            +
              VERSION = '0.0.44'
         
     | 
| 
       83 
83 
     | 
    
         | 
| 
       84 
84 
     | 
    
         
             
              # An exception that may be thrown in a transaction, to roll it back.
         
     | 
| 
       85 
85 
     | 
    
         
             
              class Rollback < StandardError; end
         
     | 
| 
         @@ -159,22 +159,30 @@ class Factbase 
     | 
|
| 
       159 
159 
     | 
    
         
             
              # inserted and all changes that happened in the block will be rolled back.
         
     | 
| 
       160 
160 
     | 
    
         
             
              #
         
     | 
| 
       161 
161 
     | 
    
         
             
              # @param [Factbase] this The factbase to use (don't provide this param)
         
     | 
| 
      
 162 
     | 
    
         
            +
              # @return [Boolean] TRUE if some changes have been made, FALSE otherwise
         
     | 
| 
       162 
163 
     | 
    
         
             
              def txn(this = self)
         
     | 
| 
       163 
164 
     | 
    
         
             
                copy = this.dup
         
     | 
| 
       164 
165 
     | 
    
         
             
                begin
         
     | 
| 
       165 
166 
     | 
    
         
             
                  yield copy
         
     | 
| 
       166 
167 
     | 
    
         
             
                rescue Factbase::Rollback
         
     | 
| 
       167 
     | 
    
         
            -
                  return
         
     | 
| 
      
 168 
     | 
    
         
            +
                  return false
         
     | 
| 
       168 
169 
     | 
    
         
             
                end
         
     | 
| 
      
 170 
     | 
    
         
            +
                modified = false
         
     | 
| 
       169 
171 
     | 
    
         
             
                @mutex.synchronize do
         
     | 
| 
       170 
172 
     | 
    
         
             
                  after = Marshal.load(copy.export)
         
     | 
| 
       171 
173 
     | 
    
         
             
                  after.each_with_index do |m, i|
         
     | 
| 
       172 
     | 
    
         
            -
                     
     | 
| 
      
 174 
     | 
    
         
            +
                    if i >= @maps.size
         
     | 
| 
      
 175 
     | 
    
         
            +
                      @maps << {}
         
     | 
| 
      
 176 
     | 
    
         
            +
                      modified = true
         
     | 
| 
      
 177 
     | 
    
         
            +
                    end
         
     | 
| 
       173 
178 
     | 
    
         
             
                    m.each do |k, v|
         
     | 
| 
      
 179 
     | 
    
         
            +
                      next if @maps[i][k] == v
         
     | 
| 
       174 
180 
     | 
    
         
             
                      @maps[i][k] = v
         
     | 
| 
      
 181 
     | 
    
         
            +
                      modified = true
         
     | 
| 
       175 
182 
     | 
    
         
             
                    end
         
     | 
| 
       176 
183 
     | 
    
         
             
                  end
         
     | 
| 
       177 
184 
     | 
    
         
             
                end
         
     | 
| 
      
 185 
     | 
    
         
            +
                modified
         
     | 
| 
       178 
186 
     | 
    
         
             
              end
         
     | 
| 
       179 
187 
     | 
    
         | 
| 
       180 
188 
     | 
    
         
             
              # Export it into a chain of bytes.
         
     | 
    
        data/test/test_factbase.rb
    CHANGED
    
    | 
         @@ -143,10 +143,11 @@ class TestFactbase < Minitest::Test 
     | 
|
| 
       143 
143 
     | 
    
         | 
| 
       144 
144 
     | 
    
         
             
              def test_txn_with_rollback
         
     | 
| 
       145 
145 
     | 
    
         
             
                fb = Factbase.new
         
     | 
| 
       146 
     | 
    
         
            -
                fb.txn do |fbt|
         
     | 
| 
      
 146 
     | 
    
         
            +
                modified = fb.txn do |fbt|
         
     | 
| 
       147 
147 
     | 
    
         
             
                  fbt.insert.bar = 33
         
     | 
| 
       148 
148 
     | 
    
         
             
                  raise Factbase::Rollback
         
     | 
| 
       149 
149 
     | 
    
         
             
                end
         
     | 
| 
      
 150 
     | 
    
         
            +
                assert(!modified)
         
     | 
| 
       150 
151 
     | 
    
         
             
                assert_equal(0, fb.query('(always)').each.to_a.size)
         
     | 
| 
       151 
152 
     | 
    
         
             
              end
         
     | 
| 
       152 
153 
     | 
    
         
             
            end
         
     |