Sha256: 042cfef57fae37fb0935dcd6cf574397e314d72224654bd524669bf0fe588f4d

Contents?: true

Size: 613 Bytes

Versions: 2

Compression:

Stored size: 613 Bytes

Contents

# frozen_string_literal: true

module Tocer
  # Default configuration for gem with support for custom settings.
  class Configuration
    attr_reader :file_path
    attr_writer :label

    def initialize file_path: File.join(ENV["HOME"], Identity.file_name)
      @file_path = file_path
      @settings = load_settings
    end

    def label
      @label ||= settings.fetch(:label, "# Table of Contents")
    end

    private

    attr_reader :settings

    def load_settings
      return {} unless File.exist?(file_path)
      yaml = YAML.load_file file_path
      yaml.is_a?(Hash) ? yaml : {}
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
tocer-2.2.0 lib/tocer/configuration.rb
tocer-2.1.0 lib/tocer/configuration.rb