Module: Rise::Util

Defined in:
lib/core/util.rb

Overview

Utility methods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.check_for_update! ⇒ Object

Check for a new version of the gem



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/core/util.rb', line 43

def self.check_for_update!
  src = Rise::Util.git_or_gem
  begin
    if src == 2  # if the gem was downloaded from rubygems
      current_version = JSON.parse(HTTP.get('https://rubygems.org/api/v1/versions/rise-cli/latest.json'))['version']
      if current_version != Rise::Constants::VERSION
        Whirly.start(
          spinner: 'line',
          status: "New version available (#{Paint[Rise::Constants::VERSION, 'red']} -> #{Paint[current_version, '#3498db']}), updating..."
        ) do
          system("gem uninstall rise-cli -v #{Rise::Constants::VERSION} > /dev/null")
          system("gem install rise-cli > /dev/null")
          puts Paint["Update complete, just run #{Paint['`rise`', '#3498db']} to deploy"]
        end
      end
    elsif src == 1
      if `git log HEAD..origin/master --oneline` != ''
        puts "It seems you're on bleeding edge, fetching new changes..."
        vputs("Updating from #{`git show --no-color --oneline -s`.split(' ')[0]} to #{`git rev-parse --short HEAD`}")
        `git pull`
        puts Paint["Update complete, just run #{Paint['`rise`', '#3498db']} to deploy"]
      end
    end
  rescue StandardError => e
    puts "Unable to check for updates. Error: #{Paint[e.message, 'red']}"
    exit 1
  end
end

.first_run? ⇒ Boolean

Checks if rise is being run for the first time

Returns:

  • (Boolean)


20
21
22
# File 'lib/core/util.rb', line 20

def self.first_run?
  !File.directory?(File.join(Dir.home, '.rise'))
end

.git_or_gem ⇒ Object

1 = git, 2 = gem, 3 = unknown



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/core/util.rb', line 27

def self.git_or_gem
  gem = nil
  1 if File.exist?(File.join(Rise::Constants::VERSION, '.git'))
  if OS.windows?
    gem = system('which gem > NUL')
  else
    gem = system('which gem > /dev/null')
  end

  2 if gem == true
  3
end

.open_deployment_in_browser(url) ⇒ Object

Opens url in a web browser if possible



101
102
103
104
105
106
107
# File 'lib/core/util.rb', line 101

def self.open_deployment_in_browser(url)
  if OS.windows?
    system("START \"\" \"#{url}\"")
  else
    system("open #{url}")
  end
end

.setup ⇒ Object

Creates all of the necessary files and login information



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/core/util.rb', line 75

def self.setup
  puts Paint['Detected first time setup, creating necessary files...', :blue]
  FileUtils.mkdir(RISE_DATA_DIR)
  FileUtils.mkdir(File.join(RISE_DATA_DIR, 'auth'))

  puts Paint['Create a password to secure your uploads.', :bold]
  pw = 
  while pw.length < 9
    puts Paint['Password not long enough,
      it has to be longer than 8 characters', :red]
      pw = 
  end
  File.open(File.join(RISE_DATA_DIR, 'auth', 'creds.json')) do |f|
    creds_hash = { 'hash' => BCrypt::Password.new(pw) }
    f.puts(JSON.pretty_generate(creds_hash))
  end
end

Instance Method Details

#signup ⇒ Object



93
94
95
96
# File 'lib/core/util.rb', line 93

def 
  print 'Password: '
  STDIN.noecho(&:gets)
end