mem_db 0.1.2 → 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 +4 -4
- data/.github/workflows/main.yml +13 -11
- data/.gitignore +1 -0
- data/README.md +2 -0
- data/lib/mem_db/field/pattern.rb +15 -13
- data/lib/mem_db/field/regexp.rb +9 -20
- data/lib/mem_db/regexp_engines/re2.rb +27 -0
- data/lib/mem_db/regexp_engines/std.rb +22 -0
- data/lib/mem_db/version.rb +1 -1
- data/mem_db.gemspec +3 -0
- metadata +21 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6677c31b83e454180efbaa876609843d9ac236c3c1c1bd0a2afafe802fce9e14
|
4
|
+
data.tar.gz: fd81a60ecd058c8663436b604bba25dc3368207e2e421d8bef73448cc23f8a3d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eca7be3316c79f6c1e56d33d749f449c65b19c41efa41a1c0744f6fea49b95c8c68feb5d9a67ca1e71bdaf9be542cc75b2dc84acfab087941bfcce3ae2dd5c0f
|
7
|
+
data.tar.gz: 5b6c349a53a7ab39b17ec929e382bf6079c0c25380b246a80ae3b22db8e450d232328268105ae368fcd25abf4b354dc4eee1c47a53f8cd722724b66b01353316
|
data/.github/workflows/main.yml
CHANGED
@@ -1,18 +1,20 @@
|
|
1
1
|
name: Ruby
|
2
2
|
|
3
|
-
on: [push,pull_request]
|
3
|
+
on: [push, pull_request]
|
4
4
|
|
5
5
|
jobs:
|
6
6
|
build:
|
7
7
|
runs-on: ubuntu-latest
|
8
8
|
steps:
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
9
|
+
- uses: actions/checkout@v2
|
10
|
+
- name: Set up Ruby
|
11
|
+
uses: ruby/setup-ruby@v1
|
12
|
+
with:
|
13
|
+
ruby-version: 2.5.5
|
14
|
+
- name: Install dependencies
|
15
|
+
run: |
|
16
|
+
sudo apt-get install libre2-dev
|
17
|
+
gem install bundler -v 2.2.5
|
18
|
+
bundle install
|
19
|
+
- name: Run
|
20
|
+
run: bundle exec rake
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -88,6 +88,8 @@ MemDB::Query.new({
|
|
88
88
|
|
89
89
|
## Development
|
90
90
|
|
91
|
+
To support the regular expression engine re2. It is necessary to install the corresponding system library. See [instructions for re2 gem](https://github.com/mudge/re2#installation)
|
92
|
+
|
91
93
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
92
94
|
|
93
95
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
data/lib/mem_db/field/pattern.rb
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require "mem_db/field"
|
4
4
|
require "mem_db/field/matching"
|
5
|
+
require "mem_db/regexp_engines/std"
|
5
6
|
|
6
7
|
class MemDB
|
7
8
|
module Field
|
@@ -12,11 +13,11 @@ class MemDB
|
|
12
13
|
WILDCARD = "*"
|
13
14
|
|
14
15
|
class Rx
|
15
|
-
def initialize(source)
|
16
|
-
parts = source.split(WILDCARD, -1).map { |part|
|
16
|
+
def initialize(source, engine)
|
17
|
+
parts = source.split(WILDCARD, -1).map { |part| engine.quote(part) }
|
17
18
|
parts[0] = "\\A#{parts[0]}"
|
18
19
|
parts[-1] = "#{parts[-1]}\\z"
|
19
|
-
@rx =
|
20
|
+
@rx = engine.new(parts.join(".*"))
|
20
21
|
end
|
21
22
|
|
22
23
|
def match?(str)
|
@@ -54,19 +55,19 @@ class MemDB
|
|
54
55
|
end
|
55
56
|
end
|
56
57
|
|
57
|
-
def initialize(source)
|
58
|
+
def initialize(source, rx_engine:)
|
58
59
|
wildcard_count = source.count(WILDCARD)
|
59
60
|
@pat =
|
60
61
|
if wildcard_count.zero?
|
61
62
|
Exact.new(source)
|
62
63
|
elsif wildcard_count > 1
|
63
|
-
Rx.new(source)
|
64
|
+
Rx.new(source, rx_engine)
|
64
65
|
elsif source.end_with?(WILDCARD)
|
65
66
|
Prefix.new(source[0..-2])
|
66
67
|
elsif source.start_with?(WILDCARD)
|
67
68
|
Suffix.new(source[1..-1])
|
68
69
|
else # rubocop:disable Lint/DuplicateBranch
|
69
|
-
Rx.new(source)
|
70
|
+
Rx.new(source, rx_engine)
|
70
71
|
end
|
71
72
|
end
|
72
73
|
|
@@ -78,8 +79,8 @@ class MemDB
|
|
78
79
|
class MultiMatching
|
79
80
|
include MemDB::Field::Matching
|
80
81
|
|
81
|
-
def initialize(arr)
|
82
|
-
@patterns = arr.map { |source| Pattern.new(source) }
|
82
|
+
def initialize(arr, rx_engine:)
|
83
|
+
@patterns = arr.map { |source| Pattern.new(source, rx_engine: rx_engine) }
|
83
84
|
end
|
84
85
|
|
85
86
|
def match?(values)
|
@@ -90,8 +91,8 @@ class MemDB
|
|
90
91
|
class SingleMatching
|
91
92
|
include MemDB::Field::Matching
|
92
93
|
|
93
|
-
def initialize(el)
|
94
|
-
@pat = Pattern.new(el)
|
94
|
+
def initialize(el, rx_engine:)
|
95
|
+
@pat = Pattern.new(el, rx_engine: rx_engine)
|
95
96
|
end
|
96
97
|
|
97
98
|
def match?(values)
|
@@ -101,15 +102,16 @@ class MemDB
|
|
101
102
|
|
102
103
|
attr_reader :field
|
103
104
|
|
104
|
-
def initialize(field)
|
105
|
+
def initialize(field, rx_engine: MemDB::RegexpEngines::Std)
|
105
106
|
@field = field
|
107
|
+
@rx_engine = rx_engine
|
106
108
|
end
|
107
109
|
|
108
110
|
def new_matching(value)
|
109
111
|
if value.is_a?(Array)
|
110
|
-
MultiMatching.new(value)
|
112
|
+
MultiMatching.new(value, rx_engine: @rx_engine)
|
111
113
|
else
|
112
|
-
SingleMatching.new(value)
|
114
|
+
SingleMatching.new(value, rx_engine: @rx_engine)
|
113
115
|
end
|
114
116
|
end
|
115
117
|
end
|
data/lib/mem_db/field/regexp.rb
CHANGED
@@ -2,30 +2,18 @@
|
|
2
2
|
|
3
3
|
require "mem_db/field"
|
4
4
|
require "mem_db/field/matching"
|
5
|
+
require "mem_db/regexp_engines/std"
|
5
6
|
|
6
7
|
class MemDB
|
7
8
|
module Field
|
8
9
|
class Regexp
|
9
10
|
include MemDB::Field
|
10
11
|
|
11
|
-
class Rx
|
12
|
-
def initialize(source, ignore_case:)
|
13
|
-
opts = ::Regexp::MULTILINE
|
14
|
-
opts |= ::Regexp::IGNORECASE if ignore_case
|
15
|
-
|
16
|
-
@rx = ::Regexp.new(source, opts)
|
17
|
-
end
|
18
|
-
|
19
|
-
def match?(str)
|
20
|
-
@rx.match?(str)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
12
|
class MultiMatching
|
25
13
|
include MemDB::Field::Matching
|
26
14
|
|
27
|
-
def initialize(arr, ignore_case:)
|
28
|
-
@patterns = arr.map { |source|
|
15
|
+
def initialize(arr, rx_engine:, ignore_case:)
|
16
|
+
@patterns = arr.map { |source| rx_engine.new(source, ignore_case: ignore_case) }
|
29
17
|
end
|
30
18
|
|
31
19
|
def match?(values)
|
@@ -36,8 +24,8 @@ class MemDB
|
|
36
24
|
class SingleMatching
|
37
25
|
include MemDB::Field::Matching
|
38
26
|
|
39
|
-
def initialize(el, ignore_case:)
|
40
|
-
@pat =
|
27
|
+
def initialize(el, rx_engine:, ignore_case:)
|
28
|
+
@pat = rx_engine.new(el, ignore_case: ignore_case)
|
41
29
|
end
|
42
30
|
|
43
31
|
def match?(values)
|
@@ -47,16 +35,17 @@ class MemDB
|
|
47
35
|
|
48
36
|
attr_reader :field
|
49
37
|
|
50
|
-
def initialize(field, ignore_case: false)
|
38
|
+
def initialize(field, rx_engine: MemDB::RegexpEngines::Std, ignore_case: false)
|
51
39
|
@field = field
|
40
|
+
@rx_engine = rx_engine
|
52
41
|
@ignore_case = ignore_case
|
53
42
|
end
|
54
43
|
|
55
44
|
def new_matching(value)
|
56
45
|
if value.is_a?(Array)
|
57
|
-
MultiMatching.new(value, ignore_case: @ignore_case)
|
46
|
+
MultiMatching.new(value, rx_engine: @rx_engine, ignore_case: @ignore_case)
|
58
47
|
else
|
59
|
-
SingleMatching.new(value, ignore_case: @ignore_case)
|
48
|
+
SingleMatching.new(value, rx_engine: @rx_engine, ignore_case: @ignore_case)
|
60
49
|
end
|
61
50
|
end
|
62
51
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "re2"
|
4
|
+
|
5
|
+
class MemDB
|
6
|
+
module RegexpEngines
|
7
|
+
class Re2
|
8
|
+
def self.quote(str)
|
9
|
+
::RE2::Regexp.quote(str)
|
10
|
+
end
|
11
|
+
|
12
|
+
def initialize(source, ignore_case: false)
|
13
|
+
opts = {
|
14
|
+
one_line: false
|
15
|
+
}
|
16
|
+
opts[:case_sensitive] = false if ignore_case
|
17
|
+
multiline_source = "(?s:#{source})"
|
18
|
+
|
19
|
+
@rx = ::RE2::Regexp.new(multiline_source, **opts)
|
20
|
+
end
|
21
|
+
|
22
|
+
def match?(str)
|
23
|
+
@rx.match?(str)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class MemDB
|
4
|
+
module RegexpEngines
|
5
|
+
class Std
|
6
|
+
def self.quote(str)
|
7
|
+
::Regexp.quote(str)
|
8
|
+
end
|
9
|
+
|
10
|
+
def initialize(source, ignore_case: false)
|
11
|
+
opts = ::Regexp::MULTILINE
|
12
|
+
opts |= ::Regexp::IGNORECASE if ignore_case
|
13
|
+
|
14
|
+
@rx = ::Regexp.new(source, opts)
|
15
|
+
end
|
16
|
+
|
17
|
+
def match?(str)
|
18
|
+
@rx.match?(str)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/mem_db/version.rb
CHANGED
data/mem_db.gemspec
CHANGED
@@ -16,10 +16,13 @@ Gem::Specification.new do |spec|
|
|
16
16
|
|
17
17
|
spec.metadata["homepage_uri"] = spec.homepage
|
18
18
|
spec.metadata["source_code_uri"] = "https://github.com/DmitryBochkarev/mem_db"
|
19
|
+
spec.metadata['rubygems_mfa_required'] = "true"
|
19
20
|
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
20
21
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
|
21
22
|
end
|
22
23
|
spec.bindir = "exe"
|
23
24
|
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
24
25
|
spec.require_paths = ["lib"]
|
26
|
+
|
27
|
+
spec.add_development_dependency "re2", ">= 1.4.0"
|
25
28
|
end
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mem_db
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dmitry Bochkarev
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
12
|
-
dependencies:
|
11
|
+
date: 2022-01-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: re2
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.4.0
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.4.0
|
13
27
|
description: MemDB is embedded database
|
14
28
|
email:
|
15
29
|
- dimabochkarev@gmail.com
|
@@ -58,6 +72,8 @@ files:
|
|
58
72
|
- lib/mem_db/indexing_object.rb
|
59
73
|
- lib/mem_db/out.rb
|
60
74
|
- lib/mem_db/query.rb
|
75
|
+
- lib/mem_db/regexp_engines/re2.rb
|
76
|
+
- lib/mem_db/regexp_engines/std.rb
|
61
77
|
- lib/mem_db/version.rb
|
62
78
|
- mem_db.gemspec
|
63
79
|
homepage: https://github.com/DmitryBochkarev/mem_db
|
@@ -66,6 +82,7 @@ licenses:
|
|
66
82
|
metadata:
|
67
83
|
homepage_uri: https://github.com/DmitryBochkarev/mem_db
|
68
84
|
source_code_uri: https://github.com/DmitryBochkarev/mem_db
|
85
|
+
rubygems_mfa_required: 'true'
|
69
86
|
post_install_message:
|
70
87
|
rdoc_options: []
|
71
88
|
require_paths:
|
@@ -81,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
81
98
|
- !ruby/object:Gem::Version
|
82
99
|
version: '0'
|
83
100
|
requirements: []
|
84
|
-
rubygems_version: 3.
|
101
|
+
rubygems_version: 3.3.3
|
85
102
|
signing_key:
|
86
103
|
specification_version: 4
|
87
104
|
summary: MemDB is embedded database
|