glib-web 4.34.0 → 4.34.2

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: c16c0b1492e8c1d4fb291c5d0583ec13c4992ca2b5ec316a62b416d8a28b7d6b
4
- data.tar.gz: b66e7297e95ba58a93926d161c545fbe37f4dbf74c9791709918035390c13194
3
+ metadata.gz: fb968a7bdcca5cd93fba46a281cbd210464b6bd5be04372769f7b5952e7cfcf8
4
+ data.tar.gz: 63a29dfa8bcf152baaf619811c303955a2e092d872633fc62ed7e931cfecd8b9
5
5
  SHA512:
6
- metadata.gz: ba8ba85ef6ff6fedcd0099bbcd61fc9296b37aafe83b44537583b7fe61c1e1e05a35b72b70850a36b19ae6a04df35ceafad75a4c7d6b8056403960a26db4802c
7
- data.tar.gz: a375d20580ee3e4e3df3a2134b1db9ada9758d2e2516b6ce1ce4e80be1bb47514650a2fa017f919da88e0eb267563b15c639099b924c29b7316db734558c1d9e
6
+ metadata.gz: 28c433305962fc28761eea800c4cf6d278bbcb73dd3a644fd041d651519005cd1febd6b099e5d9e08d64c35cc1fe36fbe83f0c4477cb1785f937000203e5a258
7
+ data.tar.gz: 6f75947877922db21c797a56dfcbc665baed3bc6e028a0a696e58b5d9d56e52e4de05faa8ce2432ce558b6e00a5134e9c38f8244a0c8f49271920709da8fa8f2
@@ -313,7 +313,7 @@ module Glib::Json::Libs
313
313
  end
314
314
  end
315
315
 
316
- def json_libs_rescue_csrf
316
+ def json_libs_rescue_csrf(sign_in_url_proc)
317
317
  rescue_from ActionController::InvalidAuthenticityToken do |exception|
318
318
  # sign_out(:user)
319
319
 
@@ -330,7 +330,7 @@ module Glib::Json::Libs
330
330
 
331
331
  respond_to do |format|
332
332
  format.html do
333
- redirect_to sign_in_url
333
+ redirect_to instance_exec(&sign_in_url_proc)
334
334
  end
335
335
  format.json do
336
336
  render json: {
@@ -116,7 +116,7 @@ module Glib
116
116
 
117
117
  # Use `send()` instead of `association(relationship).scope` because the latter returns new record objects as opposed
118
118
  # to existing objects which could cause a side effect.
119
- relation = send(relationship)
119
+ relation = public_send(relationship)
120
120
 
121
121
  # Use `each` instead of `find_each` because `each` is cached which is important to retain the
122
122
  # `marked_for_destruction` status.
@@ -11,33 +11,34 @@ module Glib
11
11
  403, ## FORBIDDEN Should be used for logged-in but not allowed to access
12
12
  ].flatten
13
13
 
14
- def initialize(context, user, router)
14
+ def initialize(context, user, router, inspect_result: true)
15
15
  @context = context
16
16
  @history = []
17
17
  @content_history = []
18
18
  @response_times = []
19
19
  @user = user
20
20
  @router = router
21
+ @inspect_result = inspect_result
21
22
  end
22
23
 
23
- def get(url, action, params = {}, inspect_result = true)
24
- fetch(:get, url, action, params, inspect_result)
24
+ def get(url, action, params = {})
25
+ fetch(:get, url, action, params, @inspect_result)
25
26
  end
26
27
 
27
- def post(url, action, params, inspect_result = true)
28
- fetch(:post, url, action, params)
28
+ def post(url, action, params)
29
+ fetch(:post, url, action, params, @inspect_result)
29
30
  end
30
31
 
31
- def patch(url, action, params, inspect_result = true)
32
- fetch(:patch, url, action, params)
32
+ def patch(url, action, params)
33
+ fetch(:patch, url, action, params, @inspect_result)
33
34
  end
34
35
 
35
- def put(url, action, params, inspect_result = true)
36
- fetch(:put, url, action, params)
36
+ def put(url, action, params)
37
+ fetch(:put, url, action, params, @inspect_result)
37
38
  end
38
39
 
39
- def delete(url, action, params = {}, inspect_result = true)
40
- fetch(:delete, url, action, {})
40
+ def delete(url, action, params = {})
41
+ fetch(:delete, url, action, {}, @inspect_result)
41
42
  end
42
43
 
43
44
  private
@@ -137,22 +137,22 @@ module Glib
137
137
  end
138
138
 
139
139
  # deprecated
140
- def follow(http, target_routers)
141
- if !target_routers.is_a?(Array)
142
- target_routers = [target_routers]
143
- end
144
-
145
- target_actions = Set.new
146
- target_routers.each do |router|
147
- target_actions += router.read_only_actions
148
- end
149
-
150
- @depth += 1
151
- target_actions.each do |crawler_action|
152
- action, url = crawler_action
153
- http.get(url, action, {}, false)
154
- end
155
- end
140
+ # def follow(http, target_routers)
141
+ # if !target_routers.is_a?(Array)
142
+ # target_routers = [target_routers]
143
+ # end
144
+
145
+ # target_actions = Set.new
146
+ # target_routers.each do |router|
147
+ # target_actions += router.read_only_actions
148
+ # end
149
+
150
+ # @depth += 1
151
+ # target_actions.each do |crawler_action|
152
+ # action, url = crawler_action
153
+ # http.get(url, action, {})
154
+ # end
155
+ # end
156
156
 
157
157
  def follow_v2(http, crawler_actions)
158
158
  @depth += 1
@@ -164,15 +164,15 @@ module Glib
164
164
 
165
165
  case action.to_s.downcase
166
166
  when 'http/post-v1', 'forms/post'
167
- http.post(url, action, params, false)
167
+ http.post(url, action, params)
168
168
  when 'http/patch-v1', 'forms/patch'
169
- http.patch(url, action, params, false)
169
+ http.patch(url, action, params)
170
170
  when 'http/put-v1', 'forms/put'
171
- http.put(url, action, params, false)
171
+ http.put(url, action, params)
172
172
  when 'http/delete-v1'
173
- http.delete(url, action, params, false)
173
+ http.delete(url, action, params)
174
174
  else
175
- http.get(url, action, params, false)
175
+ http.get(url, action, params)
176
176
  end
177
177
  end
178
178
  end
data/lib/glib/snapshot.rb CHANGED
@@ -13,10 +13,31 @@ module Glib
13
13
 
14
14
  before_save do
15
15
  self.attributes_before_save = attributes_in_database
16
- self.snapshot_changed = changed?
16
+ self.snapshot_changed = check_snapshot_changed
17
17
  end
18
18
  end
19
19
 
20
+ def check_snapshot_changed
21
+ return true if changed?
22
+
23
+ associations_for_snapshot.each do |association_name|
24
+ if (association = self.class.reflect_on_association(association_name))
25
+ case association.macro
26
+ when :has_many
27
+ public_send(association_name).each do |record|
28
+ return true if record.changed?
29
+ end
30
+ when :has_one, :belongs_to
31
+ return true if public_send(association_name).changed?
32
+ end
33
+ else
34
+ raise "Invalid association: #{association_name}"
35
+ end
36
+ end
37
+
38
+ false
39
+ end
40
+
20
41
  def where_snapshots(user: nil, field: nil, action: nil, association: nil, association_action: nil, like: nil)
21
42
  query = snapshots
22
43
 
@@ -7,10 +7,10 @@ module Glib
7
7
  end
8
8
 
9
9
  module ClassMethods
10
- def define_crawler_test(user, crawled_at, &on_after_crawl)
10
+ def define_crawler_test(user, crawled_at, dump_path:, &on_after_crawl)
11
11
  test "crawl api for #{user[:email]} #{user[:device]} #{user[:version] || 'current'}" do
12
12
  Timecop.freeze(crawled_at || user[:crawled_at]) do
13
- router = crawl_json_pages(user)
13
+ router = crawl_json_pages(user, dump_actions: dump_path.present?, dump_path: dump_path)
14
14
  on_after_crawl&.call(router)
15
15
  end
16
16
 
@@ -36,8 +36,8 @@ module Glib
36
36
  assert_equal JSON.parse(expected), JSON.parse(result), "Result mismatch! #{__git_is_available? ? `git diff #{__controller_log_dir}/#{__controller_log_file}` : ''}"
37
37
  end
38
38
 
39
- def crawl_json_pages(user, check_result: true, log_file: nil, dump_actions: false, &block)
40
- __execute_crawler(user, check_result: true) do |router, http|
39
+ def crawl_json_pages(user, log_file: nil, dump_actions: false, dump_path: nil, &block)
40
+ __execute_crawler(user, inspect_http: true) do |router, http|
41
41
  path = user[:path] ? "#{user[:path]}?format=json" : '/users/me?format=json&redirect=default'
42
42
  router.host = HOST
43
43
  router.step(
@@ -53,16 +53,23 @@ module Glib
53
53
  action, url, params = row
54
54
  [action, url, JSON.generate(params)].to_csv
55
55
  end.join
56
- filename = "#{user[:email]}[#{user[:device]}][#{user[:version] || 'current'}].csv"
57
- filepath = File.join(__crawler_log_dir, filename)
56
+
57
+ filepath = crawler_output_file(user, file_dir: dump_path)
58
58
  File.write(filepath, csv_string)
59
59
  end
60
60
  end
61
61
  end
62
62
 
63
- def retrace_json_pages(user, guiding_routers:)
64
- __execute_crawler(user, check_result: true) do |router, http|
65
- router.follow(http, guiding_routers)
63
+ def crawler_output_file(user, file_dir: nil)
64
+ filename = "#{user[:email]}[#{user[:device]}][#{user[:version] || 'current'}].csv"
65
+ File.join(file_dir || __crawler_log_dir, filename)
66
+ end
67
+
68
+ def retrace_json_pages(user, past_actions:)
69
+ __execute_crawler(user, inspect_http: false) do |router, http|
70
+ # router.follow(http, guiding_routers)
71
+ # router.follow_v2(Glib::JsonCrawler::Http.new(self, user, router), actions)
72
+ router.follow_v2(http, past_actions)
66
73
  end
67
74
  end
68
75
 
@@ -76,25 +83,23 @@ module Glib
76
83
  end
77
84
 
78
85
  private
79
- def __execute_crawler(user, check_result: true, log_file: nil, &block)
86
+ def __execute_crawler(user, inspect_http:, log_file: nil, &block)
80
87
  auth_token = login user
81
88
  user[:token] = auth_token
82
89
 
83
90
  router = Glib::JsonCrawler::Router.new
84
- http = Glib::JsonCrawler::Http.new(self, user, router)
91
+ http = Glib::JsonCrawler::Http.new(self, user, router, inspect_result: inspect_http)
85
92
  block.call(router, http)
86
93
 
87
94
  logout
88
95
 
89
- if check_result
90
- log_file = "#{user[:email]}[#{user[:device]}][#{user[:version] || 'current'}].txt" if log_file.nil?
96
+ log_file = "#{user[:email]}[#{user[:device]}][#{user[:version] || 'current'}].txt" if log_file.nil?
91
97
 
92
- file_path = File.join(__crawler_log_dir, log_file)
93
- expected = File.exist?(file_path) ? File.read(file_path) : ''
94
- result = router.logger
95
- File.write(file_path, result)
96
- assert_equal expected, result, "Result mismatch! #{log_file.sub(/\.txt$/, '')}"
97
- end
98
+ file_path = File.join(__crawler_log_dir, log_file)
99
+ expected = File.exist?(file_path) ? File.read(file_path) : ''
100
+ result = router.logger
101
+ File.write(file_path, result)
102
+ assert_equal expected, result, "Result mismatch! #{log_file.sub(/\.txt$/, '')}"
98
103
 
99
104
  router
100
105
  end
metadata CHANGED
@@ -1,11 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glib-web
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.34.0
4
+ version: 4.34.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - ''
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
  date: 2019-10-04 00:00:00.000000000 Z
@@ -122,7 +122,7 @@ dependencies:
122
122
  - - ">="
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
- description:
125
+ description:
126
126
  email: ''
127
127
  executables: []
128
128
  extensions: []
@@ -426,10 +426,10 @@ files:
426
426
  - lib/glib/value.rb
427
427
  - lib/glib/version.rb
428
428
  - lib/tasks/db.rake
429
- homepage:
429
+ homepage:
430
430
  licenses: []
431
431
  metadata: {}
432
- post_install_message:
432
+ post_install_message:
433
433
  rdoc_options: []
434
434
  require_paths:
435
435
  - lib
@@ -445,7 +445,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
445
445
  version: '0'
446
446
  requirements: []
447
447
  rubygems_version: 3.4.6
448
- signing_key:
448
+ signing_key:
449
449
  specification_version: 4
450
450
  summary: ''
451
451
  test_files: []