Class: Reactive::Updater::Cli

Inherits:
Base show all
Defined in:
lib/reactive-core/updater/cli.rb

Instance Method Summary collapse

Methods inherited from Base

#current_version, #last_available_version, #update_available?

Constructor Details

#initialize(args = []) ⇒ Cli

Returns a new instance of Cli.



7
8
9
# File 'lib/reactive-core/updater/cli.rb', line 7

def initialize(args = [])
  args.include?('--check') ? check_update : update
end

Instance Method Details

#ask(question, replies) ⇒ Object



42
43
44
45
46
47
48
49
# File 'lib/reactive-core/updater/cli.rb', line 42

def ask(question, replies)
  begin
    print question + " (#{replies}) ?"
    reply = gets.chomp.downcase
    reply = replies[/[A-Z]/] || '?' if reply.empty?
  end until replies.downcase.include? reply.downcase
  reply
end

#check_updateObject



11
12
13
14
15
16
17
# File 'lib/reactive-core/updater/cli.rb', line 11

def check_update
  if update_available?
    puts "There's a new version available: #{} (Current version: #{}"
  else
    puts "No new version available (Current version: #{})"
  end
end

#gem_sourceObject



38
39
40
# File 'lib/reactive-core/updater/cli.rb', line 38

def gem_source
  "http://localhost:8808"
end

#updateObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/reactive-core/updater/cli.rb', line 19

def update
  if update_available?
    puts `gem install #{APP_NAME} -i "#{APP_PATH}" --ignore-dependencies`
    exec(File.join(APP_PATH, '__FILE__'))         # WARNING: TODO: How about windows? should we add .cmd suffix?
  end

  puts Reactive::GemDependency.report_gems_state

  Reactive::GemDependency.missing_gems.each do |gem|
  #  gem.source = gem_source
    case ask "#{gem.name} #{gem.requirement.to_s}: Install, embed or skip", "Ies"
      when "i"
        puts gem.install
      when "e"
        puts gem.embed
    end
  end
end