super_tools 4.0.2 → 4.1.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.
data/README.md CHANGED
@@ -1,135 +1,413 @@
1
- # SuperForm::Reform
1
+ # SuperTools
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/super_tools.svg)](https://rubygems.org/gems/super_tools)
4
+ [![Test](https://github.com/superlanding/super_tools/actions/workflows/test.yml/badge.svg)](https://github.com/superlanding/super_tools/actions/workflows/test.yml)
5
+
6
+ SuperTools 是 Super Landing 內部 Rails 專案共用的工具箱,把各專案重複出現的小零件收在同一個 gem:
7
+
8
+ | 模組 | 用途 |
9
+ | --- | --- |
10
+ | [`SuperProcess`](#superprocess) | 單一用途的 Service Object(參數 → 驗證 → callback → 執行),以及「像類別方法一樣呼叫實例方法」的 `Basic` |
11
+ | [`SuperForm`](#superform) | Form Object:`Basic`(ActiveModel + Virtus)與 `Reform`(Reform + 交易式儲存 `AtomicSave`) |
12
+ | [`SuperValue`](#supervalue) | 包裝一個 model 的 Value Object(委派屬性 + init callback) |
13
+ | [`SuperSpreadsheet`](#superspreadsheet) | 讀取 `.csv`(UTF-8 / Big5 / Big5-HKSCS)、`.xls`、`.xlsx` 成二維陣列 |
14
+ | [`SuperFormatter`](#superformatter) | 把物流 / 電商匯出的表格(Ecan、Tcat、Hct、Shopline)轉成有欄位名稱的 row |
15
+ | [`SuperTable`](#supertable) | 在 view 裡用 Ruby 產生 Bootstrap 風格的 `<table>` |
16
+ | [`SuperZipcode`](#superzipcode) | 台灣地址 → 郵遞區號 |
17
+ | [`SuperSearch`](#supersearch) | 以 Searchkick / Elasticsearch scroll API 遍歷大量搜尋結果 |
18
+ | [`SuperInteraction`](#superinteraction) | 在 controller 組合要回傳給瀏覽器執行的 JS(alert、modal、reload…) |
19
+ | [`SuperAirbrake`](#superairbrake) | 共用的 Airbrake 設定 DSL:敏感資料遮罩、雜訊忽略、效能門檻等規則可單獨開關/調參數/替換,也能加專案自訂規則(需另外 `require "super_airbrake"`) |
20
+
21
+ ## 需求
22
+
23
+ 本 gem 必須在 Rails 環境中使用(`require "super_tools"` 時需要 `Rails` 已經載入;Rails app 透過 Bundler 載入即可)。
24
+
25
+ - Ruby `>= 2.7.0`
26
+ - Rails `>= 6.1, < 8.2`
27
+
28
+ CI([`.github/workflows/test.yml`](.github/workflows/test.yml))實際測試的組合:
29
+
30
+ | Ruby | Rails |
31
+ | --- | --- |
32
+ | 2.7.6 | 6.1、7.0 |
33
+ | 3.0.7 | 6.1、7.0 |
34
+ | 3.1.7 | 6.1、7.0 |
35
+ | 3.3.12 | 8.0、8.1 |
36
+ | 3.4.11 | 8.0、8.1 |
37
+
38
+ ## 安裝
2
39
 
3
40
  ```ruby
4
- class MerchantForm::Edit < SuperForm::Reform
5
- model :merchant
41
+ # Gemfile
42
+ gem "super_tools"
43
+ ```
6
44
 
7
- property :title, default: ''
8
- property :contact, default: ''
9
- end
45
+ ```bash
46
+ bundle install
47
+ ```
48
+
49
+ 要使用 `SuperForm::Reform` 的巢狀表單驗證時,本專案自己的 Gemfile 使用的是 fork 版 `reform-rails`(修正無限迴圈問題,測試也是對著這個 fork 跑的):
50
+
51
+ ```ruby
52
+ gem "reform-rails", github: "superlanding/reform-rails", tag: "v0.2.6.f"
53
+ ```
10
54
 
55
+ gemspec 對 `reform-rails` 沒有版本限制,所以消費端是否一定要用 fork 取決於你的表單用法;上面這行是本專案測試使用的設定。
56
+
57
+ > `super_tools` 會一併安裝 `reform` 2.6.2、`dry-types` 1.5.1、`dry-logic` 1.2.0、`virtus`、`roo`、`roo-xls`、`spreadsheet`、`fast_excel`、`searchkick`、`warehouse_items` 等相依(精確版本見 [`super_tools.gemspec`](super_tools.gemspec))。
58
+
59
+ ## 設定
60
+
61
+ 大部分模組不需要設定。需要時才設定的有兩個:
62
+
63
+ **1. SuperTable 需要 Rails URL helper 時**,在 `config/initializers/super_table.rb` 自行混入:
64
+
65
+ ```ruby
66
+ SuperTable::Builder.send(:include, ::Rails.application.routes.url_helpers)
67
+ SuperTable::Record.send(:include, ::Rails.application.routes.url_helpers)
68
+ SuperTable::Tableable.send(:include, ::Rails.application.routes.url_helpers)
69
+ ```
70
+
71
+ **2. SuperInteraction 的 `js.modal`** 需要先指定 modal layout 使用的前端框架(沒設定會因為 `@@framework` 未初始化而丟 `NameError`),支援 `:bootstrap3`、`:bootstrap4`、`:beyond`:
72
+
73
+ ```ruby
74
+ # config/initializers/super_interaction.rb
75
+ SuperInteraction::Layout.framework = :bootstrap4
11
76
  ```
12
77
 
13
- # SuperLogger::Formatter
78
+ ## 使用方式
79
+
80
+ 以下範例都在本專案的測試環境(Ruby 3.4 / Rails 8.1)實際執行過;範例裡的 `Book` 是只有 `name` 欄位的 ActiveRecord model。
14
81
 
15
- 就是之前的 `LoggerFormatter`
82
+ ### SuperProcess
16
83
 
17
- # SuperProcess::Core
84
+ #### `SuperProcess::Core`
85
+
86
+ Service Object:`init` 宣告要處理的 model,`attribute`(Virtus)宣告輸入參數並自動轉型,驗證用 ActiveModel 的 `validates` / `validate`,`callable` 區塊是真正的工作。
18
87
 
19
88
  ```ruby
20
- class BillingCalculate < SuperProcess::Core
21
- init :billing do
22
- attribute :total_orders_amount, Integer
23
- end
89
+ class PublishBook < SuperProcess::Core
90
+ init :book
91
+
92
+ attribute :name, String
93
+ attribute :price, Integer
94
+
95
+ validates :name, presence: true
96
+ validate :price_must_not_be_negative
97
+
98
+ before_call :prepare # 另有 after_call / before_task / after_task
24
99
 
25
100
  callable do
26
- "RESULT_OBJECT"
101
+ book.update!(name: name)
102
+ book # 回傳值會放在 #result
103
+ end
104
+
105
+ def prepare
106
+ # ...
107
+ end
108
+
109
+ def price_must_not_be_negative
110
+ errors.add(:price, "不可小於 0") if price.to_i < 0
111
+ end
112
+ end
113
+
114
+ service = PublishBook.new(Book.new)
115
+ service.call(name: "Ruby", price: "100") #=> true
116
+ service.price #=> 100(字串被轉成 Integer)
117
+ service.result #=> #<Book ...>
118
+ service.error_messages #=> []
119
+
120
+ service = PublishBook.new(Book.new)
121
+ service.call(name: "", price: -1) #=> false(驗證失敗,不會執行 callable)
122
+ service.error_message #=> "can't be blank"(第一筆錯誤)
123
+ service.error_messages #=> ["can't be blank", "不可小於 0"](Array)
124
+
125
+ service.call!(name: "") # 驗證失敗時丟 SuperProcess::Core::ValidError
126
+ ```
127
+
128
+ 執行順序:`before_call` → 驗證 → `before_task` → `callable` → `after_task` → `after_call`。
129
+
130
+ #### `SuperProcess::Basic`
131
+
132
+ 讓類別可以直接呼叫實例方法(透過 `method_missing` 先 `new` 再呼叫):
133
+
134
+ ```ruby
135
+ class Robot
136
+ extend SuperProcess::Basic
137
+
138
+ def hello
139
+ "hi"
27
140
  end
141
+ end
142
+
143
+ Robot.hello #=> "hi"
144
+ Robot.not_defined #=> NoMethodError
145
+ ```
146
+
147
+ ### SuperForm
148
+
149
+ #### `SuperForm::Basic`
150
+
151
+ ActiveModel + Virtus 的表單物件,適合不對應資料表的表單。`form_name` 決定 `model_name`(給 `form_for` 用),`i18n_prefix` 決定 i18n scope(預設 `:forms`)。
152
+
153
+ ```ruby
154
+ class ContactForm < SuperForm::Basic
155
+ form_name :contact
156
+ attribute :email, String
157
+ attribute :age, Integer
158
+ validates :email, presence: true
159
+ end
160
+
161
+ form = ContactForm.new(email: "", age: "20")
162
+ form.valid? #=> false
163
+ form.errors.full_messages #=> ["Email can't be blank"]
164
+ form.age #=> 20
165
+ form.model_name.to_s #=> "Contact"
166
+ ContactForm.i18n_scope #=> :forms
167
+ ```
168
+
169
+ #### `SuperForm::Reform`
170
+
171
+ 繼承 `Reform::Form`,加上 `form_name` / `i18n_prefix`(預設 `:activerecord`)、型別轉換(Coercion),以及 `SuperForm::AtomicSave` 提供的 `save_with_transaction`:驗證、同步到 model、執行你的區塊、`save!` 全部包在同一個資料庫交易裡。
28
172
 
29
- def valid_amount
30
- if total_orders_amount > 1000
31
- errors.add(:total_orders_amount, "金額必須小於 1000 元")
173
+ ```ruby
174
+ class BookForm < SuperForm::Reform
175
+ form_name :book
176
+ property :name
177
+ validates :name, presence: true
178
+
179
+ before_commit { Rails.logger.info("before_commit") }
180
+ after_commit { Rails.logger.info("after_commit") }
181
+
182
+ def save(params = {})
183
+ save_with_transaction(params) do
184
+ model.status = "selling" # 在 sync 之後、save! 之前執行的區塊
32
185
  end
33
186
  end
34
187
  end
35
188
 
36
- @service = BillingCalculate.new(@billing)
37
- @service.call(total_orders_amount: "100")
38
- #=> true
39
- @service.total_orders_amount
40
- #=> 100
41
- @service.result
42
- #=> "RESULT_OBJECT"
43
- @service.error_messages
44
- #=> ""
189
+ form = BookForm.new(Book.new)
190
+ form.save(name: "") #=> false(驗證失敗,交易 rollback)
191
+ form.errors.full_messages #=> ["Name can't be blank"]
192
+
193
+ form = BookForm.new(Book.new)
194
+ form.save(name: "Ruby") #=> true
195
+ form.model.persisted? #=> true
196
+
197
+ form.save_with_transaction!(name: "") # 驗證失敗時丟 SuperForm::AtomicSave::ReformAtomicSaveError
45
198
  ```
46
199
 
47
- # SuperZipcode::Taiwan
200
+ 可用的 callback:`before_transaction`、`before_queries`、`before_validations`、`after_validations`、`before_commit`、`after_commit`;每個都可以傳方法名稱或區塊(兩者擇一)。巢狀 collection 的寫法請參考 [`test/super_form/reform_db_test.rb`](test/super_form/reform_db_test.rb)。
201
+
202
+ ### SuperValue
48
203
 
49
204
  ```ruby
50
- SuperZipcode::Taiwan.find_zip_code("高雄市鳳山區鳳甲一街129號")
51
- #=> 830
205
+ class OrderValue < SuperValue::Base
206
+ init :order # 建構時傳入的 model
207
+ property :title # 委派給 order.title
208
+ after_init { @label = "#{title}!" } # 另有 before_init
209
+ attr_reader :label
210
+ end
211
+
212
+ value = OrderValue.new(Struct.new(:title).new("x"))
213
+ value.title #=> "x"
214
+ value.label #=> "x!"
52
215
  ```
53
216
 
54
- # SuperTable
217
+ ### SuperSpreadsheet
55
218
 
56
- 如需要 Rails URL helper 請於 initializers/suepr_table.rb 自行混入
219
+ `SuperSpreadsheet::Loader` 繼承 `SuperProcess::Core`,依副檔名讀取 `.csv`(依序嘗試 Big5、Big5-HKSCS,最後當 UTF-8)、`.xls`、`.xlsx`,浮點數若是整數會轉成 Integer。
57
220
 
58
221
  ```ruby
59
- SuperTable::Builder.send(:include, ::Rails.application.routes.url_helpers)
60
- SuperTable::Record.send(:include, ::Rails.application.routes.url_helpers)
61
- SuperTable::Tableable.send(:include, ::Rails.application.routes.url_helpers)
222
+ loader = SuperSpreadsheet::Loader.new("/tmp/orders.csv").tap(&:call)
223
+ loader.result
224
+ #=> [["姓名", "電話"], ["許功蓋", "0912-333-456"]]
225
+
226
+ bad = SuperSpreadsheet::Loader.new("/tmp/file.lol")
227
+ bad.call #=> false
228
+ bad.error_messages #=> ["檔案格式錯誤"](空白檔案則是「檔案內容錯誤,空白檔案」)
62
229
  ```
63
230
 
64
- # SuperSpreadsheet::Loader
231
+ ### SuperFormatter
232
+
233
+ 把 `SuperSpreadsheet::Loader` 讀進來的表格,依第一列標題找出欄位,轉成可以用欄位名稱存取的 row。目前有 `Ecan`、`Tcat`、`Hct`、`Shopline`:
65
234
 
66
235
  ```ruby
67
- @spreadsheet = SuperSpreadsheet::Loader.new("/tmp/xxx.csv").tap { |s| s.call }
68
- @spreadsheet = SuperSpreadsheet::Loader.new("/tmp/xxx.xls").tap { |s| s.call }
69
- @spreadsheet = SuperSpreadsheet::Loader.new("/tmp/xxx.xlsx").tap { |s| s.call }
236
+ spreadsheet = SuperSpreadsheet::Loader.new("tcat_export.csv").tap(&:call)
237
+ import = SuperFormatter::Tcat::Import.new(spreadsheet).tap(&:call)
70
238
 
71
- @spreadsheet.result
72
- #=> [ [ '欄位1', '欄位2', '欄位3' ], [ '資料1', '資料2', '資料3'] ]
239
+ row = import.result.first
240
+ row.global_order_id #=> "MB40881"
241
+ row.recipient #=> "黃齡萱"
242
+ row.mobile #=> "0977481414"
243
+ row.tracking_code #=> "625270211891"
73
244
  ```
74
245
 
75
- # SuperSearch::Scroll
246
+ `SuperFormatter::Shopline::Import` 會把同一張訂單的多列商品合併,`result` 是 `SuperFormatter::Shopline::Order` 陣列(`rows` 是原始每一列):
76
247
 
77
248
  ```ruby
78
- ::SuperSearch::Scroll.new(Member, options: { where: { age: 20 } })
249
+ spreadsheet = SuperSpreadsheet::Loader.load!("shopline_export.xls").tap(&:call)
250
+ import = SuperFormatter::Shopline::Import.new(spreadsheet)
251
+ import.call #=> true
252
+ import.result.first #=> #<SuperFormatter::Shopline::Order ...>
79
253
  ```
80
254
 
81
- # SuperInteraction
255
+ 各家欄位對應表在 `lib/super_formatter/*/head.rb`;新增一家物流時,照 `Tcat` 的 `Head` / `Row` / `Import` 三個檔案的做法,並在 `lib/super_tools.rb` 加上 `require`。
82
256
 
83
- ### app/controllers/application_controller.rb
257
+ ### SuperTable
258
+
259
+ 用 Ruby 宣告表格欄位,再在 view 裡渲染。`column` 宣告欄位(key、標題、HTML 屬性,`desc:` 會顯示在標題下方的小字),`collection` 宣告資料集合與每筆資料的呈現方式(`property` 委派給 model,其餘方法可自行覆寫),`placeholder` 是沒有資料時顯示的內容。
84
260
 
85
261
  ```ruby
86
- class ApplicationController < ActionController::Base
87
- include SuperInteraction::BootstrapHelper
88
- include SuperInteraction::BeyondrHelper
262
+ class OrdersTable < SuperTable::Tableable
263
+ column :ship_no, "訂單編號", width: 100
264
+ column :recipient, "收件人", desc: "姓名 / 電話"
265
+ column :amount, "金額", class: "text-end"
266
+
267
+ collection :orders do
268
+ property :ship_no
269
+ def amount_text
270
+ "NT$ #{model.amount}"
271
+ end
272
+ end
273
+
274
+ def placeholder
275
+ "目前沒有訂單"
276
+ end
277
+ end
278
+ ```
279
+
280
+ ```erb
281
+ <%# controller 裡:@table = OrdersTable.new(orders) %>
282
+ <%= super_table(@table, size: :sm, responsive: :md) do |t| %>
283
+ <%= t.heads :ship_no, :recipient, :amount %>
284
+ <%= t.columns do |order| %>
285
+ <%= t.column :ship_no %>
286
+ <%= t.column order.recipient %>
287
+ <%= t.column order.amount_text, class: "text-end" %>
288
+ <% end %>
289
+ <% end %>
290
+ ```
291
+
292
+ 輸出(有兩筆資料時,已省略換行):
293
+
294
+ ```html
295
+ <div class="table-responsive-md"><table class="table table-hover table-sm"><tr class="table-secondary"><th width="100">訂單編號</th><th>收件人<div class="small text-primary">姓名 / 電話</div></th><th class="text-end">金額</th></tr><tr><td>A1</td><td>王小明</td><td class="text-end">NT$ 100</td></tr>…</table></div>
296
+ ```
297
+
298
+ `super_table` 的選項:`hover:`(預設 `true`,且只有在有資料時才加 `table-hover`)、`size: :sm`、`responsive: :sm / :md / :lg / :xl`,其餘選項會變成 `<table>` 的 HTML 屬性。沒有資料時 `t.columns` 會輸出一列 `placeholder`(沒定義就顯示「尚無資料」)。
299
+
300
+ ### SuperZipcode
301
+
302
+ ```ruby
303
+ SuperZipcode::Taiwan.find_zip_code("高雄市鳳山區鳳甲一街129號")
304
+ #=> "830"(字串)
305
+ ```
306
+
307
+ ### SuperSearch
308
+
309
+ `SuperSearch::Scroll` 包裝 Searchkick 的查詢,改用 Elasticsearch scroll API 分批遍歷(單批最多 10000 筆)。需要可連線的 Elasticsearch,本專案測試沒有涵蓋這個模組。
310
+
311
+ ```ruby
312
+ scroll = SuperSearch::Scroll.new(Member, term: "*", options: { where: { age: 20 }, scroll: "5m", size: 1000 })
313
+ scroll.search do |results, total_count|
314
+ results.each { |member| ... }
89
315
  end
90
316
  ```
91
317
 
92
- ### app/controllers/members_controller.rb
318
+ ### SuperInteraction
319
+
320
+ 在 controller 組合要回傳給瀏覽器執行的 JavaScript,`run` 會以 `render js:` 回傳。需要前端有 jQuery 外掛(`$.modal`、`$.alert`,Beyond 版是 `$.uniqModal`)與 Turbolinks,modal layout 使用 HAML(App 需自行安裝 `haml`)。本專案測試沒有涵蓋這個模組。
93
321
 
94
322
  ```ruby
323
+ class ApplicationController < ActionController::Base
324
+ include SuperInteraction::BootstrapHelper # 提供 js (Bootstrap 版)
325
+ include SuperInteraction::BeyondHelper # 提供 srj(Beyond 版)
326
+ end
327
+
95
328
  class MembersController < ApplicationController
96
- # GET /
97
329
  def index
98
- js.alert("Helloworld").reload.run
330
+ js.alert("Hello world").reload.run
99
331
  end
100
332
 
101
- # GET /
102
333
  def new
103
334
  @member = Member.new
104
335
  # View: app/views/members/edit.html.haml
105
- # Layout: app/views/layouts/modal.html.haml
106
- js.modal(partial: :edit).run
336
+ # Layout: 依 SuperInteraction::Layout.framework 選擇內建的 modal layout
337
+ js.modal(partial: :edit, size: "lg", title: "新增會員").run
107
338
  end
108
339
  end
109
340
  ```
110
341
 
111
- ### app/views/layouts/modal.html.haml
342
+ 可串接的方法:`alert`、`modal`、`close`、`reload`、`redirect_to(url)`、`ajax_get(url)`、`modal_saved_reload(message)`、`modal_saved_rediret_to(message, url)`、`cmd(js_code)`;通知用 `bs_notice` / `bs_danger` / `bs_success`(Beyond 版是 `b_notice` / `b_danger` / `b_success`)。
343
+
344
+ ### SuperAirbrake
345
+
346
+ 把 Airbrake 的設定與 filter 收成一份 DSL,給一頁商店、火箭快遞、EIP 共用。`airbrake` 不是本 gem 的硬相依,`require "super_tools"` 也不會載入它;專案的 Gemfile 要自己有 `airbrake`(13.0.1 ~ 13.x),並在 initializer 明確 `require "super_airbrake"`。**完整教學見 [docs/super_airbrake.md](docs/super_airbrake.md)。**
347
+
348
+ ```ruby
349
+ # config/initializers/airbrake.rb
350
+ require "super_airbrake"
351
+
352
+ SuperAirbrake.configure do |c|
353
+ c.project_id = ENV["AIRBRAKE_PROJECT_ID"] # id 或 key 任一為空 → 不呼叫 Airbrake.configure(規則照掛)
354
+ c.project_key = ENV["AIRBRAKE_PROJECT_KEY"]
355
+ c.performance_stats = true
356
+ c.performance_threshold_ms = 1500 # 預設 1500:低於門檻的效能事件不上報
357
+
358
+ # 內建規則:開/關/調參數/整條換掉
359
+ c.rule :web_not_found # 網頁 404 不報(預設關)
360
+ c.rule :blocklist, keys: [:card_number] # 額外遮罩的 key(預設已含 filter_parameters+Authorization)
361
+ c.disable :referer_blocklist
362
+
363
+ # 專案自訂:宣告式忽略(條件之間 AND、陣列內 OR;常數給字串不會觸發 autoload)
364
+ c.ignore "ActiveRecord::RecordNotFound", name: :admin_not_found,
365
+ controller: "Admin::BaseController", controller_path: %r{\Aadmin/}
366
+ c.filter(:tag_tenant) { |notice| notice[:context][:tenant] = Current.tenant&.slug }
367
+ end
368
+
369
+ puts SuperAirbrake.explain # 印出每條規則的開關、來源與參數
370
+ ```
371
+
372
+ 內建規則(名稱 → 預設):`blocklist`(開)、`referer_blocklist`(開)、`signal_exception`(開)、`invalid_mime`(開)、`retryable_jobs`(開,有 Sidekiq 才掛)、`performance_threshold`(開)、`web_not_found`(關)、`current_session`(關)、`proxy_timeout`(關)。另有 `c.query_stats = :skip_fast`、`c.use`、`SuperAirbrake.register`、`c.replace`、`c.after_install` 與測試用的 `SuperAirbrake::Testing`,參數表與範例都在 [docs/super_airbrake.md](docs/super_airbrake.md)。
373
+
374
+ 相容性:`lib/super_airbrake/` 用 Ruby 2.6 相容語法、只依賴 `airbrake` 與 `active_support`,CI 另外在 Ruby 2.6.7/Rails 5.2.8/airbrake 13.0.1(一頁商店的環境)跑它的測試。一頁商店因為 Ruby/Rails 版本無法使用 4.x,會走 2.x 回植線(見文件第 10 節)。
112
375
 
113
- ```haml
114
- .modal
115
- = yield :wrapper
116
- .modal-dialog{ class: "modal-#{bs_modal_size}" }
117
- .modal-content
118
- .modal-header
119
- %button.close{"aria-label" => "Close", "data-dismiss" => "modal", :type => "button"}
120
- = fa_icon('times')
121
- = yield :header
122
- - if title.present?
123
- %h4.modal-title= title
124
- = yield
125
- = yield :before_body
126
- - body_html = capture { yield :body }
127
- - if body_html.present?
128
- .modal-body= body_html
129
- = yield :after_body
376
+ ## 開發與測試
130
377
 
131
- - footer_html = capture { yield :footer }
132
- - if footer_html.present?
133
- .modal-footer= footer_html
378
+ ```bash
379
+ git clone git@github.com:superlanding/super_tools.git
380
+ cd super_tools
134
381
 
382
+ # 選一個 gemfiles/ 底下的組合(命名:ruby_<版本>_rails_<版本>.gemfile)
383
+ export BUNDLE_GEMFILE=$PWD/gemfiles/ruby_3.4_rails_8.1.gemfile
384
+ bundle install
385
+ bundle exec rake t # 跑 test/**/*_test.rb(不含 test/super_airbrake)
386
+ bundle exec rake super_airbrake # 跑 SuperAirbrake 的測試(test/super_airbrake/**/*_test.rb)
387
+
388
+ # SuperAirbrake 的舊環境(一頁商店:Ruby 2.6.7 / Rails 5.2.8 / airbrake 13.0.1)
389
+ BUNDLE_GEMFILE=$PWD/gemfiles/super_airbrake_legacy.gemfile bundle exec rake super_airbrake
135
390
  ```
391
+
392
+ - 測試框架是 Minitest + shoulda-context,測試資料在 `test/support/`。
393
+ - 想一次跑 Ruby 2.7 / 3.0 / 3.1 × Rails 6 / 7,可用 `bin/test_all`(Appraisal);以 `gemfiles/` 與 `.github/workflows/test.yml` 為準,[`MULTI_RUBY_TESTING.md`](MULTI_RUBY_TESTING.md) 只描述 Rails 6 / 7 的組合。
394
+ - 專案的 Gemfile 會從 GitHub 安裝 fork 版 `reform-rails`,需要能連到 GitHub。
395
+
396
+ ## 發版
397
+
398
+ 本 gem 透過 GitHub Actions([`.github/workflows/publish.yml`](.github/workflows/publish.yml))以 RubyGems Trusted Publishing 自動發佈,不使用 API key:
399
+
400
+ 1. 開 PR 時修改 `lib/super_tools/version.rb`(Semantic Versioning:修 bug 跳 patch、相容的新功能跳 minor、不相容變更跳 major)。
401
+ 2. 同一個 PR 更新 [CHANGELOG.md](CHANGELOG.md)(新增 `## [x.y.z] - YYYY-MM-DD` 區塊)與必要的 README.md。
402
+ 3. CI 通過、由真人合併到 `master`。
403
+ 4. `publish.yml` 發現 `master` 的版本號還不在 rubygems.org 時,會先跑測試(Ruby 3.4 / Rails 8.1),再發佈並打上 `vX.Y.Z` tag;版本已存在則自動略過。
404
+
405
+ 只改文件 / CI / CLAUDE.md 的 PR 可以不跳版號(合併後不會發佈)。
406
+
407
+ ## 參與開發
408
+
409
+ 每個 PR 都要同步更新 README.md(行為、用法、設定、相依或支援版本有變動時)與 CHANGELOG.md,規則寫在 [CLAUDE.md](CLAUDE.md)。
410
+
411
+ ## 授權
412
+
413
+ [MIT License](LICENSE.txt)
data/Rakefile CHANGED
@@ -4,7 +4,14 @@ require "rake/testtask"
4
4
  Rake::TestTask.new(:t) do |t|
5
5
  t.libs << "test"
6
6
  t.libs << "lib"
7
- t.test_files = FileList["test/**/*_test.rb"]
7
+ # SuperAirbrake 有自己的 task(不載入 super_tools 其他工具,也要能在 Ruby 2.6/Rails 5.2 跑)
8
+ t.test_files = FileList["test/**/*_test.rb"].exclude("test/super_airbrake/**/*_test.rb")
9
+ end
10
+
11
+ Rake::TestTask.new(:super_airbrake) do |t|
12
+ t.libs << "test"
13
+ t.libs << "lib"
14
+ t.test_files = FileList["test/super_airbrake/**/*_test.rb"]
8
15
  end
9
16
 
10
17
  task :default => :test