Sha256: b2c0bf569f87a4d1e042a7b990effeb9a1989426172a670069a9bdb941319d10

Contents?: true

Size: 1.81 KB

Versions: 14

Compression:

Stored size: 1.81 KB

Contents

require "timber/cli/file_helper"

module Timber
  class CLI
    class ConfigFile
      attr_reader :path, :file_helper

      def initialize(path, file_helper)
        @path = path
        @file_helper = file_helper
      end

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

      def exists?
        File.exists?(path)
      end

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

      def silence_template_renders!
        append!("config.integrations.action_view.silence = Rails.env.production?")
      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

14 entries across 14 versions & 1 rubygems

Version Path
timber-2.4.0 lib/timber/cli/config_file.rb
timber-2.3.4 lib/timber/cli/config_file.rb
timber-2.3.3 lib/timber/cli/config_file.rb
timber-2.3.2 lib/timber/cli/config_file.rb
timber-2.3.1 lib/timber/cli/config_file.rb
timber-2.3.0 lib/timber/cli/config_file.rb
timber-2.2.3 lib/timber/cli/config_file.rb
timber-2.2.2 lib/timber/cli/config_file.rb
timber-2.2.1 lib/timber/cli/config_file.rb
timber-2.2.0 lib/timber/cli/config_file.rb
timber-2.1.10 lib/timber/cli/config_file.rb
timber-2.1.9 lib/timber/cli/config_file.rb
timber-2.1.8 lib/timber/cli/config_file.rb
timber-2.1.7 lib/timber/cli/config_file.rb