Module: Commissar::Config
- Defined in:
- lib/commissar.rb
Constant Summary collapse
- BUNDLED_DIR =
File.("../../conf", __FILE__)
Class Method Summary collapse
- .load(filename) ⇒ Object
- .load_complex_gems ⇒ Object
- .load_known_wallets ⇒ Object
- .load_weights ⇒ Object
- .resolve(filename) ⇒ Object
Class Method Details
.load(filename) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/commissar.rb', line 20 def self.load(filename) path = resolve(filename) return [] unless path File.readlines(path, chomp: true) .reject { |l| l.strip.empty? || l.strip.start_with?("#") } end |
.load_complex_gems ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/commissar.rb', line 40 def self.load_complex_gems path = resolve("complex_gems.txt") return {} unless path File.readlines(path, chomp: true) .reject { |l| l.strip.empty? || l.strip.start_with?("#") } .each_with_object({}) do |line, hash| name, category = line.split(":", 2) hash[name.strip] = category.strip if name && category end end |
.load_known_wallets ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/commissar.rb', line 52 def self.load_known_wallets path = resolve("known_bad_wallets.txt") return {} unless path File.readlines(path, chomp: true) .reject { |l| l.strip.empty? || l.strip.start_with?("#") } .each_with_object({}) do |line, hash| addr, label = line.split(":", 2) next unless addr && label hash[addr.strip] = label.strip end end |
.load_weights ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/commissar.rb', line 28 def self.load_weights path = resolve("severity.txt") return {} unless path File.readlines(path, chomp: true) .reject { |l| l.strip.empty? || l.strip.start_with?("#") } .each_with_object({}) do |line, hash| k, v = line.split(":", 2) hash[k.strip] = v.to_i if k && v end end |
.resolve(filename) ⇒ Object
65 66 67 68 69 70 71 |
# File 'lib/commissar.rb', line 65 def self.resolve(filename) candidates = [ File.join(Dir.pwd, "conf", filename), File.join(BUNDLED_DIR, filename) ] candidates.find { |p| File.exist?(p) } end |