Class: Calltally::Config
- Inherits:
-
Object
- Object
- Calltally::Config
- Defined in:
- lib/calltally/config.rb
Constant Summary collapse
- DEFAULTS =
{ "profile" => "auto", # auto|rails|default "dirs" => %w[.], "exclude" => %w[vendor node_modules tmp log .git .bundle], "top" => 100, "verbose" => false, "mode" => "pairs", # pairs|methods|receivers "receivers" => nil, # ["User","Group"] "methods" => nil, # ["where","find"] "include_nil_receiver" => false, "split_variables" => false, # Show variable names vs grouping "receiver_types" => nil, # ["locals", "ivars", "constants"] etc. "skip_operators" => true, "format" => "table", # table|json|csv "output" => nil, "plugins" => [] # Enable plugins (e.g., ["erb"]) }.freeze
- RAILS_DIR_PRESET =
%w[app lib config].freeze
Class Method Summary collapse
- .load(base_dir:, cli_opts:) ⇒ Object
- .resolve_profile(base_dir, desired) ⇒ Object
- .to_set_or_nil(v) ⇒ Object
Class Method Details
.load(base_dir:, cli_opts:) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/calltally/config.rb', line 28 def self.load(base_dir:, cli_opts:) config = DEFAULTS.dup path = File.join(base_dir, ".calltally.yml") if File.file?(path) yaml = YAML.load_file(path) || {} yaml.each { |k, v| config[k.to_s] = v } end cli_opts.compact.each { |k, v| config[k.to_s] = v } config["profile"] = resolve_profile(base_dir, config["profile"]) if config["profile"] == "rails" config["dirs"] = RAILS_DIR_PRESET if config["dirs"] == DEFAULTS["dirs"] end config["receivers"] = to_set_or_nil(config["receivers"]) config["methods"] = to_set_or_nil(config["methods"]&.map(&:to_s)) config end |
.resolve_profile(base_dir, desired) ⇒ Object
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/calltally/config.rb', line 50 def self.resolve_profile(base_dir, desired) return desired unless desired == "auto" gemfile_path = File.join(base_dir, "Gemfile") if File.file?(gemfile_path) && File.read(gemfile_path).match?(/^\s*gem\s+["']rails["']/) "rails" else "default" end end |
.to_set_or_nil(v) ⇒ Object
61 62 63 64 65 66 67 68 |
# File 'lib/calltally/config.rb', line 61 def self.to_set_or_nil(v) case v when nil then nil when Set then v when Array then Set.new(v) else Set.new([v]) end end |