Sha256: 9b9a5037ef34c8f9bacf78823a2e7ae94466e23966520a35de7669099aa16769

Contents?: true

Size: 1.4 KB

Versions: 31

Compression:

Stored size: 1.4 KB

Contents

module Jets::Gems
  class Agree
    def initialize
      @agree_file = "#{ENV['HOME']}/.jets/agree"
    end

    # Only prompts if hasnt prompted before and saved a ~/.jets/agree file
    def prompt
      return if bypass_prompt
      return if File.exist?(@agree_file)

      puts <<~EOL
        Jets sends data about your gems to your specified lambda build service **lambdagems.com** so that it can compile and generate the necessary Lambda layers.  Lambdagems only collects anonymous non-identifiable data.

        Is it okay to send your gem data to Lambdagems? (Y/n)?
      EOL

      answer = $stdin.gets.strip
      value = answer =~ /y/i ? 'yes' : 'no'

      write_file(value)
    end

    # Allow user to bypass prompt with JETS_AGREE=1 JETS_AGREE=yes etc
    # Useful for CI/CD pipelines.
    def bypass_prompt
      agree = ENV['JETS_AGREE']
      return false unless agree

      if %w[1 yes true].include?(agree.downcase)
        write_file('yes')
      else
        write_file('no')
      end

      true
    end

    def yes?
      File.exist?(@agree_file) && IO.read(@agree_file).strip == 'yes'
    end

    def no?
      File.exist?(@agree_file) && IO.read(@agree_file).strip == 'no'
    end

    def yes!
      write_file("yes")
    end

    def no!
      write_file("no")
    end

    def write_file(content)
      FileUtils.mkdir_p(File.dirname(@agree_file))
      IO.write(@agree_file, content)
    end
  end
end

Version data entries

31 entries across 31 versions & 2 rubygems

Version Path
jets-gems-0.2.0 lib/jets/gems/agree.rb
jets-gems-0.1.0 lib/jets/gems/agree.rb
jets-1.9.7 vendor/jets-gems/lib/jets/gems/agree.rb
jets-1.9.6 vendor/jets-gems/lib/jets/gems/agree.rb
jets-1.9.5 vendor/jets-gems/lib/jets/gems/agree.rb
jets-1.9.4 vendor/jets-gems/lib/jets/gems/agree.rb
jets-1.9.3 vendor/jets-gems/lib/jets/gems/agree.rb
jets-1.9.2 vendor/jets-gems/lib/jets/gems/agree.rb
jets-1.9.1 vendor/jets-gems/lib/jets/gems/agree.rb
jets-1.9.0 vendor/jets-gems/lib/jets/gems/agree.rb
jets-1.8.14 vendor/jets-gems/lib/jets/gems/agree.rb
jets-1.8.13 vendor/jets-gems/lib/jets/gems/agree.rb
jets-1.8.12 vendor/jets-gems/lib/jets/gems/agree.rb
jets-1.8.11 vendor/jets-gems/lib/jets/gems/agree.rb
jets-1.8.10 vendor/jets-gems/lib/jets/gems/agree.rb
jets-1.8.9 vendor/jets-gems/lib/jets/gems/agree.rb
jets-1.8.8 vendor/jets-gems/lib/jets/gems/agree.rb
jets-1.8.7 vendor/jets-gems/lib/jets/gems/agree.rb
jets-1.8.6 vendor/jets-gems/lib/jets/gems/agree.rb
jets-1.8.5 vendor/jets-gems/lib/jets/gems/agree.rb