http_store 0.3.6 → 0.3.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: cc0c7e35bf11a61949db7691bb74a8256947e0e6c27ea7b26dbffe41db50d547
4
- data.tar.gz: 85c15402f5309d4134beb54558334bf91a0f2068b9d67bc2f62fd2468d54ded1
3
+ metadata.gz: 13a85e318867138cd3a9179f389281b76f045a3f227bb62be21e293c383d3d09
4
+ data.tar.gz: 9377610891824c3013c519fd28a7377063b4b3eb89376bb7535a5e8ab9cb5dd0
5
5
  SHA512:
6
- metadata.gz: babd6761df2ca0da813c5c2a08b7b684480fbc6c65f53d48587db8eaae5f7c2f5d1a9412f4871607d3e72ae216f65122f601f012691d635524f291d88926853f
7
- data.tar.gz: d717a172a03c4c959f6b3ea285eed5361c7c54d15c6ab8ec31ca852e6e4513b66e6c2987a2e3d5ac33fb5c3f5288128e03138f6b288734c451eed502617ec9b9
6
+ metadata.gz: 9cc6c6fb3481294ef589d2bfe2505edc3c14e3aff164ea7db755d704c0287a68919baf48cf11e6f11b940d37d915c7762f2584e549a7ebe5579a05f2c06f1230
7
+ data.tar.gz: 3ef74302c890bf5b32dcabab68c925e49fa44f27ca0fd77b42c05237b7b357236cf3db4e830413cb47257fc2da37fae608fe831ea808305658f002d79a176e86
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- http_store (0.3.6)
4
+ http_store (0.3.7)
5
5
  activerecord (>= 5.0, < 6.1)
6
6
  hashie (~> 3.0)
7
7
  rails (>= 5, < 7)
@@ -17,7 +17,7 @@ module HttpStore
17
17
  return unless request_valid?
18
18
 
19
19
  # exist request or not force, return
20
- load_storeable_record and return if !force && storeable_record.present?
20
+ load_storeable_record and return if use_cache?
21
21
 
22
22
  execute # send request
23
23
  raise HttpStore::RequestError, 'response_obj is nil' if response_obj.nil?
@@ -65,10 +65,6 @@ module HttpStore
65
65
  e.response
66
66
  # :nocov:
67
67
  end
68
-
69
- def json_safe_parse(str)
70
- JSON.parse(str) rescue str
71
- end
72
68
  end
73
69
  end
74
70
 
@@ -6,7 +6,7 @@ module HttpStore
6
6
  def storeable_record
7
7
  return unless HttpStore.config.store_enable
8
8
 
9
- @storeable_record ||= HttpStore.config.store_class.find_by(request_digest: request_digest, response_valid: true)
9
+ @storeable_record ||= HttpStore.config.store_class.find_by(request_digest: @meta.request_digest, response_valid: true)
10
10
  end
11
11
 
12
12
  def load_storeable_record
@@ -14,21 +14,24 @@ module HttpStore
14
14
 
15
15
  attrs =
16
16
  storeable_record.attributes.slice(*HttpStore::ALL_KEYS).map do |k, v|
17
- [k, v.is_a?(String) ? re_storable(v) : v]
17
+ [k, v.is_a?(String) ? json_safe_parse(v) : v]
18
18
  end.to_h
19
19
 
20
- @meta.parent_id = storeable_record.id
21
20
  @meta.reverse_merge! attrs
21
+ @meta.parent_id = storeable_record.id
22
22
  end
23
23
 
24
24
  # you can rewrite this callback, to store the request
25
25
  def store_request
26
26
  return unless HttpStore.config.store_enable
27
27
 
28
- @parent_storeable_record = storeable_record
29
- @storeable_record = HttpStore.config.store_class.new(storable_meta)
30
- @storeable_record.parent = @parent_storeable_record if @parent_storeable_record.present?
31
- save!
28
+ @meta.parent_id = storeable_record.id if use_cache?
29
+ @storeable_record = HttpStore.config.store_class.new(storable_meta)
30
+ @storeable_record.save!
31
+ end
32
+
33
+ def use_cache?
34
+ @use_cache ||= !@meta.force && storeable_record.present?
32
35
  end
33
36
 
34
37
  def storable_meta
@@ -41,10 +44,6 @@ module HttpStore
41
44
  end.to_h
42
45
  end
43
46
 
44
- def re_storable(value)
45
-
46
- end
47
-
48
47
  def storable(value)
49
48
  case value
50
49
  when Hash
@@ -62,6 +61,10 @@ module HttpStore
62
61
  def storable_string(str)
63
62
  str.length > STRING_LIMIT_SIZE ? { digest: Digest::SHA1.hexdigest(str), origin: str[0..1000] } : str
64
63
  end
64
+
65
+ def json_safe_parse(str)
66
+ JSON.parse(str) rescue str
67
+ end
65
68
  end
66
69
  end
67
70
  end
@@ -31,7 +31,8 @@ module HttpStore
31
31
  http_method: request.request_method,
32
32
  data: request.params,
33
33
  headers: request.headers.select { |k, _v| k.start_with? 'HTTP_' }.to_h,
34
- query_params: request.query_parameters
34
+ query_params: request.query_parameters,
35
+ force: true,
35
36
  }
36
37
  end
37
38
 
@@ -1,3 +1,3 @@
1
1
  module HttpStore
2
- VERSION = "0.3.6"
2
+ VERSION = "0.3.7"
3
3
  end
data/lib/http_store.rb CHANGED
@@ -10,7 +10,7 @@ module HttpStore
10
10
 
11
11
  REQUEST_KEYS = %w[http_method url data_type headers query_params data other_params force request_valid]
12
12
  RESPONSE_KEYS = %w[status_code response response_headers response_data response_valid]
13
- META_KEYS = %w[request_digest client_type requestable_id requestable_type]
13
+ META_KEYS = %w[request_digest client_type parent_id requestable_id requestable_type]
14
14
  TMP_KEYS = %w[requestable response_obj]
15
15
 
16
16
  DIGEST_KEYS = %w[http_method url data_type data other_params requestable_id requestable_type]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: http_store
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.6
4
+ version: 0.3.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - black