Class: Rays::Service::UpdateManager

Inherits:
Object
  • Object
show all
Defined in:
lib/rays/services/update_manager.rb

Instance Method Summary collapse

Constructor Details

#initialize(rays_content) ⇒ UpdateManager

Returns a new instance of UpdateManager.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/rays/services/update_manager.rb', line 28

def initialize(rays_content)
  @current_version = nil
  @rays_content = rays_content

  unless rays_content.nil?
    version_string = rays_content.properties['version']
    if !version_string.nil? and !version_string.strip.empty?
      @current_version = Gem::Version.create version_string
    end
  end

  if @current_version.nil?
    @current_version ||= Gem::Version.create '1.1.9'
    rays_content.properties['version'] = @current_version.to_s
    rays_content.write
  end

  @updaters = Hash.new
  @updaters[Gem::Version.create('1.2.0')] = 'update_1_2_0'
  @updaters[Gem::Version.create('1.2.1')] = 'update_1_2_1'
  @updaters[Gem::Version.create('1.2.2')] = 'update_1_2_2'
  @updaters[Gem::Version.create('1.2.3')] = 'update_1_2_3'
  @updaters[Gem::Version.create('1.2.4')] = 'update_1_2_4'
  @updaters[Gem::Version.create('1.2.5')] = 'update_1_2_5'
  @updaters[Gem::Version.create('1.2.6')] = 'update_1_2_6'
  @updaters[Gem::Version.create('1.2.7')] = 'update_1_2_7'
  @updaters[Gem::Version.create('1.2.8')] = 'update_1_2_8'
end

Instance Method Details

#checkObject



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/rays/services/update_manager.rb', line 57

def check
  if @current_version < @updaters.keys.max
    $log.error "Your project version is #{@current_version.to_s}.\nYour rays version is #{@updaters.keys.max.to_s}.\nPress 'Enter' to upgrade or 'ctrl+c' to abort."
    begin
      STDIN.gets.chomp
    rescue Interrupt
      exit
    end
    update
  elsif @current_version > @updaters.keys.max
    $log.error "Your project version #{@current_version.to_s} is higher than the rays one #{@updaters.keys.max}.\nIt is highly recommended to upgrade your rays ('<!gem update raystool!>') before continue.\nPress 'Enter' to continue or 'ctrl+c' to abort."
    begin
      STDIN.gets.chomp
    rescue Interrupt
      exit
    end
  end

end

#updateObject



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/rays/services/update_manager.rb', line 77

def update
  @updaters.keys.sort.each do |version|
    if @current_version < version
      $log.info "Updating project to version #{version.to_s}"
      begin
        self.send @updaters[version]
        sync_version version
      rescue => e
        $log.warn "Failed to update to version #{version.to_s}. Please report on http://github.com/dmitri-carpov/rays/issues"
        $log.error "\n\n#{e}.\nBacktrace:\r\n#{e.backtrace.join("\r\n")}"
        exit
      end
    end
  end
end