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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 450fac8896504841b9ed4dcc1f8846c077678aa00f6e046377f0aaf1d9d5bca8
4
- data.tar.gz: 66d1c2585c68faafc4949d41e5112ba798f16d985fd7e557c1c154ee34b294b0
3
+ metadata.gz: 3420398f6bb70d1972fe648bc4a880ac64bbc08d43cad850109b60a11cee4c38
4
+ data.tar.gz: 170a4ef45eaa1ebdb23b12abfa7d142792a33cbad1383c0470c2cabcfc202e2c
5
5
  SHA512:
6
- metadata.gz: 829181d98d91b0d32fd9a95bca2991a908a8f0f25238e4d185b94c28fa83c543b9d0092d347bf5204add4212fc225eaa520a35697afb2634ccef4a487c5f60ff
7
- data.tar.gz: c340dc530f656b75a33e5becfc7fe9562ff08a1c3f7b36a30f8f2614146d5480f804ab85e041c7e4cd0de32ef5e66d20c5a5e2f5cbb0a7dcedd67db3b81e6801
6
+ metadata.gz: e633c361b62356812fcce2fcdab642b3678d444c063fe06497644146e3ad02fddfa5927664418c0bbdaf7b89c3835a8d8118bcca1b8e3cb92e9eeaeac823c739
7
+ data.tar.gz: 4ae7c3394bb79a1535f5eac8625b18ccbfd4f318a54e855e94dbe25584e46cb7e8d979beed88a06736d5131da73d4cebb481315e378217b5c74049d272d78ed0
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fmcache (0.1.2)
4
+ fmcache (0.1.3)
5
5
  field_mask_parser (~> 0.4.2)
6
6
 
7
7
  GEM
@@ -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.map(&:to_s))
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 cach of id does not exist, treat current and lower
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 user
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 [String] h
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)
@@ -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
@@ -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).map(&:to_s)
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
@@ -1,6 +1,9 @@
1
1
  module FMCache
2
2
  class Field
3
3
  class << self
4
+ # @param [<Symbol>] prefix
5
+ # @param [Symbol] attr
6
+ # @return [String]
4
7
  def to_s(prefix:, attr:)
5
8
  l = prefix + [attr]
6
9
  l.join(".")
@@ -2,6 +2,7 @@ module FMCache
2
2
  class Helper
3
3
  class << self
4
4
  # @param [FieldMaskParser::Node] field_mask
5
+ # @param [<Symbol>] prefix
5
6
  # @return [<String>]
6
7
  def to_fields(field_mask, prefix: [])
7
8
  field_mask.to_paths(prefix: prefix, sort: false)
@@ -1,3 +1,3 @@
1
1
  module FMCache
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fmcache
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nao Minami