Class: Txray::Config
- Inherits:
-
Object
- Object
- Txray::Config
- Defined in:
- lib/txray/config.rb
Constant Summary collapse
- FILENAME =
".txray.yml"- DEFAULTS =
{ "include" => [ "app", "lib", "db/migrate" ], "exclude" => %w[spec test vendor node_modules tmp log .git], "max_depth" => 3, "fail_level" => "low", "disabled_rules" => [], "external_clients" => [], "severities" => {}, "runtime" => { "enabled" => false, "threshold_ms" => 250, "on_violation" => "log", "log_path" => "tmp/txray.ndjson", "ignore" => [], "guard_http" => true, "guard_jobs" => true, "guard_mail" => true } }.freeze
- ARRAY_KEYS =
%w[include exclude disabled_rules external_clients].freeze
- HASH_KEYS =
%w[severities runtime].freeze
- FAIL_LEVELS =
%w[low medium high none].freeze
Class Method Summary collapse
Instance Method Summary collapse
- #disabled_rules ⇒ Object
- #excludes ⇒ Object
- #external_clients ⇒ Object
- #fail_level ⇒ Object
- #includes ⇒ Object
-
#initialize(data = {}) ⇒ Config
constructor
A new instance of Config.
- #max_depth ⇒ Object
- #merge(overrides) ⇒ Object
- #rule(id) ⇒ Object
- #rule_enabled?(id) ⇒ Boolean
- #runtime ⇒ Object
- #to_h ⇒ Object
Constructor Details
Class Method Details
.discover(from = Dir.pwd) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/txray/config.rb', line 30 def self.discover(from = Dir.pwd) Pathname.new(from).ascend do |directory| candidate = directory.join(FILENAME) return candidate.to_s if candidate.file? end nil end |
.load(path = nil) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/txray/config.rb', line 38 def self.load(path = nil) raise Error, "no such config file: #{path}" if path && !File.exist?(path) path ||= discover data = path ? YAML.safe_load_file(path) : {} new(data.is_a?(Hash) ? data : {}) end |
Instance Method Details
#disabled_rules ⇒ Object
59 |
# File 'lib/txray/config.rb', line 59 def disabled_rules = Array(@data["disabled_rules"]).map(&:to_s) |
#excludes ⇒ Object
56 |
# File 'lib/txray/config.rb', line 56 def excludes = Array(@data["exclude"]) |
#external_clients ⇒ Object
58 |
# File 'lib/txray/config.rb', line 58 def external_clients = Array(@data["external_clients"]).map(&:to_s) |
#fail_level ⇒ Object
62 |
# File 'lib/txray/config.rb', line 62 def fail_level = @data["fail_level"].to_s.to_sym |
#includes ⇒ Object
55 |
# File 'lib/txray/config.rb', line 55 def includes = Array(@data["include"]) |
#max_depth ⇒ Object
57 |
# File 'lib/txray/config.rb', line 57 def max_depth = Integer(@data["max_depth"]) |
#merge(overrides) ⇒ Object
94 95 96 |
# File 'lib/txray/config.rb', line 94 def merge(overrides) self.class.new(@data.merge(overrides.compact.transform_keys(&:to_s))) end |
#rule(id) ⇒ Object
86 87 88 89 90 91 92 |
# File 'lib/txray/config.rb', line 86 def rule(id) severity = @data["severities"].to_h[id.to_s] base = Rules[id] return base unless severity base.dup.tap { |copy| copy.severity = severity.to_sym } end |
#rule_enabled?(id) ⇒ Boolean
64 |
# File 'lib/txray/config.rb', line 64 def rule_enabled?(id) = !disabled_rules.include?(id.to_s) |
#runtime ⇒ Object
60 |
# File 'lib/txray/config.rb', line 60 def runtime = @data["runtime"].transform_keys(&:to_s) |
#to_h ⇒ Object
100 |
# File 'lib/txray/config.rb', line 100 def to_h = @data |