factbase 0.0.54 → 0.0.56
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/flatten.rb +1 -1
- data/lib/factbase/rules.rb +6 -2
- data/lib/factbase.rb +2 -1
- data/test/factbase/test_flatten.rb +6 -0
- data/test/factbase/test_rules.rb +8 -0
- data/test/test_factbase.rb +12 -0
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: d26f7abaafccccb51ef4077d66fed7a4a8ef846df2a7d46191d7113b27a2a689
         | 
| 4 | 
            +
              data.tar.gz: 8d0a64e42a4a695edc7ef5a7958ceb69aa6a965e53778782bd865c49a8752a4f
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 65c7a43401b8933e212dea979319cc75a0e42349123f0cd98871ee4d1493002b2f280a229820101ef481168c64a2e97333a549036dd3c88dfa3d05b4230d9085
         | 
| 7 | 
            +
              data.tar.gz: 9106f2c57b7840e95de6a6dba53859f0d0c4e0bea5770b22d558c35894e847145fe0b9d5640d017441baa91be48bcbc4a09cf38ae8390ab9d0efe379b5add37b
         | 
    
        data/lib/factbase/flatten.rb
    CHANGED
    
    | @@ -38,7 +38,7 @@ class Factbase::Flatten | |
| 38 38 | 
             
              # @return [Array<HashMap>] The hashmaps, but improved
         | 
| 39 39 | 
             
              def it
         | 
| 40 40 | 
             
                @maps
         | 
| 41 | 
            -
                  .sort_by { |m| m[@sorter] }
         | 
| 41 | 
            +
                  .sort_by { |m| m[@sorter] || [] }
         | 
| 42 42 | 
             
                  .map { |m| m.sort.to_h }
         | 
| 43 43 | 
             
                  .map { |m| m.transform_values { |v| v.size == 1 ? v[0] : v } }
         | 
| 44 44 | 
             
              end
         | 
    
        data/lib/factbase/rules.rb
    CHANGED
    
    | @@ -142,12 +142,16 @@ class Factbase::Rules | |
| 142 142 | 
             
                end
         | 
| 143 143 |  | 
| 144 144 | 
             
                def it(fact)
         | 
| 145 | 
            -
                   | 
| 145 | 
            +
                  a = fact[@uid]
         | 
| 146 | 
            +
                  return if a.nil?
         | 
| 147 | 
            +
                  @facts << a[0] unless @uid.nil?
         | 
| 146 148 | 
             
                end
         | 
| 147 149 |  | 
| 148 150 | 
             
                def include?(fact)
         | 
| 149 151 | 
             
                  return true if @uid.nil?
         | 
| 150 | 
            -
                   | 
| 152 | 
            +
                  a = fact[@uid]
         | 
| 153 | 
            +
                  return true if a.nil?
         | 
| 154 | 
            +
                  @facts.include?(a[0])
         | 
| 151 155 | 
             
                end
         | 
| 152 156 | 
             
              end
         | 
| 153 157 | 
             
            end
         | 
    
        data/lib/factbase.rb
    CHANGED
    
    | @@ -81,7 +81,7 @@ require 'yaml' | |
| 81 81 | 
             
            # License:: MIT
         | 
| 82 82 | 
             
            class Factbase
         | 
| 83 83 | 
             
              # Current version of the gem (changed by .rultor.yml on every release)
         | 
| 84 | 
            -
              VERSION = '0.0. | 
| 84 | 
            +
              VERSION = '0.0.56'
         | 
| 85 85 |  | 
| 86 86 | 
             
              # An exception that may be thrown in a transaction, to roll it back.
         | 
| 87 87 | 
             
              class Rollback < StandardError; end
         | 
| @@ -214,6 +214,7 @@ class Factbase | |
| 214 214 | 
             
              #
         | 
| 215 215 | 
             
              # @param [Bytes] bytes Byte array to import
         | 
| 216 216 | 
             
              def import(bytes)
         | 
| 217 | 
            +
                raise 'Empty input, cannot load a factbase' if bytes.empty?
         | 
| 217 218 | 
             
                @maps += Marshal.load(bytes)
         | 
| 218 219 | 
             
              end
         | 
| 219 220 | 
             
            end
         | 
| @@ -36,4 +36,10 @@ class TestFlatten < Minitest::Test | |
| 36 36 | 
             
                assert(42, to[1]['b'])
         | 
| 37 37 | 
             
                assert(2, to[2]['c'].size)
         | 
| 38 38 | 
             
              end
         | 
| 39 | 
            +
             | 
| 40 | 
            +
              def test_without_sorter
         | 
| 41 | 
            +
                maps = [{ 'b' => [42], 'i' => [44] }, { 'a' => 33 }]
         | 
| 42 | 
            +
                to = Factbase::Flatten.new(maps, 'i').it
         | 
| 43 | 
            +
                assert(33, to[0]['a'])
         | 
| 44 | 
            +
              end
         | 
| 39 45 | 
             
            end
         | 
    
        data/test/factbase/test_rules.rb
    CHANGED
    
    | @@ -44,6 +44,14 @@ class TestRules < Minitest::Test | |
| 44 44 | 
             
                end
         | 
| 45 45 | 
             
              end
         | 
| 46 46 |  | 
| 47 | 
            +
              def test_check_with_id
         | 
| 48 | 
            +
                fb = Factbase::Rules.new(Factbase.new, '(exists foo)', uid: 'id')
         | 
| 49 | 
            +
                fb.txn do |fbt|
         | 
| 50 | 
            +
                  f = fbt.insert
         | 
| 51 | 
            +
                  f.foo = 42
         | 
| 52 | 
            +
                end
         | 
| 53 | 
            +
              end
         | 
| 54 | 
            +
             | 
| 47 55 | 
             
              def test_to_string
         | 
| 48 56 | 
             
                fb = Factbase::Rules.new(
         | 
| 49 57 | 
             
                  Factbase.new,
         | 
    
        data/test/test_factbase.rb
    CHANGED
    
    | @@ -90,6 +90,18 @@ class TestFactbase < Minitest::Test | |
| 90 90 | 
             
                assert_equal(1, f2.query('(eq foo 42)').each.to_a.count)
         | 
| 91 91 | 
             
              end
         | 
| 92 92 |  | 
| 93 | 
            +
              def test_reads_from_empty_file
         | 
| 94 | 
            +
                fb = Factbase.new
         | 
| 95 | 
            +
                Tempfile.open do |f|
         | 
| 96 | 
            +
                  File.binwrite(f.path, '')
         | 
| 97 | 
            +
                  assert(
         | 
| 98 | 
            +
                    assert_raises do
         | 
| 99 | 
            +
                      fb.import(File.binread(f.path))
         | 
| 100 | 
            +
                    end.message.include?('cannot load a factbase')
         | 
| 101 | 
            +
                  )
         | 
| 102 | 
            +
                end
         | 
| 103 | 
            +
              end
         | 
| 104 | 
            +
             | 
| 93 105 | 
             
              def test_empty_or_not
         | 
| 94 106 | 
             
                fb = Factbase.new
         | 
| 95 107 | 
             
                assert_equal(0, fb.size)
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: factbase
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.0. | 
| 4 | 
            +
              version: 0.0.56
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Yegor Bugayenko
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2024-06- | 
| 11 | 
            +
            date: 2024-06-27 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: backtrace
         |