http_store 0.3.4 → 0.3.5

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: bbad1b169cfaefecb2f2c7a96b916d382e109c8ff89c7104340974a9061013f0
4
- data.tar.gz: 8957ccdac995dcaacb30b40b0e4cbe3c53b06fcacf92344b741515dd3c8cbbfc
3
+ metadata.gz: 2bb337e2004a6a150a320fd1a9d3afbe17054860faa48cb31b53f1f266382928
4
+ data.tar.gz: ca53ded6e7fbf4eaaa341b52a520a4d7b07b94322c87ce8ecf2e4ea4dc8542c4
5
5
  SHA512:
6
- metadata.gz: 7a52092f8d72dcac74d88662e7cc5ecf361be80526d6ebb8908fd448f28e7f1a6c7107ccdb972bc640f672b3e572d310585c31dfc4219ad36ccc769a28d5c494
7
- data.tar.gz: 9a14abb12047c30f3afd11c1218ee068ee4a3de9da46291024f872087aca09303351538d0bdd1b1ca26e45c855cae840adb413cb564326e4a9ad36b8adb213be
6
+ metadata.gz: fa430ae04cd59ba0aa5f2806815837f1322482019008d4f222830fd73ba51cbb2a9fd1f6f0da5fda10add07f594fbcbe39e3d8cb15aee9a534f80a08b6b6c2e8
7
+ data.tar.gz: 70d4a2cd9cb8cba4c0e7d331bad2466f2b06d60917ca90ed7e4fa156782400a3d23508b4b7a5e770ad480fbcf03cbbcc78152708eae73060d4da6dcb2a4a8e36
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- http_store (0.3.4)
4
+ http_store (0.3.5)
5
5
  activerecord (>= 5.0, < 6.1)
6
6
  hashie (~> 3.0)
7
7
  rails (>= 5, < 7)
@@ -28,6 +28,7 @@ class CreateHttpLogs < ActiveRecord::Migration[5.2]
28
28
  t.string :client_type, comment: '请求类型'
29
29
  t.string :requestable_id, comment: '外键 ID'
30
30
  t.string :requestable_type, comment: '外键 类型'
31
+ t.integer :parent_id
31
32
 
32
33
  t.timestamps
33
34
  end
@@ -17,7 +17,7 @@ module HttpStore
17
17
  return unless request_valid?
18
18
 
19
19
  # exist request or not force, return
20
- return if !force && storeable_record.present?
20
+ load_storeable_record and return if !force && storeable_record.present?
21
21
 
22
22
  execute # send request
23
23
  raise HttpStore::RequestError, 'response_obj is nil' if response_obj.nil?
@@ -6,14 +6,29 @@ module HttpStore
6
6
  def storeable_record
7
7
  return unless HttpStore.config.store_enable
8
8
 
9
- @storeable_model ||= HttpStore.config.store_class.find_by(request_digest: request_digest, response_valid: true)
9
+ @storeable_record ||= HttpStore.config.store_class.find_by(request_digest: request_digest, response_valid: true)
10
+ end
11
+
12
+ def load_storeable_record
13
+ return if storeable_record.nil?
14
+
15
+ attrs =
16
+ storeable_record.attributes.slice(*HttpStore::ALL_KEYS).map do |k, v|
17
+ [k, v.is_a?(String) ? re_storable(v) : v]
18
+ end.to_h
19
+
20
+ @meta.parent_id = storeable_record.id
21
+ @meta.reverse_merge! attrs
10
22
  end
11
23
 
12
24
  # you can rewrite this callback, to store the request
13
25
  def store_request
14
26
  return unless HttpStore.config.store_enable
15
27
 
16
- HttpStore.config.store_class.new(storable_meta).save
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!
17
32
  end
18
33
 
19
34
  def storable_meta
@@ -26,6 +41,10 @@ module HttpStore
26
41
  end.to_h
27
42
  end
28
43
 
44
+ def re_storable(value)
45
+
46
+ end
47
+
29
48
  def storable(value)
30
49
  case value
31
50
  when Hash
@@ -1,5 +1,8 @@
1
1
  module HttpStore
2
2
  class HttpLog < ActiveRecord::Base
3
3
  belongs_to :requestable, polymorphic: true, optional: true
4
+
5
+ has_many :sons, class_name: 'HttpStore::HttpLog', foreign_key: 'parent_id'
6
+ belongs_to :parent, class_name: 'HttpStore::HttpLog'
4
7
  end
5
8
  end
@@ -1,3 +1,3 @@
1
1
  module HttpStore
2
- VERSION = "0.3.4"
2
+ VERSION = "0.3.5"
3
3
  end
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.4
4
+ version: 0.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - black