factbase 0.0.5 → 0.0.7

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: d62cf79f36b50a4a4e447d9596287e62b4a5c5850a74980ec1571cbf6b2db4e2
4
- data.tar.gz: 8b0ddac1b055b6de0a78e3f96adf04a2132384a75a65b24ae904f3bd9e41c02f
3
+ metadata.gz: 453a090310ef10ace85c3ee099b85bd8744d24428923f1e896626b996d3124ca
4
+ data.tar.gz: 0236a9f6bb4b4dacca29bd1d61da395a8dadb084b81e915b7694a763ecf0985b
5
5
  SHA512:
6
- metadata.gz: 73c098af9694327477acb8455b5d28d8c208ed3105f6a7273296c6fca7304ef67a7c6707b8db34d3556d2254b3297c2c93236115a9d69c3ae423d02cc84c5e5c
7
- data.tar.gz: 5b04e6671d7296e398c2fc7e8bbf5d19a0eeca5429fdab09bea857816601e580c2e38985b7ca434648536693940ac81f90cb140596be740b2f770c54f338b0ae
6
+ metadata.gz: 00312f424b58cfda7eee00a7fba6792da9a5b439eab34e29745cdd481913df87afc016944387e95356ece05feddbc444d90ddb52bdf2a20d3bc4ac38e7224a79
7
+ data.tar.gz: 224a5b63c85cf5fc604da26f8f4205a35fe6b3ace5f8fb959b6a2a3fd71f08dc79a2804215dab823c1143e02a8ddd06de0df3154912e116de04da97233ff8795
@@ -1,6 +1,25 @@
1
+ # Copyright (c) 2024 Yegor Bugayenko
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the 'Software'), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in all
11
+ # copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ # SOFTWARE.
1
20
  ---
2
21
  name: pdd
3
- on:
22
+ 'on':
4
23
  push:
5
24
  branches:
6
25
  - master
@@ -1,3 +1,22 @@
1
+ # Copyright (c) 2024 Yegor Bugayenko
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the 'Software'), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in all
11
+ # copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ # SOFTWARE.
1
20
  ---
2
21
  name: rake
3
22
  on:
@@ -1,6 +1,25 @@
1
+ # Copyright (c) 2024 Yegor Bugayenko
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the 'Software'), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in all
11
+ # copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ # SOFTWARE.
1
20
  ---
2
21
  name: xcop
3
- on:
22
+ 'on':
4
23
  push:
5
24
  pull_request:
6
25
  jobs:
data/Rakefile CHANGED
@@ -22,7 +22,6 @@
22
22
 
23
23
  require 'rubygems'
24
24
  require 'rake'
25
- require 'rdoc'
26
25
  require 'rake/clean'
27
26
 
28
27
  def name
data/factbase.gemspec CHANGED
@@ -26,7 +26,7 @@ Gem::Specification.new do |s|
26
26
  s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
27
27
  s.required_ruby_version = '>=2.3'
28
28
  s.name = 'factbase'
29
- s.version = '0.0.5'
29
+ s.version = '0.0.7'
30
30
  s.license = 'MIT'
31
31
  s.summary = 'Factbase'
32
32
  s.description = 'Fact base in memory and on disc'
@@ -37,5 +37,7 @@ Gem::Specification.new do |s|
37
37
  s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
38
38
  s.rdoc_options = ['--charset=UTF-8']
39
39
  s.extra_rdoc_files = ['README.md', 'LICENSE.txt']
40
+ s.add_runtime_dependency 'json', '~> 2.7'
41
+ s.add_runtime_dependency 'nokogiri', '~> 1.10'
40
42
  s.metadata['rubygems_mfa_required'] = 'true'
41
43
  end
data/lib/factbase/fact.rb CHANGED
@@ -35,10 +35,11 @@ class Factbase::Fact
35
35
  def method_missing(*args)
36
36
  k = args[0].to_s
37
37
  if k.end_with?('=')
38
- k = k[0..-2]
38
+ kk = k[0..-2]
39
+ raise "Invalid prop name '#{kk}'" unless kk.match?(/^[a-z][a-zA-Z0-9]+$/)
39
40
  @mutex.synchronize do
40
- @map[k] = [] if @map[k].nil?
41
- @map[k] << args[1]
41
+ @map[kk] = [] if @map[kk].nil?
42
+ @map[kk] << args[1]
42
43
  end
43
44
  nil
44
45
  elsif k == '[]'
data/lib/factbase.rb CHANGED
@@ -20,6 +20,9 @@
20
20
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
  # SOFTWARE.
22
22
 
23
+ require 'json'
24
+ require 'nokogiri'
25
+
23
26
  # Factbase.
24
27
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
25
28
  # Copyright:: Copyright (c) 2024 Yegor Bugayenko
@@ -31,6 +34,12 @@ class Factbase
31
34
  @mutex = Mutex.new
32
35
  end
33
36
 
37
+ # Size.
38
+ # @return [Integer] How many facts are in there
39
+ def size
40
+ @maps.size
41
+ end
42
+
34
43
  # Insert a new fact.
35
44
  # @return [Factbase::Fact] The fact just inserted
36
45
  def insert
@@ -76,7 +85,29 @@ class Factbase
76
85
  # rubocop:enable Security/MarshalLoad
77
86
  end
78
87
 
88
+ # Convert the entire factbase into JSON.
89
+ # @return [String] The factbase in JSON format
79
90
  def to_json(_ = nil)
80
91
  @maps.to_json
81
92
  end
93
+
94
+ # Convert the entire factbase into XML.
95
+ # @return [String] The factbase in XML format
96
+ def to_xml
97
+ Nokogiri::XML::Builder.new(encoding: 'UTF-8') do |xml|
98
+ xml.fb do
99
+ @maps.each do |m|
100
+ xml.f do
101
+ m.each do |k, vv|
102
+ xml.send(:"#{k}") do
103
+ vv.each do |v|
104
+ xml.send(:v, v)
105
+ end
106
+ end
107
+ end
108
+ end
109
+ end
110
+ end
111
+ end.to_xml
112
+ end
82
113
  end
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- #
4
3
  # Copyright (c) 2024 Yegor Bugayenko
5
4
  #
6
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- #
4
3
  # Copyright (c) 2024 Yegor Bugayenko
5
4
  #
6
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- #
4
3
  # Copyright (c) 2024 Yegor Bugayenko
5
4
  #
6
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- #
4
3
  # Copyright (c) 2024 Yegor Bugayenko
5
4
  #
6
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- #
4
3
  # Copyright (c) 2024 Yegor Bugayenko
5
4
  #
6
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- #
4
3
  # Copyright (c) 2024 Yegor Bugayenko
5
4
  #
6
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
data/test/test__helper.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- #
4
3
  # Copyright (c) 2024 Yegor Bugayenko
5
4
  #
6
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- #
4
3
  # Copyright (c) 2024 Yegor Bugayenko
5
4
  #
6
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -23,6 +22,7 @@
23
22
 
24
23
  require 'minitest/autorun'
25
24
  require 'json'
25
+ require 'nokogiri'
26
26
  require_relative '../lib/factbase'
27
27
 
28
28
  # Factbase main module test.
@@ -42,6 +42,7 @@ class TestFactbase < Minitest::Test
42
42
  found += 1
43
43
  end
44
44
  assert_equal(2, found)
45
+ assert_equal(2, fb.size)
45
46
  end
46
47
 
47
48
  def test_serialize_and_deserialize
@@ -63,4 +64,15 @@ class TestFactbase < Minitest::Test
63
64
  json = JSON.parse(fb.to_json)
64
65
  assert(42, json[0]['foo'][1])
65
66
  end
67
+
68
+ def test_to_xml
69
+ fb = Factbase.new
70
+ f = fb.insert
71
+ f.foo = 42
72
+ f.foo = 256
73
+ fb.insert
74
+ xml = Nokogiri::XML.parse(fb.to_xml)
75
+ assert(!xml.xpath('/fb[count(f) = 2]').empty?)
76
+ assert(!xml.xpath('/fb/f/foo[v="42"]').empty?)
77
+ end
66
78
  end
metadata CHANGED
@@ -1,15 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: factbase
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.7
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-11 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2024-05-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: json
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.7'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: nokogiri
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.10'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.10'
13
41
  description: Fact base in memory and on disc
14
42
  email: yegor256@gmail.com
15
43
  executables: []