Class: Jets::Api::Agree

Inherits:
Object
  • Object
show all
Defined in:
lib/jets/api/agree.rb

Instance Method Summary collapse

Constructor Details

#initializeAgree

Returns a new instance of Agree.



3
4
5
# File 'lib/jets/api/agree.rb', line 3

def initialize
  @agree_file = "#{ENV["HOME"]}/.jets/agree"
end

Instance Method Details

#bypass_promptObject

Allow user to bypass prompt with JETS_AGREE=1 JETS_AGREE=yes etc Useful for CI/CD pipelines.



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/jets/api/agree.rb', line 28

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

#no!Object



53
54
55
# File 'lib/jets/api/agree.rb', line 53

def no!
  write_file("no")
end

#no?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/jets/api/agree.rb', line 45

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

#promptObject

Only prompts if hasnt prompted before and saved a ~/.jets/agree file



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/jets/api/agree.rb', line 8

def prompt
  return if bypass_prompt
  return if File.exist?(@agree_file) && File.mtime(@agree_file) > Time.parse("2021-04-12")

  puts <<~EOL
    To use jets you must agree to the terms of service.

    Jets Terms: https://www.rubyonjets.com/terms

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

  answer = $stdin.gets.strip
  value = /y/i.match?(answer) ? "yes" : "no"

  write_file(value)
end

#write_file(content) ⇒ Object



57
58
59
60
# File 'lib/jets/api/agree.rb', line 57

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

#yes!Object



49
50
51
# File 'lib/jets/api/agree.rb', line 49

def yes!
  write_file("yes")
end

#yes?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/jets/api/agree.rb', line 41

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