Class: Modulorails::SelfUpdateGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/modulorails/self_update/self_update_generator.rb

Overview

Author: Matthieu 'ciappa_m' Ciappara This updates modulorails by editing the gemfile and running a bundle update

Constant Summary collapse

LATEST_VERSION_URL =
'https://rubygems.org/api/v1/versions/modulorails/latest.json'

Instance Method Summary collapse

Instance Method Details

#create_config_fileObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/generators/modulorails/self_update/self_update_generator.rb', line 14

def create_config_file
  modulorails_version = Gem::Version.new(Modulorails::VERSION)

  # Get the last published version
  last_published_version_s = HTTParty.get(LATEST_VERSION_URL).parsed_response['version']
  last_published_version   = Gem::Version.new(last_published_version_s)

  # Do nothing if we could not fetch the last published version (whatever the reason)
  # Or if the current version is the same as the last published version
  return if last_published_version <= modulorails_version

  # Add gem to Gemfile
  gsub_file 'Gemfile', /^\s*gem\s['"]modulorails['"].*$/,
            "gem 'modulorails', '= #{last_published_version}'"

  # Update the gem and the Gemfile.lock
  system('bundle install')
rescue StandardError => e
  warn("[Modulorails] Error: cannot generate health_check configuration: #{e.message}")
end