Class: Jets::Gems::Agree

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

Instance Method Summary collapse

Constructor Details

#initializeAgree

Returns a new instance of Agree.



3
4
5
# File 'lib/jets/gems/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.



48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/jets/gems/agree.rb', line 48

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



73
74
75
# File 'lib/jets/gems/agree.rb', line 73

def no!
  write_file("no")
end

#no?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/jets/gems/agree.rb', line 65

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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/jets/gems/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
    Jets uses pre-built binary gems from the serverlessgems.com service to
    provide a user-friendly developer experience. The Serverless Gems Service
    rate limits free gem download requests daily. You can upgrade to a paid plan
    for unlimited gem download requests. Open Source projects may also qualify
    for a free unlimited plan. More info:

      https://www.serverlessgems.com/rate-limits

    If you do not want to use Serverless Gems, you can disable the Serverless
    Gems service and provide your own custom Lambda Layer. More info:

      https://rubyonjets.com/docs/serverlessgems/
      https://rubyonjets.com/docs/extras/custom-lambda-layers/

    Also, reporting gems to Serverless Gems allows it to build new gems typically
    within a few minutes. So if you run into missing gems, you can try deploying
    again after a few minutes. Non-reported gems may take several days or longer.
    Serverless Gems only collects the info it needs to run the service.
    More info: https://www.serverlessgems.com/privacy
    This message will only appear once on this machine.

    You can also automatically skip this message by setting:
    JETS_AGREE=yes or JETS_AGREE=no

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

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

  write_file(value)
end

#write_file(content) ⇒ Object



77
78
79
80
# File 'lib/jets/gems/agree.rb', line 77

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

#yes!Object



69
70
71
# File 'lib/jets/gems/agree.rb', line 69

def yes!
  write_file("yes")
end

#yes?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/jets/gems/agree.rb', line 61

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