class Ahnnotate::Config

Public Class Methods

default() click to toggle source
# File lib/ahnnotate/config.rb, line 16
def self.default
  @default ||= {
    "boot" => nil,
    "rake_db_autorun" => false,
    "annotate" => {
      "models" => {
        "enabled" => true,
        "path" => "app/models",
        "extension" => ".rb",
      },
    },
  }
end
effective_default() click to toggle source
# File lib/ahnnotate/config.rb, line 37
def self.effective_default
  if @effective_default
    return @effective_default
  end

  @effective_default ||= YAML.load(YAML.dump(default)) # deep dup

  if Gem.loaded_specs.key?("rails")
    @effective_default.merge!(rails_additions)
  end

  @effective_default
end
load(root:) click to toggle source
# File lib/ahnnotate/config.rb, line 5
def self.load(root:)
  config_path = root.join(".ahnnotate.yml")

  if !config_path.exist?
    return new({})
  end

  loaded_config = YAML.safe_load(File.read(config_path))
  new(loaded_config)
end
new(config) click to toggle source
# File lib/ahnnotate/config.rb, line 51
def initialize(config)
  @config =
    if config.is_a?(Hash)
      config
    else
      {}
    end
end
rails_additions() click to toggle source
# File lib/ahnnotate/config.rb, line 30
def self.rails_additions
  @rails_additions ||= {
    "boot" => %(require File.expand_path("config/environment").to_s),
    "rake_db_autorun" => true,
  }
end

Public Instance Methods

[](*args) click to toggle source
# File lib/ahnnotate/config.rb, line 60
def [](*args)
  specified_config = @config.dig(*args)

  if specified_config.nil?
    self.class.effective_default.dig(*args)
  else
    specified_config
  end
end