Class: Bulletproof::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/bulletproof/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/bulletproof/configuration.rb', line 54

def initialize
  @enabled                  = false
  @max_includes_depth       = 2
  @max_associations         = 3
  @max_records_per_model    = 1_000
  @max_total_records        = 5_000
  @max_gc_runs_per_request  = nil
  @rails_logger             = true
  @console                  = true
  @alert                    = false
  @log_file                 = nil
  @notifier                 = nil
end

Instance Attribute Details

#alertObject

HTML レスポンスにオーバーレイパネルを注入するか(デフォルト: false) 開発者ツールを開かなくても画面上で警告を確認できる



42
43
44
# File 'lib/bulletproof/configuration.rb', line 42

def alert
  @alert
end

#consoleObject

HTML レスポンスの 直前に console.warn を注入するか(デフォルト: true) ブラウザの開発者ツールの Console タブで確認できる



38
39
40
# File 'lib/bulletproof/configuration.rb', line 38

def console
  @console
end

#enabledObject

ランタイム監視を有効にするか(デフォルト: false) Rails では config/initializers/bulletproof.rb で true に設定して使う



17
18
19
# File 'lib/bulletproof/configuration.rb', line 17

def enabled
  @enabled
end

#log_fileObject

警告をファイルに追記するか(デフォルト: nil = 無効) ファイルパスを文字列で指定する c.log_file = Rails.root.join("log/bulletproof.log").to_s



47
48
49
# File 'lib/bulletproof/configuration.rb', line 47

def log_file
  @log_file
end

#max_associationsObject

1つの includes で許容するアソシエーション数の上限



11
12
13
# File 'lib/bulletproof/configuration.rb', line 11

def max_associations
  @max_associations
end

#max_gc_runs_per_requestObject

リクエスト中に許容する GC 実行回数の上限 超えると :gc_pressure 警告を出す nil(デフォルト)のとき無効。GC 頻度はアプリや Ruby 設定に依存するため 必要な場合にのみ明示的に設定する(例: 10)



31
32
33
# File 'lib/bulletproof/configuration.rb', line 31

def max_gc_runs_per_request
  @max_gc_runs_per_request
end

#max_includes_depthObject

includes のネスト深さの上限(例: posts: { comments: :author } は深さ2)



8
9
10
# File 'lib/bulletproof/configuration.rb', line 8

def max_includes_depth
  @max_includes_depth
end

#max_records_per_modelObject

1モデルあたりのロード件数の上限 超えると :mass_instantiation 警告を出す



21
22
23
# File 'lib/bulletproof/configuration.rb', line 21

def max_records_per_model
  @max_records_per_model
end

#max_total_recordsObject

リクエスト全体(全モデル合算)のロード件数の上限 超えると :high_total_records 警告を出す



25
26
27
# File 'lib/bulletproof/configuration.rb', line 25

def max_total_records
  @max_total_records
end

#notifierObject

カスタム通知先。Slack 等に飛ばしたいときに設定する(デフォルト: nil = 無効) callable で RuntimeWarning を引数に取る c.notifier = ->(w) { SlackNotifier.ping(w.message) }



52
53
54
# File 'lib/bulletproof/configuration.rb', line 52

def notifier
  @notifier
end

#rails_loggerObject

Rails.logger.warn に出力するか(デフォルト: true)



34
35
36
# File 'lib/bulletproof/configuration.rb', line 34

def rails_logger
  @rails_logger
end