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.



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/jets/gems/agree.rb', line 30

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



55
56
57
# File 'lib/jets/gems/agree.rb', line 55

def no!
  write_file("no")
end

#no?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/jets/gems/agree.rb', line 47

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
# File 'lib/jets/gems/agree.rb', line 8

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.

    Reporting gems generally allows Lambdagems to build new gems within 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.

    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

#write_file(content) ⇒ Object



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

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

#yes!Object



51
52
53
# File 'lib/jets/gems/agree.rb', line 51

def yes!
  write_file("yes")
end

#yes?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/jets/gems/agree.rb', line 43

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