fmcache 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/fmcache/decoder.rb +4 -1
- data/lib/fmcache/decoder/fields_checker.rb +1 -1
- data/lib/fmcache/decoder/value_decoder.rb +6 -3
- data/lib/fmcache/encoder.rb +3 -7
- data/lib/fmcache/engine.rb +9 -1
- data/lib/fmcache/field.rb +3 -0
- data/lib/fmcache/helper.rb +1 -0
- data/lib/fmcache/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3420398f6bb70d1972fe648bc4a880ac64bbc08d43cad850109b60a11cee4c38
|
4
|
+
data.tar.gz: 170a4ef45eaa1ebdb23b12abfa7d142792a33cbad1383c0470c2cabcfc202e2c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e633c361b62356812fcce2fcdab642b3678d444c063fe06497644146e3ad02fddfa5927664418c0bbdaf7b89c3835a8d8118bcca1b8e3cb92e9eeaeac823c739
|
7
|
+
data.tar.gz: 4ae7c3394bb79a1535f5eac8625b18ccbfd4f318a54e855e94dbe25584e46cb7e8d979beed88a06736d5131da73d4cebb481315e378217b5c74049d272d78ed0
|
data/Gemfile.lock
CHANGED
data/lib/fmcache/decoder.rb
CHANGED
@@ -32,12 +32,14 @@ module FMCache
|
|
32
32
|
|
33
33
|
# @param [<Hash>] list
|
34
34
|
# @param [FieldMaskParser::Node] field_mask
|
35
|
+
# @param [<String>] fields
|
36
|
+
# @return [DecodeResult]
|
35
37
|
def decode_list(list, field_mask: nil, fields: nil)
|
36
38
|
if field_mask.nil? && fields.nil?
|
37
39
|
raise "invalid args!"
|
38
40
|
end
|
39
41
|
if fields
|
40
|
-
field_mask = field_mask_parser.call(fields
|
42
|
+
field_mask = field_mask_parser.call(fields)
|
41
43
|
end
|
42
44
|
|
43
45
|
values = []
|
@@ -61,6 +63,7 @@ module FMCache
|
|
61
63
|
)
|
62
64
|
end
|
63
65
|
|
66
|
+
# @param [FieldsChecker::CheckResult] decode_result
|
64
67
|
# @param [DecodeResult] decode_result
|
65
68
|
# @param [DecodeResult] invalid_decode_result
|
66
69
|
# @return [<Hash>, <Hash>, IncompleteInfo]
|
@@ -60,7 +60,7 @@ module FMCache
|
|
60
60
|
missing_fields += m_f
|
61
61
|
end
|
62
62
|
else
|
63
|
-
# NOTE: When the
|
63
|
+
# NOTE: When the cache of id does not exist, treat current and lower
|
64
64
|
# layer as missing fields
|
65
65
|
# TODO(south37) Improve performance
|
66
66
|
missing_fields += fields
|
@@ -13,7 +13,7 @@ module FMCache
|
|
13
13
|
|
14
14
|
h = fetch(field_mask, [])
|
15
15
|
|
16
|
-
d = h.values.first # NOTE: Top of h is a
|
16
|
+
d = h.values.first # NOTE: Top of h is a hash
|
17
17
|
|
18
18
|
[d.to_h, @invalid_fields]
|
19
19
|
end
|
@@ -53,6 +53,8 @@ module FMCache
|
|
53
53
|
r
|
54
54
|
end
|
55
55
|
|
56
|
+
# @param [FieldMaskParser::Node] field_mask
|
57
|
+
# @param [<Symbol>] prefix
|
56
58
|
def fetch_items(field_mask, prefix)
|
57
59
|
r = {}
|
58
60
|
field_mask.attrs.each do |attr|
|
@@ -66,14 +68,15 @@ module FMCache
|
|
66
68
|
r
|
67
69
|
end
|
68
70
|
|
69
|
-
# @param [
|
71
|
+
# @param [<Hash>] h
|
72
|
+
# @return [<Item>]
|
70
73
|
def itemize(h)
|
71
74
|
h.map do |hh|
|
72
75
|
Item.new(id: hh.fetch(:id), p_id: hh.fetch(:p_id), value: hh.fetch(:value))
|
73
76
|
end
|
74
77
|
end
|
75
78
|
|
76
|
-
# @param [{ Integer => Data }]
|
79
|
+
# @param [{ Integer => Data }] parents
|
77
80
|
# @param [FieldMaskParser::Node] field_mask
|
78
81
|
# @param [<Symbol>] prefix
|
79
82
|
def assign_has_one!(parents, field_mask, prefix)
|
data/lib/fmcache/encoder.rb
CHANGED
@@ -6,19 +6,15 @@ module FMCache
|
|
6
6
|
# @param [FieldMaskParser::Node] field_mask
|
7
7
|
# @return [{ String => { String => <Hash> } }]
|
8
8
|
def encode(values, field_mask)
|
9
|
+
fields = Helper.to_fields(field_mask)
|
10
|
+
|
9
11
|
r = {}
|
10
12
|
values.each do |value|
|
11
13
|
h = {}
|
12
|
-
|
13
|
-
# NOTE: initialize each field by array
|
14
|
-
fields = Helper.to_fields(field_mask).map(&:to_s)
|
15
14
|
fields.each do |f|
|
16
15
|
h[f] = []
|
17
16
|
end
|
18
|
-
|
19
|
-
encode_one(value, field_mask).each do |f, v|
|
20
|
-
h[f] = v
|
21
|
-
end
|
17
|
+
h.merge! encode_one(value, field_mask)
|
22
18
|
|
23
19
|
id = value.fetch(:id)
|
24
20
|
r[Helper.to_key(id)] = h
|
data/lib/fmcache/engine.rb
CHANGED
@@ -3,6 +3,10 @@ module FMCache
|
|
3
3
|
DEFAULT_TTL = 7 * 24 * 3600 # 7 days
|
4
4
|
|
5
5
|
# @param [Redis | MockRRedis] client
|
6
|
+
# @param [Proc] fm_parser
|
7
|
+
# @param [Integer] ttl
|
8
|
+
# @param [Proc] notifier
|
9
|
+
# @param [#dump#load] json_serializer
|
6
10
|
def initialize(client:, fm_parser:, ttl: DEFAULT_TTL, notifier: nil, json_serializer: nil)
|
7
11
|
@client = Client.new(client, notifier)
|
8
12
|
@fm_parser = wrap(fm_parser)
|
@@ -31,7 +35,7 @@ module FMCache
|
|
31
35
|
normalize!(field_mask)
|
32
36
|
|
33
37
|
keys = Helper.to_keys(ids)
|
34
|
-
fields = Helper.to_fields(field_mask)
|
38
|
+
fields = Helper.to_fields(field_mask)
|
35
39
|
h = client.get(keys: keys, fields: fields)
|
36
40
|
decode(merge(@jsonizer.dejsonize(h), ids), field_mask)
|
37
41
|
end
|
@@ -66,6 +70,7 @@ module FMCache
|
|
66
70
|
Helper.sort(values + v + i_v, ids)
|
67
71
|
end
|
68
72
|
|
73
|
+
# @param [<Integer | String>] ids
|
69
74
|
def delete(ids:)
|
70
75
|
ids = ids.map(&:to_i)
|
71
76
|
client.del(keys: Helper.to_keys(ids))
|
@@ -99,6 +104,8 @@ module FMCache
|
|
99
104
|
hash
|
100
105
|
end
|
101
106
|
|
107
|
+
# @param [Proc] fm_parser
|
108
|
+
# @return [Proc]
|
102
109
|
def wrap(fm_parser)
|
103
110
|
-> (fields) {
|
104
111
|
n = fm_parser.call(fields)
|
@@ -107,6 +114,7 @@ module FMCache
|
|
107
114
|
}
|
108
115
|
end
|
109
116
|
|
117
|
+
# @param [FieldMaskParser::Node] field_mask
|
110
118
|
def normalize!(field_mask)
|
111
119
|
if !field_mask.attrs.include?(:id)
|
112
120
|
field_mask.attrs << :id
|
data/lib/fmcache/field.rb
CHANGED
data/lib/fmcache/helper.rb
CHANGED
data/lib/fmcache/version.rb
CHANGED