super_tools 2.1.0 → 4.0.0

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.
Files changed (48) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/test.yml +43 -0
  3. data/.gitignore +6 -0
  4. data/.ruby-version +1 -0
  5. data/Appraisals +29 -0
  6. data/Gemfile +2 -0
  7. data/Gemfile.lock +166 -150
  8. data/MULTI_RUBY_TESTING.md +170 -0
  9. data/bin/test_all +35 -0
  10. data/dependabot.yml +7 -0
  11. data/gemfiles/.bundle/config +2 -0
  12. data/gemfiles/ruby_2.7_rails_6.gemfile +8 -0
  13. data/gemfiles/ruby_2.7_rails_7.gemfile +8 -0
  14. data/gemfiles/ruby_3.0_rails_6.gemfile +8 -0
  15. data/gemfiles/ruby_3.0_rails_7.gemfile +8 -0
  16. data/gemfiles/ruby_3.1_rails_6.gemfile +8 -0
  17. data/gemfiles/ruby_3.1_rails_7.gemfile +8 -0
  18. data/lib/super_form/basic.rb +2 -7
  19. data/lib/super_form/concerns/atomic_save.rb +3 -3
  20. data/lib/super_form/reform.rb +28 -6
  21. data/lib/super_formatter/ecan/head.rb +4 -4
  22. data/lib/super_formatter/ecan/import.rb +4 -3
  23. data/lib/super_formatter/ecan/row.rb +3 -2
  24. data/lib/super_formatter/hct/head.rb +5 -5
  25. data/lib/super_formatter/hct/import.rb +4 -3
  26. data/lib/super_formatter/hct/row.rb +4 -3
  27. data/lib/super_formatter/shopline/head.rb +16 -16
  28. data/lib/super_formatter/shopline/import.rb +5 -6
  29. data/lib/super_formatter/shopline/order.rb +9 -8
  30. data/lib/super_formatter/shopline/row.rb +2 -2
  31. data/lib/super_formatter/tcat/head.rb +4 -4
  32. data/lib/super_formatter/tcat/import.rb +4 -4
  33. data/lib/super_formatter/tcat/row.rb +5 -4
  34. data/lib/super_interaction/beyond.rb +1 -1
  35. data/lib/super_interaction/engine.rb +2 -0
  36. data/lib/super_process/basic.rb +12 -0
  37. data/lib/super_process/core.rb +26 -25
  38. data/lib/super_search/scroll.rb +11 -8
  39. data/lib/super_spreadsheet/loader.rb +14 -14
  40. data/lib/super_table/action_view.rb +4 -4
  41. data/lib/super_table/builder.rb +5 -4
  42. data/lib/super_table/record.rb +1 -1
  43. data/lib/super_tools/version.rb +2 -2
  44. data/lib/super_tools.rb +42 -30
  45. data/lib/super_zipcode/taiwan.rb +131 -102
  46. data/super_tools.gemspec +18 -22
  47. metadata +111 -59
  48. data/lib/super_logger/formatter.rb +0 -15
data/bin/test_all ADDED
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env bash
2
+
3
+ set -e
4
+
5
+ echo "=== Testing all Ruby versions with Rails 6 & 7 ==="
6
+ echo ""
7
+
8
+ # Check if appraisal is installed
9
+ if ! bundle exec appraisal -h > /dev/null 2>&1; then
10
+ echo "Error: appraisal gem not found. Please run 'bundle install' first."
11
+ exit 1
12
+ fi
13
+
14
+ # Test each combination
15
+ combinations=(
16
+ "ruby-2.7-rails-6:Ruby 2.7.6 + Rails 6"
17
+ "ruby-2.7-rails-7:Ruby 2.7.6 + Rails 7"
18
+ "ruby-3.0-rails-6:Ruby 3.0.7 + Rails 6"
19
+ "ruby-3.0-rails-7:Ruby 3.0.7 + Rails 7"
20
+ "ruby-3.1-rails-6:Ruby 3.1.7 + Rails 6"
21
+ "ruby-3.1-rails-7:Ruby 3.1.7 + Rails 7"
22
+ )
23
+
24
+ for combo in "${combinations[@]}"; do
25
+ IFS=':' read -r appraisal_name display_name <<< "$combo"
26
+ echo "===================================="
27
+ echo "Testing: $display_name"
28
+ echo "===================================="
29
+ bundle exec appraisal $appraisal_name rake t
30
+ echo ""
31
+ done
32
+
33
+ echo "===================================="
34
+ echo "All tests completed!"
35
+ echo "===================================="
data/dependabot.yml ADDED
@@ -0,0 +1,7 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: "bundler"
4
+ directory: "/"
5
+ target-branch: "feat-rails-6.1.6"
6
+ schedule:
7
+ interval: "daily"
@@ -0,0 +1,2 @@
1
+ ---
2
+ BUNDLE_RETRY: "1"
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "reform-rails", tag: "v0.2.6.f", git: "https://github.com/superlanding/reform-rails"
6
+ gem "rails", "~> 6.1.0"
7
+
8
+ gemspec path: "../"
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "reform-rails", tag: "v0.2.6.f", git: "https://github.com/superlanding/reform-rails"
6
+ gem "rails", "~> 7.0.0"
7
+
8
+ gemspec path: "../"
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "reform-rails", tag: "v0.2.6.f", git: "https://github.com/superlanding/reform-rails"
6
+ gem "rails", "~> 6.1.0"
7
+
8
+ gemspec path: "../"
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "reform-rails", tag: "v0.2.6.f", git: "https://github.com/superlanding/reform-rails"
6
+ gem "rails", "~> 7.0.0"
7
+
8
+ gemspec path: "../"
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "reform-rails", tag: "v0.2.6.f", git: "https://github.com/superlanding/reform-rails"
6
+ gem "rails", "~> 6.1.0"
7
+
8
+ gemspec path: "../"
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "reform-rails", tag: "v0.2.6.f", git: "https://github.com/superlanding/reform-rails"
6
+ gem "rails", "~> 7.0.0"
7
+
8
+ gemspec path: "../"
@@ -1,4 +1,5 @@
1
- require 'virtus'
1
+ require "virtus"
2
+
2
3
  module SuperForm
3
4
  class Basic
4
5
  include ActiveModel::Model
@@ -7,12 +8,6 @@ module SuperForm
7
8
  include ActiveModel::Validations
8
9
  include Virtus.model
9
10
 
10
- def sync_params(params)
11
- params.each do |attr, value|
12
- public_send("#{attr}=", value) if respond_to?("#{attr}=")
13
- end
14
- end
15
-
16
11
  class << self
17
12
  def form_name(name)
18
13
  # 定義 form name (給 form 用的)
@@ -60,17 +60,17 @@ module SuperForm
60
60
  # 1. do validate data
61
61
  run_callbacks :validations do
62
62
  if validate(params) == false
63
- raise ReformAtomicSaveError, "Not Validate => #{self.errors.full_messages.inspect}"
63
+ raise ReformAtomicSaveError, "Not Validate => #{self.errors.full_messages}"
64
64
  end
65
65
  end
66
66
 
67
67
  # 2. sync to model
68
68
  sync
69
69
 
70
- # 2. define how to store data in block
70
+ # 3. define how to store data in block
71
71
  yield if block_given?
72
72
 
73
- # 3. save all data
73
+ # 4. save all data
74
74
  save!
75
75
  end
76
76
  end
@@ -1,10 +1,11 @@
1
- require 'super_form/concerns/atomic_save'
2
- require 'reform'
3
- require 'reform/form'
4
- require 'reform/active_record'
1
+ require "super_form/concerns/atomic_save"
2
+ require "reform"
3
+ require "reform/rails"
4
+ require "reform/form"
5
+ require "reform/active_record"
5
6
  require "reform/form/coercion"
6
- require 'disposable'
7
- require 'disposable/twin/parent'
7
+ require "disposable"
8
+ require "disposable/twin/parent"
8
9
 
9
10
  class SuperForm::Reform < Reform::Form
10
11
  include SuperForm::AtomicSave
@@ -25,6 +26,27 @@ class SuperForm::Reform < Reform::Form
25
26
  define_singleton_method :model_name do
26
27
  active_model_name_for(name.to_s.camelize) # Reform::Form::ActiveModel
27
28
  end
29
+ # NOTE: 這行很可能沒有作用
28
30
  model(name)
29
31
  end
30
32
  end
33
+
34
+ # Hack Dry::Type 升級 0.15 以後
35
+ # 變成強制型別,會造成 params input 空字串時的錯誤
36
+ # 這裡是 hack
37
+ # https://github.com/apotonick/disposable/blob/master/lib/disposable/twin/coercion.rb
38
+ # https://github.com/dry-rb/dry-types/blob/a4983c88299b6f323a769f783cf956629e61f8ed/lib/dry/types/coercions/params.rb#L86
39
+
40
+ Dry::Types::Coercions::Params.module_eval do
41
+ def self.to_int(input, &block)
42
+ if input.is_a? String
43
+ Integer(input, 10)
44
+ else
45
+ Integer(input)
46
+ end
47
+ rescue ArgumentError, TypeError => e
48
+ return input.to_i if input.respond_to?(:to_i)
49
+
50
+ CoercionError.handle(e, &block)
51
+ end
52
+ end
@@ -3,11 +3,11 @@ module SuperFormatter
3
3
  Head = Struct.new(:data) do
4
4
  def indexes
5
5
  @indexes ||= {
6
- global_order_id: data.index('客戶單號'),
7
- recipient: data.index('收件人'),
8
- tracking_code: data.index('宅配單號')
6
+ global_order_id: data.index("客戶單號"),
7
+ recipient: data.index("收件人"),
8
+ tracking_code: data.index("宅配單號")
9
9
  }
10
10
  end
11
11
  end
12
12
  end
13
- end
13
+ end
@@ -1,6 +1,7 @@
1
- require 'super_formatter/import'
2
- require 'super_formatter/hct/head'
3
- require 'super_formatter/hct/row'
1
+ require "super_formatter/import"
2
+ require "super_formatter/hct/head"
3
+ require "super_formatter/hct/row"
4
+
4
5
  module SuperFormatter
5
6
  module Ecan
6
7
  class Import < SuperFormatter::Import
@@ -1,11 +1,12 @@
1
- require 'super_formatter/row'
1
+ require "super_formatter/row"
2
+
2
3
  module SuperFormatter
3
4
  module Ecan
4
5
  class Row < ::SuperFormatter::Row
5
6
 
6
7
  def global_order_id
7
8
  order_id = (find(:global_order_id) || "")
8
- if order_id[0] == 'C'
9
+ if order_id[0] == "C"
9
10
  order_id[1, order_id.length - 1]
10
11
  else
11
12
  order_id
@@ -3,12 +3,12 @@ module SuperFormatter
3
3
  Head = Struct.new(:data) do
4
4
  def indexes
5
5
  @indexes ||= {
6
- global_order_id: data.index('訂單號碼') || data.index('清單編號'),
7
- mobile: data.index('收貨人電話') || data.index('收貨人電話1'),
8
- recipient: data.index('收貨人') || data.index('收貨人名稱'),
9
- tracking_code: data.index('查貨號碼') || data.index('十碼貨號')
6
+ global_order_id: data.index("訂單號碼") || data.index("清單編號"),
7
+ mobile: data.index("收貨人電話") || data.index("收貨人電話1"),
8
+ recipient: data.index("收貨人") || data.index("收貨人名稱"),
9
+ tracking_code: data.index("查貨號碼") || data.index("十碼貨號")
10
10
  }
11
11
  end
12
12
  end
13
13
  end
14
- end
14
+ end
@@ -1,6 +1,7 @@
1
- require 'super_formatter/import'
2
- require 'super_formatter/hct/head'
3
- require 'super_formatter/hct/row'
1
+ require "super_formatter/import"
2
+ require "super_formatter/hct/head"
3
+ require "super_formatter/hct/row"
4
+
4
5
  module SuperFormatter
5
6
  module Hct
6
7
  class Import < ::SuperFormatter::Import
@@ -1,16 +1,17 @@
1
- require 'super_formatter/row'
1
+ require "super_formatter/row"
2
+
2
3
  module SuperFormatter
3
4
  module Hct
4
5
  class Row < ::SuperFormatter::Row
5
6
 
6
7
  def tracking_code
7
- (find(:tracking_code) || "").gsub("'", '')
8
+ (find(:tracking_code) || "").gsub("'", "")
8
9
  end
9
10
 
10
11
  def mobile
11
12
  @mobile ||= begin
12
13
  text = (find(:mobile) || "").gsub("'", "")
13
- if text[0] == '9' && text.length == 9
14
+ if text[0] == "9" && text.length == 9
14
15
  "0#{text}"
15
16
  else
16
17
  text
@@ -3,22 +3,22 @@ module SuperFormatter
3
3
  Head = Struct.new(:data) do
4
4
  def indexes
5
5
  @indexes ||= {
6
- order_id: data.index('訂單號碼'),
7
- order_created: data.index('訂單日期'),
8
- shipping_method: data.index('送貨方式'),
9
- payment_method: data.index('付款方式'),
10
- payment_status: data.index('付款狀態'),
11
- recipient: data.index('收件人'),
12
- mobile: data.index('收件人電話號碼'),
13
- store_id: data.index('全家服務編號 / 7-11 店號'),
14
- address: data.index('完整地址'),
15
- total_order_amount: data.index('訂單合計'),
16
- note: data.index('送貨備註'),
17
- item_title: data.index('商品名稱'),
18
- item_option: data.index('選項'),
19
- item_code: data.index('商品貨號'),
20
- item_qty: data.index('數量'),
21
- item_cost: data.index('商品成本')
6
+ order_id: data.index("訂單號碼"),
7
+ order_created: data.index("訂單日期"),
8
+ shipping_method: data.index("送貨方式"),
9
+ payment_method: data.index("付款方式"),
10
+ payment_status: data.index("付款狀態"),
11
+ recipient: data.index("收件人"),
12
+ mobile: data.index("收件人電話號碼"),
13
+ store_id: data.index("全家服務編號 / 7-11 店號"),
14
+ address: data.index("完整地址"),
15
+ total_order_amount: data.index("訂單合計"),
16
+ note: data.index("送貨備註"),
17
+ item_title: data.index("商品名稱"),
18
+ item_option: data.index("選項"),
19
+ item_code: data.index("商品貨號"),
20
+ item_qty: data.index("數量"),
21
+ item_cost: data.index("商品成本")
22
22
  }
23
23
  end
24
24
  end
@@ -1,16 +1,15 @@
1
- require 'super_formatter/import'
2
- require 'super_formatter/shopline/head'
3
- require 'super_formatter/shopline/row'
4
- require 'super_formatter/shopline/order'
1
+ require "super_formatter/import"
2
+ require "super_formatter/shopline/head"
3
+ require "super_formatter/shopline/row"
4
+ require "super_formatter/shopline/order"
5
+
5
6
  module SuperFormatter
6
7
  module Shopline
7
8
  class Import < ::SuperFormatter::Import
8
9
 
9
10
  callable do
10
11
  build_rows!(Head, Row)
11
-
12
12
  self.orders = merged_orders!.values
13
-
14
13
  self.orders
15
14
  end
16
15
 
@@ -1,4 +1,5 @@
1
- require 'warehouse'
1
+ require "warehouse"
2
+
2
3
  module SuperFormatter
3
4
  module Shopline
4
5
  class Order
@@ -13,7 +14,7 @@ module SuperFormatter
13
14
  delegate :complete?, to: :row
14
15
 
15
16
  def order_id
16
- row.order_id.gsub("#", '')
17
+ row.order_id.gsub("#", "")
17
18
  end
18
19
 
19
20
  def initialize(row)
@@ -23,13 +24,13 @@ module SuperFormatter
23
24
 
24
25
  def provider
25
26
  @provider ||= case
26
- when row.shipping_method.include?('7-11')
27
+ when row.shipping_method.include?("7-11")
27
28
  :UNIMART
28
- when row.shipping_method.include?('全家')
29
+ when row.shipping_method.include?("全家")
29
30
  :FAMI
30
- when row.shipping_method.include?('新竹')
31
+ when row.shipping_method.include?("新竹")
31
32
  :HCT
32
- when row.shipping_method.include?('黑貓')
33
+ when row.shipping_method.include?("黑貓")
33
34
  :TCAT
34
35
  else
35
36
  nil
@@ -58,7 +59,7 @@ module SuperFormatter
58
59
  end
59
60
 
60
61
  def cash_on_delivery?
61
- if row.payment_method.include?('取貨付款')
62
+ if row.payment_method.include?("取貨付款")
62
63
  true
63
64
  else
64
65
  false
@@ -70,7 +71,7 @@ module SuperFormatter
70
71
  end
71
72
 
72
73
  def paid?
73
- row.payment_status == '已付款'
74
+ row.payment_status == "已付款"
74
75
  end
75
76
 
76
77
  def items
@@ -1,8 +1,8 @@
1
- require 'super_formatter/row'
1
+ require "super_formatter/row"
2
+
2
3
  module SuperFormatter
3
4
  module Shopline
4
5
  class Row < ::SuperFormatter::Row
5
-
6
6
  end
7
7
  end
8
8
  end
@@ -3,10 +3,10 @@ module SuperFormatter
3
3
  Head = Struct.new(:data) do
4
4
  def indexes
5
5
  @indexes ||= {
6
- global_order_id: data.index('訂單編號'),
7
- mobile: data.index('手機(收)'),
8
- recipient: data.index('收件人'),
9
- tracking_code: data.index('託運單號')
6
+ global_order_id: data.index("訂單編號"),
7
+ mobile: data.index("手機(收)"),
8
+ recipient: data.index("收件人"),
9
+ tracking_code: data.index("託運單號")
10
10
  }
11
11
  end
12
12
  end
@@ -1,10 +1,10 @@
1
- require 'super_formatter/import'
2
- require 'super_formatter/hct/head'
3
- require 'super_formatter/hct/row'
1
+ require "super_formatter/import"
2
+ require "super_formatter/hct/head"
3
+ require "super_formatter/hct/row"
4
+
4
5
  module SuperFormatter
5
6
  module Tcat
6
7
  class Import < SuperFormatter::Import
7
-
8
8
  callable do
9
9
  build_rows!(Head, Row)
10
10
  end
@@ -1,16 +1,17 @@
1
- require 'super_formatter/row'
1
+ require "super_formatter/row"
2
+
2
3
  module SuperFormatter
3
4
  module Tcat
4
5
  class Row < ::SuperFormatter::Row
5
6
 
6
7
  def tracking_code
7
- (find(:tracking_code) || "").gsub("'", '')
8
+ (find(:tracking_code) || "").gsub("'", "")
8
9
  end
9
-
10
+
10
11
  def mobile
11
12
  @mobile ||= begin
12
13
  text = (find(:mobile) || "").gsub("'", "")
13
- if text[0] == '9' && text.length == 9
14
+ if text[0] == "9" && text.length == 9
14
15
  "0#{text}"
15
16
  else
16
17
  text
@@ -65,7 +65,7 @@ module SuperInteraction
65
65
  end
66
66
 
67
67
  def b_alert(class_type, text)
68
- cmd("if (typeof($.alert) == undefined) { alert('#{helpers.j(text)}'); } else { $.alert.#{class_type}('#{helpers.j(text)}'); }")
68
+ cmd("if (typeof($.alert) === 'undefined') { alert('#{helpers.j(text)}'); } else { $.alert.#{class_type}('#{helpers.j(text)}'); }")
69
69
  end
70
70
 
71
71
  def cmd(js_code)
@@ -3,6 +3,8 @@ module SuperInteraction
3
3
  class Engine < Rails::Engine
4
4
  paths["app/views"] = "lib/super_interaction/views"
5
5
 
6
+ # NOTE: 需要確認底下的程式有無作用
7
+ # lib/super_interaction 底下並沒有 javascripts 目錄
6
8
  initializer 'beyond.assets.precompile' do |app|
7
9
  app.config.assets.paths << root.join('lib', 'super_interaction', 'javascripts').to_s
8
10
  end
@@ -0,0 +1,12 @@
1
+ module SuperProcess
2
+ module Basic
3
+
4
+ def method_missing(m, *args, &block)
5
+ if block_given?
6
+ new.public_send(m, *args, &block)
7
+ else
8
+ new.public_send(m, *args)
9
+ end
10
+ end
11
+ end
12
+ end
@@ -1,4 +1,5 @@
1
- require 'virtus'
1
+ require "virtus"
2
+
2
3
  module SuperProcess
3
4
  class Core
4
5
  include ActiveModel::Validations
@@ -7,30 +8,38 @@ module SuperProcess
7
8
 
8
9
  ValidError = Class.new(StandardError)
9
10
 
10
- define_callbacks :validations, :task
11
+ CALLBACK_CALL = :"__super_process__call"
12
+ CALLBACK_TASK = :"__super_process__task"
13
+
14
+ # https://github.com/rails/rails/blob/v6.1.6/activesupport/lib/active_support/callbacks.rb#L97
15
+ # 這裡透過 define_callbacks define 了 CALLBACK_CALL 與 CALLBACK_TASK
16
+ # 卻沒有 set_callbacks,所以在 run_callbacks 時
17
+ # 會因為找不到儲存的 callback 而直接執行 block
18
+ # 這裡的用法必須注意 rails 內部或是使用此 class 的開發者
19
+ # 不可以使用 CALLBACK_CALL 與 CALLBACK_TASK 相同命名的 callback
20
+ # 否則會有不可預期的副作用
21
+ define_callbacks CALLBACK_CALL, CALLBACK_TASK
11
22
 
12
23
  def self.before_call(method_name)
13
- set_callback :validations, :before, method_name
24
+ set_callback CALLBACK_CALL, :before, method_name
14
25
  end
15
26
 
16
27
  def self.after_call(method_name)
17
- set_callback :validations, :after, method_name
28
+ set_callback CALLBACK_CALL, :after, method_name
18
29
  end
19
30
 
20
31
  def self.before_task(method_name)
21
- set_callback :task, :before, method_name
32
+ set_callback CALLBACK_TASK, :before, method_name
22
33
  end
23
34
 
24
35
  def self.after_task(method_name)
25
- set_callback :task, :after, method_name
36
+ set_callback CALLBACK_TASK, :after, method_name
26
37
  end
27
38
 
28
- def self.init(model_name, &block)
39
+ def self.init(model_name)
29
40
  attr_accessor model_name
30
-
31
- class_eval(&block) if block_given?
32
-
33
41
  define_method :initialize do |model|
42
+ super({})
34
43
  self.send("#{model_name}=", model)
35
44
  end
36
45
  end
@@ -40,10 +49,9 @@ module SuperProcess
40
49
  params.each do |attr, value|
41
50
  public_send("#{attr}=", value) if respond_to?("#{attr}=")
42
51
  end
43
- run_callbacks :validations do
52
+ run_callbacks CALLBACK_CALL do
44
53
  raise ValidError, "Validation Error" if valid? == false
45
-
46
- run_callbacks :task do
54
+ run_callbacks CALLBACK_TASK do
47
55
  instance_eval(&block)
48
56
  end
49
57
  end
@@ -63,20 +71,13 @@ module SuperProcess
63
71
  @result
64
72
  end
65
73
 
66
- def error_messages
67
- if errors.messages.values.present?
68
- errors.messages.values.first.first
69
- else
70
- ""
71
- end
74
+ def error_message
75
+ errors.messages.values.first.first if errors.messages.values.present?
72
76
  end
73
77
 
74
- def self.method_missing(m, *args, &block)
75
- if block_given?
76
- new.public_send(m, *args, &block)
77
- else
78
- new.public_send(m, *args)
79
- end
78
+ def error_messages
79
+ errors.messages.values.flatten
80
80
  end
81
+
81
82
  end
82
83
  end
@@ -1,11 +1,13 @@
1
- require 'searchkick'
1
+ # NOTE: 這個 class 完全沒有在 landing 或 xdelivery 出現過
2
+ require "searchkick"
3
+
2
4
  module SuperSearch
3
5
  class Scroll
4
6
  attr_accessor :expire_time, :size, :query
5
7
 
6
- # ScrollSearch.new(Member, '*', where: {}, order: {}, scroll: '5m', size: 10000)
7
- def initialize(model, term: '*', options: {})
8
- self.expire_time = options.delete(:scroll) || '5m'
8
+ # ScrollSearch.new(Member, "*", where: {}, order: {}, scroll: "5m", size: 10000)
9
+ def initialize(model, term: "*", options: {})
10
+ self.expire_time = options.delete(:scroll) || "5m"
9
11
 
10
12
  # 單次筆數不得超過 10000
11
13
  self.size = options.delete(:size).to_i
@@ -48,7 +50,7 @@ module SuperSearch
48
50
  # searchkick/query line: 104
49
51
  def handle_response(response)
50
52
  # 從 response 設定 scroll ID
51
- @scroll_id = response['_scroll_id']
53
+ @scroll_id = response["_scroll_id"]
52
54
  super
53
55
  end
54
56
 
@@ -66,9 +68,10 @@ module SuperSearch
66
68
 
67
69
  # 開始遍歷搜尋
68
70
  def search(&block)
69
- while r = query.execute and not r.response['hits']['hits'].empty? do
70
- block.call(r.results, r.total_count) if block
71
- end
71
+ while r = query.execute and not r.response["hits"]["hits"].empty? do
72
+ block.call(r.results, r.total_count) if block
72
73
  end
73
74
  end
75
+
74
76
  end
77
+ end