factbase 0.0.36 → 0.0.37

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c801d7ec256766a03b081de5949367aef74dc991b67207ae30c6e6229f11c425
4
- data.tar.gz: 2cfc12996cc7e4d85fad86377ddc9b87916d5d2a1cbe5542ba8128488c1e0049
3
+ metadata.gz: a464f6fa40a3aef098e4ab4a58b6f6905ac101421f22fb806b63c4fb624aa610
4
+ data.tar.gz: ad19a0147890d8b4ff8fff96f7e9f47b09ecb264b3cb52fa606be892278fa380
5
5
  SHA512:
6
- metadata.gz: 6d2d1ec011eaf2d34f00068fa71809bf8bd3fe794b6097eeb1292ad25f1a6916e319490a137fa4c1908c00ce640f19c8efff27444ca277e72048daf5e688c3ef
7
- data.tar.gz: 7f20423de58a836eb68261a8d7ad45ec00056a4f991b8f34c68dd4833a42bbb0009bca75a4a8092112cfb80599e2be04e5cca9a9bfe18b3ae18102622d98f9a6
6
+ metadata.gz: 6abb74b759ef7eea421e8a7f4f1ebdbf7ae46836dfefcd324286508fbb82e207a787265c0cf9f8931b43b00d50e5df983266fa9442f9c277111dfa9ea3a778de
7
+ data.tar.gz: b0ed97f83f59230bafce810488f3e720d098a748149f7fbd58b7f1c25425b2fba6b742ce16b18692df34607eb3c42f9f11196ca212bc0273d7bdffe15e759efe
@@ -32,7 +32,7 @@ jobs:
32
32
  strategy:
33
33
  matrix:
34
34
  os: [ubuntu-20.04, macos-12, windows-2022]
35
- ruby: [3.2]
35
+ ruby: [3.2, 3.3]
36
36
  runs-on: ${{ matrix.os }}
37
37
  steps:
38
38
  - uses: actions/checkout@v4
data/Gemfile.lock CHANGED
@@ -101,7 +101,7 @@ GEM
101
101
  zeitwerk (~> 2.6)
102
102
  rainbow (3.1.1)
103
103
  rake (13.2.1)
104
- rdoc (6.6.3.1)
104
+ rdoc (6.7.0)
105
105
  psych (>= 4.0.0)
106
106
  regexp_parser (2.9.2)
107
107
  reline (0.5.7)
@@ -171,7 +171,7 @@ GEM
171
171
  webrick (1.8.1)
172
172
  yaml (0.3.0)
173
173
  yard (0.9.36)
174
- zeitwerk (2.6.14)
174
+ zeitwerk (2.6.15)
175
175
 
176
176
  PLATFORMS
177
177
  arm64-darwin-22
data/factbase.gemspec CHANGED
@@ -25,17 +25,21 @@ require_relative 'lib/factbase'
25
25
 
26
26
  Gem::Specification.new do |s|
27
27
  s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
28
- s.required_ruby_version = '>=2.3'
28
+ s.required_ruby_version = '>=3.0'
29
29
  s.name = 'factbase'
30
30
  s.version = Factbase::VERSION
31
31
  s.license = 'MIT'
32
32
  s.summary = 'Factbase'
33
- s.description = 'Fact base in memory and on disc'
33
+ s.description =
34
+ 'A primitive in-memory collection of key-value records ' \
35
+ 'known as "facts," with an ability to insert facts, add properties ' \
36
+ 'to facts, and delete facts. There is no ability to modify facts. ' \
37
+ 'It is also possible to find facts using Lisp-alike query predicates. ' \
38
+ 'An entire factbase may be exported to a binary file and imported back.'
34
39
  s.authors = ['Yegor Bugayenko']
35
40
  s.email = 'yegor256@gmail.com'
36
41
  s.homepage = 'http://github.com/yegor256/factbase.rb'
37
42
  s.files = `git ls-files`.split($RS)
38
- s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
39
43
  s.rdoc_options = ['--charset=UTF-8']
40
44
  s.extra_rdoc_files = ['README.md', 'LICENSE.txt']
41
45
  s.add_runtime_dependency 'json', '~> 2.7'
data/lib/factbase/fact.rb CHANGED
@@ -28,10 +28,20 @@ require_relative '../factbase'
28
28
  #
29
29
  # This is an internal class, it is not supposed to be instantiated directly.
30
30
  #
31
+ # It is possible to use for testing directly, for example to make a
32
+ # fact with a single key/value pair inside:
33
+ #
34
+ # require 'factbase/fact'
35
+ # f = Factbase::Fact.new(Mutex.new, { 'foo' => [42, 256, 'Hello, world!'] })
36
+ # assert_equal(42, f.foo)
37
+ #
31
38
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
32
39
  # Copyright:: Copyright (c) 2024 Yegor Bugayenko
33
40
  # License:: MIT
34
41
  class Factbase::Fact
42
+ # Ctor.
43
+ # @param [Mutex] mutex A mutex to use for maps synchronization
44
+ # @param [Hash] map A map of key/value pairs
35
45
  def initialize(mutex, map)
36
46
  @mutex = mutex
37
47
  @map = map
@@ -136,7 +136,7 @@ class Factbase::Syntax
136
136
  elsif t.match?(/^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$/)
137
137
  Time.parse(t)
138
138
  else
139
- raise "Wrong symbol format (#{t})" unless t.match?(/^[a-z][a-zA-Z0-9_]*$/)
139
+ raise "Wrong symbol format (#{t})" unless t.match?(/^[_a-z][a-zA-Z0-9_]*$/)
140
140
  t.to_sym
141
141
  end
142
142
  end
data/lib/factbase/term.rb CHANGED
@@ -27,6 +27,15 @@ require_relative 'fact'
27
27
  #
28
28
  # This is an internal class, it is not supposed to be instantiated directly.
29
29
  #
30
+ # It is possible to use for testing directly, for example to make a
31
+ # term with two arguments:
32
+ #
33
+ # require 'factbase/fact'
34
+ # require 'factbase/term'
35
+ # f = Factbase::Fact.new(Mutex.new, { 'foo' => [42, 256, 'Hello, world!'] })
36
+ # t = Factbase::Term.new(:lt, [:foo, 50])
37
+ # assert(t.evaluate(f))
38
+ #
30
39
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
31
40
  # Copyright:: Copyright (c) 2024 Yegor Bugayenko
32
41
  # License:: MIT
data/lib/factbase.rb CHANGED
@@ -24,12 +24,32 @@ require 'json'
24
24
  require 'yaml'
25
25
 
26
26
  # Factbase.
27
+ #
28
+ # This is an entry point to a factbase:
29
+ #
30
+ # fb = Factbase.new
31
+ # f = fb.insert # new fact created
32
+ # f.name = 'Jeff Lebowski'
33
+ # f.age = 42
34
+ # found = f.query('(gt 20 age)').each.to_a[0]
35
+ # assert(found.age == 42)
36
+ #
37
+ # A factbase may be exported to a file and then imported back:
38
+ #
39
+ # fb1 = Factbase.new
40
+ # File.writebin(file, fb1.export)
41
+ # fb2 = Factbase.new # it's empty
42
+ # fb2.import(File.readbin(file))
43
+ #
44
+ # It's important to use +writebin+ and +readbin+, because the content is
45
+ # a chain of bytes, not a text.
46
+ #
27
47
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
28
48
  # Copyright:: Copyright (c) 2024 Yegor Bugayenko
29
49
  # License:: MIT
30
50
  class Factbase
31
51
  # Current version of the gem (changed by .rultor.yml on every release)
32
- VERSION = '0.0.36'
52
+ VERSION = '0.0.37'
33
53
 
34
54
  # Constructor.
35
55
  def initialize(facts = [])
@@ -67,7 +67,7 @@ class TestQuery < Minitest::Test
67
67
  '(gt (size num) 2)' => 1,
68
68
  '(matches name "^[a-z]+$")' => 1,
69
69
  '(lt (size num) 2)' => 2,
70
- '(eq (size hello) 0)' => 3,
70
+ '(eq (size _hello) 0)' => 3,
71
71
  '(eq num pi)' => 0,
72
72
  '(absent time)' => 2,
73
73
  '(eq pi (agg (eq num 0) (sum pi)))' => 1,
@@ -49,8 +49,8 @@ class TestFactbase < Minitest::Test
49
49
  f2 = Factbase.new
50
50
  f1.insert.foo = 42
51
51
  Tempfile.open do |f|
52
- File.write(f.path, f1.export)
53
- f2.import(File.read(f.path))
52
+ File.binwrite(f.path, f1.export)
53
+ f2.import(File.binread(f.path))
54
54
  end
55
55
  assert_equal(1, f2.query('(eq foo 42)').each.to_a.count)
56
56
  end
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.36
4
+ version: 0.0.37
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-05-26 00:00:00.000000000 Z
11
+ date: 2024-05-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -66,7 +66,11 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0.3'
69
- description: Fact base in memory and on disc
69
+ description: A primitive in-memory collection of key-value records known as "facts,"
70
+ with an ability to insert facts, add properties to facts, and delete facts. There
71
+ is no ability to modify facts. It is also possible to find facts using Lisp-alike
72
+ query predicates. An entire factbase may be exported to a binary file and imported
73
+ back.
70
74
  email: yegor256@gmail.com
71
75
  executables: []
72
76
  extensions: []
@@ -138,7 +142,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
138
142
  requirements:
139
143
  - - ">="
140
144
  - !ruby/object:Gem::Version
141
- version: '2.3'
145
+ version: '3.0'
142
146
  required_rubygems_version: !ruby/object:Gem::Requirement
143
147
  requirements:
144
148
  - - ">="