Sha256: 22951c7dda9a62007bfa0eedb3f428fa02679322854512d87b8a8a99307a1cc5

Contents?: true

Size: 1.63 KB

Versions: 2

Compression:

Stored size: 1.63 KB

Contents

require "timber/cli/file_helper"

module Timber
  class CLI
    class ConfigFile
      attr_reader :path

      def initialize(path)
        @path = path
      end

      def create!
        FileHelper.write(path, content)
      end

      def exists?
        File.exists?(path)
      end

      def logrageify!
        append!("config.logrageify!")
      end

      private
        def append!(code)
          if !content.include?(code)
            content.gsub!(insert_hook, "#{code}\n\n#{insert_hook}")
          end

          true
        end

        def insert_hook
          @insert_hook ||= "# Add additional configuration here."
        end

        # We provide this as an instance method so that the string is only defined when needed.
        # This avoids allocating this string during normal app runtime.
        def content
          @content ||= <<-CONTENT
# Timber.io Ruby Configuration - Simple Structured Logging
#
#  ^  ^  ^   ^      ___I_      ^  ^   ^  ^  ^   ^  ^
# /|\\/|\\/|\\ /|\\    /\\-_--\\    /|\\/|\\ /|\\/|\\/|\\ /|\\/|\\
# /|\\/|\\/|\\ /|\\   /  \\_-__\\   /|\\/|\\ /|\\/|\\/|\\ /|\\/|\\
# /|\\/|\\/|\\ /|\\   |[]| [] |   /|\\/|\\ /|\\/|\\/|\\ /|\\/|\\
# -------------------------------------------------------------------
# Website:       https://timber.io
# Documentation: https://timber.io/docs
# Support:       support@timber.io
# -------------------------------------------------------------------

config = Timber::Config.instance

#{insert_hook}
# For a full list of configuration options and their explanations see:
# http://www.rubydoc.info/github/timberio/timber-ruby/Timber/Config

CONTENT
        end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
timber-2.1.0.rc5 lib/timber/cli/config_file.rb
timber-2.1.0.rc4 lib/timber/cli/config_file.rb