mem_db 0.1.0 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +0 -1
- data/.rubocop.yml +11 -2
- data/Gemfile +3 -0
- data/lib/mem_db/field/downcase.rb +36 -0
- data/lib/mem_db/field/enum.rb +10 -16
- data/lib/mem_db/field/matching.rb +1 -1
- data/lib/mem_db/field/may_missing.rb +16 -6
- data/lib/mem_db/field/negative.rb +10 -2
- data/lib/mem_db/field/pattern.rb +11 -19
- data/lib/mem_db/field/regexp.rb +19 -23
- data/lib/mem_db/field.rb +10 -2
- data/lib/mem_db/fields.rb +8 -4
- data/lib/mem_db/idx/downcase.rb +25 -0
- data/lib/mem_db/idx.rb +4 -0
- data/lib/mem_db/indexing_object.rb +1 -3
- data/lib/mem_db/query.rb +9 -0
- data/lib/mem_db/version.rb +1 -1
- data/lib/mem_db.rb +2 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ced4d270ba624c4f0c6ef2a8bcda1b7b3f9b600d6840ec05d3f1c0cc5c82f176
|
4
|
+
data.tar.gz: f7cd1e3f65c61dcb0eada7840165f09b4028e22af31df2d295f5c4e7d2ee2a6d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f2cf1d016537298f4f0ca45b509298dc6098fded738a2018f758c1aec7ab0cfe4b05a031c1ecdf22386864da6cd7e6bff7d2e751cca19e0b778c03da8930fd1
|
7
|
+
data.tar.gz: f3a2b7025725d9592fc89d5e85d94b2fe3a2a37c77e1518eeb9f9bb16e3a7db09bd4a676a7013d6153524145cfd2288e799201b912e07073028af3398a5cf441
|
data/.rspec
CHANGED
data/.rubocop.yml
CHANGED
@@ -1,9 +1,12 @@
|
|
1
1
|
AllCops:
|
2
2
|
TargetRubyVersion: 2.5
|
3
|
+
NewCops: enable
|
3
4
|
|
4
5
|
Style/StringLiterals:
|
5
|
-
Enabled:
|
6
|
-
|
6
|
+
Enabled: false
|
7
|
+
|
8
|
+
Style/QuotedSymbols:
|
9
|
+
Enabled: false
|
7
10
|
|
8
11
|
Style/StringLiteralsInInterpolation:
|
9
12
|
Enabled: true
|
@@ -41,3 +44,9 @@ Metrics/BlockLength:
|
|
41
44
|
|
42
45
|
Metrics/MethodLength:
|
43
46
|
Enabled: false
|
47
|
+
|
48
|
+
Layout/MultilineMethodCallIndentation:
|
49
|
+
EnforcedStyle: indented
|
50
|
+
|
51
|
+
Style/MultilineBlockChain:
|
52
|
+
Enabled: false
|
data/Gemfile
CHANGED
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "mem_db/field"
|
4
|
+
require "mem_db/field/matching"
|
5
|
+
|
6
|
+
class MemDB
|
7
|
+
module Field
|
8
|
+
class Downcase
|
9
|
+
include MemDB::Field
|
10
|
+
|
11
|
+
def initialize(original)
|
12
|
+
@original = original
|
13
|
+
end
|
14
|
+
|
15
|
+
def field
|
16
|
+
@original.field
|
17
|
+
end
|
18
|
+
|
19
|
+
def query_field
|
20
|
+
@original.query_field
|
21
|
+
end
|
22
|
+
|
23
|
+
def new_matching(value)
|
24
|
+
@original.new_matching(value)
|
25
|
+
end
|
26
|
+
|
27
|
+
def field_value(obj)
|
28
|
+
@original.field_value(obj).map(&:downcase)
|
29
|
+
end
|
30
|
+
|
31
|
+
def prepare_query(obj)
|
32
|
+
@original.prepare_query(obj).map(&:downcase)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/mem_db/field/enum.rb
CHANGED
@@ -11,28 +11,24 @@ class MemDB
|
|
11
11
|
class MultiMatching
|
12
12
|
include MemDB::Field::Matching
|
13
13
|
|
14
|
-
def initialize(
|
15
|
-
@enum = enum
|
14
|
+
def initialize(arr)
|
16
15
|
@arr = arr
|
17
16
|
end
|
18
17
|
|
19
|
-
def match?(
|
20
|
-
|
21
|
-
@arr.include?(el)
|
22
|
-
end
|
18
|
+
def match?(values)
|
19
|
+
values.any? { |el| @arr.include?(el) }
|
23
20
|
end
|
24
21
|
end
|
25
22
|
|
26
23
|
class SingleMatching
|
27
24
|
include MemDB::Field::Matching
|
28
25
|
|
29
|
-
def initialize(
|
30
|
-
@enum = enum
|
26
|
+
def initialize(el)
|
31
27
|
@el = el
|
32
28
|
end
|
33
29
|
|
34
|
-
def match?(
|
35
|
-
|
30
|
+
def match?(values)
|
31
|
+
values.include?(@el)
|
36
32
|
end
|
37
33
|
end
|
38
34
|
|
@@ -42,13 +38,11 @@ class MemDB
|
|
42
38
|
@field = field
|
43
39
|
end
|
44
40
|
|
45
|
-
def new_matching(
|
46
|
-
|
47
|
-
|
48
|
-
if val.is_a?(Array)
|
49
|
-
MultiMatching.new(self, val)
|
41
|
+
def new_matching(value)
|
42
|
+
if value.is_a?(Array)
|
43
|
+
MultiMatching.new(value)
|
50
44
|
else
|
51
|
-
SingleMatching.new(
|
45
|
+
SingleMatching.new(value)
|
52
46
|
end
|
53
47
|
end
|
54
48
|
end
|
@@ -11,7 +11,7 @@ class MemDB
|
|
11
11
|
class Any
|
12
12
|
include MemDB::Field::Matching
|
13
13
|
|
14
|
-
def match?(
|
14
|
+
def match?(_values)
|
15
15
|
true
|
16
16
|
end
|
17
17
|
end
|
@@ -30,15 +30,25 @@ class MemDB
|
|
30
30
|
@original.query_field
|
31
31
|
end
|
32
32
|
|
33
|
-
def new_matching(
|
34
|
-
|
35
|
-
|
36
|
-
if v.nil?
|
33
|
+
def new_matching(value)
|
34
|
+
if value.nil?
|
37
35
|
ANY_MATCHING
|
38
36
|
else
|
39
|
-
@original.new_matching(
|
37
|
+
@original.new_matching(value)
|
40
38
|
end
|
41
39
|
end
|
40
|
+
|
41
|
+
def field_value(obj)
|
42
|
+
if obj[field].nil?
|
43
|
+
nil
|
44
|
+
else
|
45
|
+
@original.field_value(obj)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def prepare_query(obj)
|
50
|
+
@original.prepare_query(obj)
|
51
|
+
end
|
42
52
|
end
|
43
53
|
end
|
44
54
|
end
|
@@ -32,8 +32,16 @@ class MemDB
|
|
32
32
|
@original.query_field
|
33
33
|
end
|
34
34
|
|
35
|
-
def new_matching(
|
36
|
-
NegativeMatching.new(@original.new_matching(
|
35
|
+
def new_matching(value)
|
36
|
+
NegativeMatching.new(@original.new_matching(value))
|
37
|
+
end
|
38
|
+
|
39
|
+
def field_value(obj)
|
40
|
+
@original.field_value(obj)
|
41
|
+
end
|
42
|
+
|
43
|
+
def prepare_query(obj)
|
44
|
+
@original.prepare_query(obj)
|
37
45
|
end
|
38
46
|
end
|
39
47
|
end
|
data/lib/mem_db/field/pattern.rb
CHANGED
@@ -65,7 +65,7 @@ class MemDB
|
|
65
65
|
Prefix.new(source[0..-2])
|
66
66
|
elsif source.start_with?(WILDCARD)
|
67
67
|
Suffix.new(source[1..-1])
|
68
|
-
else
|
68
|
+
else # rubocop:disable Lint/DuplicateBranch
|
69
69
|
Rx.new(source)
|
70
70
|
end
|
71
71
|
end
|
@@ -78,30 +78,24 @@ class MemDB
|
|
78
78
|
class MultiMatching
|
79
79
|
include MemDB::Field::Matching
|
80
80
|
|
81
|
-
def initialize(
|
82
|
-
@f = f
|
81
|
+
def initialize(arr)
|
83
82
|
@patterns = arr.map { |source| Pattern.new(source) }
|
84
83
|
end
|
85
84
|
|
86
|
-
def match?(
|
87
|
-
@
|
88
|
-
return true if @patterns.any? { |pat| pat.match?(str) }
|
89
|
-
end
|
90
|
-
|
91
|
-
false
|
85
|
+
def match?(values)
|
86
|
+
values.any? { |str| @patterns.any? { |pat| pat.match?(str) } }
|
92
87
|
end
|
93
88
|
end
|
94
89
|
|
95
90
|
class SingleMatching
|
96
91
|
include MemDB::Field::Matching
|
97
92
|
|
98
|
-
def initialize(
|
99
|
-
@f = f
|
93
|
+
def initialize(el)
|
100
94
|
@pat = Pattern.new(el)
|
101
95
|
end
|
102
96
|
|
103
|
-
def match?(
|
104
|
-
|
97
|
+
def match?(values)
|
98
|
+
values.any? { |str| @pat.match?(str) }
|
105
99
|
end
|
106
100
|
end
|
107
101
|
|
@@ -111,13 +105,11 @@ class MemDB
|
|
111
105
|
@field = field
|
112
106
|
end
|
113
107
|
|
114
|
-
def new_matching(
|
115
|
-
|
116
|
-
|
117
|
-
if val.is_a?(Array)
|
118
|
-
MultiMatching.new(self, val)
|
108
|
+
def new_matching(value)
|
109
|
+
if value.is_a?(Array)
|
110
|
+
MultiMatching.new(value)
|
119
111
|
else
|
120
|
-
SingleMatching.new(
|
112
|
+
SingleMatching.new(value)
|
121
113
|
end
|
122
114
|
end
|
123
115
|
end
|
data/lib/mem_db/field/regexp.rb
CHANGED
@@ -9,8 +9,11 @@ class MemDB
|
|
9
9
|
include MemDB::Field
|
10
10
|
|
11
11
|
class Rx
|
12
|
-
def initialize(source)
|
13
|
-
|
12
|
+
def initialize(source, ignore_case:)
|
13
|
+
opts = ::Regexp::MULTILINE
|
14
|
+
opts |= ::Regexp::IGNORECASE if ignore_case
|
15
|
+
|
16
|
+
@rx = ::Regexp.new(source, opts)
|
14
17
|
end
|
15
18
|
|
16
19
|
def match?(str)
|
@@ -21,46 +24,39 @@ class MemDB
|
|
21
24
|
class MultiMatching
|
22
25
|
include MemDB::Field::Matching
|
23
26
|
|
24
|
-
def initialize(
|
25
|
-
@
|
26
|
-
@patterns = arr.map { |source| Rx.new(source) }
|
27
|
+
def initialize(arr, ignore_case:)
|
28
|
+
@patterns = arr.map { |source| Rx.new(source, ignore_case: ignore_case) }
|
27
29
|
end
|
28
30
|
|
29
|
-
def match?(
|
30
|
-
@
|
31
|
-
return true if @patterns.any? { |pat| pat.match?(str) }
|
32
|
-
end
|
33
|
-
|
34
|
-
false
|
31
|
+
def match?(values)
|
32
|
+
values.any? { |str| @patterns.any? { |pat| pat.match?(str) } }
|
35
33
|
end
|
36
34
|
end
|
37
35
|
|
38
36
|
class SingleMatching
|
39
37
|
include MemDB::Field::Matching
|
40
38
|
|
41
|
-
def initialize(
|
42
|
-
@
|
43
|
-
@pat = Rx.new(el)
|
39
|
+
def initialize(el, ignore_case:)
|
40
|
+
@pat = Rx.new(el, ignore_case: ignore_case)
|
44
41
|
end
|
45
42
|
|
46
|
-
def match?(
|
47
|
-
|
43
|
+
def match?(values)
|
44
|
+
values.any? { |str| @pat.match?(str) }
|
48
45
|
end
|
49
46
|
end
|
50
47
|
|
51
48
|
attr_reader :field
|
52
49
|
|
53
|
-
def initialize(field)
|
50
|
+
def initialize(field, ignore_case: false)
|
54
51
|
@field = field
|
52
|
+
@ignore_case = ignore_case
|
55
53
|
end
|
56
54
|
|
57
|
-
def new_matching(
|
58
|
-
|
59
|
-
|
60
|
-
if val.is_a?(Array)
|
61
|
-
MultiMatching.new(self, val)
|
55
|
+
def new_matching(value)
|
56
|
+
if value.is_a?(Array)
|
57
|
+
MultiMatching.new(value, ignore_case: @ignore_case)
|
62
58
|
else
|
63
|
-
SingleMatching.new(
|
59
|
+
SingleMatching.new(value, ignore_case: @ignore_case)
|
64
60
|
end
|
65
61
|
end
|
66
62
|
end
|
data/lib/mem_db/field.rb
CHANGED
@@ -10,6 +10,10 @@ class MemDB
|
|
10
10
|
MemDB::Field::Negative.new(self)
|
11
11
|
end
|
12
12
|
|
13
|
+
def downcase
|
14
|
+
MemDB::Field::Downcase.new(self)
|
15
|
+
end
|
16
|
+
|
13
17
|
def field
|
14
18
|
raise NotImplementedError, "#{self.class} has not implemented method '#{__method__}'"
|
15
19
|
end
|
@@ -23,11 +27,15 @@ class MemDB
|
|
23
27
|
@query_field || field
|
24
28
|
end
|
25
29
|
|
26
|
-
def new_matching(
|
30
|
+
def new_matching(_value)
|
27
31
|
raise NotImplementedError, "#{self.class} has not implemented method '#{__method__}'"
|
28
32
|
end
|
29
33
|
|
30
|
-
def
|
34
|
+
def field_value(obj)
|
35
|
+
obj[field]
|
36
|
+
end
|
37
|
+
|
38
|
+
def prepare_query(query)
|
31
39
|
query[query_field]
|
32
40
|
end
|
33
41
|
end
|
data/lib/mem_db/fields.rb
CHANGED
@@ -4,13 +4,17 @@ class MemDB
|
|
4
4
|
class Fields
|
5
5
|
class Matching
|
6
6
|
def initialize(fields, obj)
|
7
|
-
@matchings = fields
|
8
|
-
|
9
|
-
|
7
|
+
@matchings = fields
|
8
|
+
.map do |field|
|
9
|
+
[field, field.new_matching(field.field_value(obj))]
|
10
|
+
end
|
11
|
+
.reject! do |_field, matching|
|
12
|
+
matching == MemDB::Field::MayMissing::ANY_MATCHING
|
13
|
+
end
|
10
14
|
end
|
11
15
|
|
12
16
|
def match?(query)
|
13
|
-
@matchings.all? { |matching| matching.match?(query) }
|
17
|
+
@matchings.all? { |field, matching| matching.match?(query.field_value(field)) }
|
14
18
|
end
|
15
19
|
end
|
16
20
|
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class MemDB
|
4
|
+
module Idx
|
5
|
+
class Downcase
|
6
|
+
include MemDB::Idx
|
7
|
+
|
8
|
+
def initialize(original)
|
9
|
+
@original = original
|
10
|
+
end
|
11
|
+
|
12
|
+
def field
|
13
|
+
@original.field
|
14
|
+
end
|
15
|
+
|
16
|
+
def map_value(str)
|
17
|
+
@original.map_value(str.downcase)
|
18
|
+
end
|
19
|
+
|
20
|
+
def map_query(str)
|
21
|
+
@original.map_query(str.downcase)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/mem_db/idx.rb
CHANGED
data/lib/mem_db/query.rb
CHANGED
@@ -6,6 +6,7 @@ class MemDB
|
|
6
6
|
@params = params
|
7
7
|
@attrs = {}
|
8
8
|
@idx_value = {}
|
9
|
+
@field_value = {}
|
9
10
|
end
|
10
11
|
|
11
12
|
def using(index)
|
@@ -37,6 +38,14 @@ class MemDB
|
|
37
38
|
end
|
38
39
|
end
|
39
40
|
|
41
|
+
def field_value(field)
|
42
|
+
if @field_value.key?(field)
|
43
|
+
@field_value[field]
|
44
|
+
else
|
45
|
+
@field_value[field] ||= field.prepare_query(self)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
40
49
|
def prepare_attr(attr)
|
41
50
|
v = @params[attr]
|
42
51
|
if v.is_a?(Array)
|
data/lib/mem_db/version.rb
CHANGED
data/lib/mem_db.rb
CHANGED
@@ -86,6 +86,7 @@ require_relative "mem_db/idx/reverse"
|
|
86
86
|
require_relative "mem_db/idx/uniq"
|
87
87
|
require_relative "mem_db/idx/pattern"
|
88
88
|
require_relative "mem_db/idx/default"
|
89
|
+
require_relative "mem_db/idx/downcase"
|
89
90
|
|
90
91
|
require_relative "mem_db/index/bucket"
|
91
92
|
require_relative "mem_db/index/any"
|
@@ -100,3 +101,4 @@ require_relative "mem_db/field/negative"
|
|
100
101
|
require_relative "mem_db/field/enum"
|
101
102
|
require_relative "mem_db/field/pattern"
|
102
103
|
require_relative "mem_db/field/regexp"
|
104
|
+
require_relative "mem_db/field/downcase"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mem_db
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dmitry Bochkarev
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-10-12 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: MemDB is embedded database
|
14
14
|
email:
|
@@ -30,6 +30,7 @@ files:
|
|
30
30
|
- lib/mem_db.rb
|
31
31
|
- lib/mem_db/bucket.rb
|
32
32
|
- lib/mem_db/field.rb
|
33
|
+
- lib/mem_db/field/downcase.rb
|
33
34
|
- lib/mem_db/field/enum.rb
|
34
35
|
- lib/mem_db/field/matching.rb
|
35
36
|
- lib/mem_db/field/may_missing.rb
|
@@ -41,6 +42,7 @@ files:
|
|
41
42
|
- lib/mem_db/idx/bytes.rb
|
42
43
|
- lib/mem_db/idx/chars.rb
|
43
44
|
- lib/mem_db/idx/default.rb
|
45
|
+
- lib/mem_db/idx/downcase.rb
|
44
46
|
- lib/mem_db/idx/itself.rb
|
45
47
|
- lib/mem_db/idx/pattern.rb
|
46
48
|
- lib/mem_db/idx/reverse.rb
|