Sha256: 26b616efe3b1f14fd737ac7ddd5e44d606082be56909ee6617032279d0a6abc6

Contents?: true

Size: 1.88 KB

Versions: 14

Compression:

Stored size: 1.88 KB

Contents

require "timber/cli/file_helper"
require "timber/cli/io/messages"

module Timber
  class CLI
    class Installer
      DEPRIORITIZED_PLATFORMS = ["linux", "other"].freeze

      attr_reader :io, :api, :file_helper

      def initialize(io, api)
        @io = io
        @api = api
        @file_helper = FileHelper.new(api)
      end

      def run(app)
        raise NotImplementedError.new
      end

      private
        def get_delivery_strategy(app)
          if DEPRIORITIZED_PLATFORMS.include?(app.platform_type)
            :http
          else
            :stdout
          end
        end

        # Determines the API key storage prference (environment variable or inline)
        def get_api_key_storage_preference
          io.puts ""
          io.puts IO::Messages.separator
          io.puts ""
          io.puts "For production/staging would you like to store your Timber API key"
          io.puts "in an environment variable? (TIMBER_API_KEY)"
          io.puts ""
          io.puts "y) Yes, store in TIMBER_API_KEY", :blue
          io.puts "n) No, just paste the API key inline", :blue
          io.puts ""

          case io.ask_yes_no("Enter your choice:", event_prompt: "Store API key in env?")
          when :yes
            io.puts ""
            io.puts IO::Messages.http_environment_variables(api.api_key)
            io.puts ""

            io.ask_to_proceed

            :environment
          when :no
            :inline
          end
        end

        # Based on the API key storage preference, we generate the proper code.
        def get_api_key_code(storage_type)
          case storage_type
          when :environment
            "ENV['TIMBER_API_KEY']"
          when :inline
            "'#{api.api_key}'"
          else
            raise ArgumentError.new("API key storage type not recognized! " \
              "#{storage_type.inspect}")
          end
        end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
timber-2.6.2 lib/timber/cli/installer.rb
timber-2.6.1 lib/timber/cli/installer.rb
timber-2.6.0 lib/timber/cli/installer.rb
timber-2.6.0.pre.beta2 lib/timber/cli/installer.rb
timber-2.6.0.pre.beta1 lib/timber/cli/installer.rb
timber-2.5.1 lib/timber/cli/installer.rb
timber-2.5.0 lib/timber/cli/installer.rb
timber-2.4.0 lib/timber/cli/installer.rb
timber-2.3.4 lib/timber/cli/installer.rb
timber-2.3.3 lib/timber/cli/installer.rb
timber-2.3.2 lib/timber/cli/installer.rb
timber-2.3.1 lib/timber/cli/installer.rb
timber-2.3.0 lib/timber/cli/installer.rb
timber-2.2.3 lib/timber/cli/installer.rb