Class: Jets::Commands::Upgrade::V1
- Inherits:
-
Object
- Object
- Jets::Commands::Upgrade::V1
- Defined in:
- lib/jets/commands/upgrade/v1.rb
Instance Method Summary collapse
- #environment_configs ⇒ Object
-
#initialize(options) ⇒ V1
constructor
A new instance of V1.
- #run ⇒ Object
- #update_mode_setting ⇒ Object
- #update_routes ⇒ Object
Constructor Details
#initialize(options) ⇒ V1
Returns a new instance of V1.
5 6 7 |
# File 'lib/jets/commands/upgrade/v1.rb', line 5 def initialize() @options = end |
Instance Method Details
#environment_configs ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/jets/commands/upgrade/v1.rb', line 17 def environment_configs path = File.("../templates/skeleton/config/environments", File.dirname(__FILE__)) Dir.glob("#{path}/*").each do |src| config_file = "config/environments/#{File.basename(src)}" dest = "#{Jets.root}#{config_file}" unless File.exist?(dest) puts "Create: #{config_file}" FileUtils.mkdir_p(File.dirname(dest)) FileUtils.cp(src, dest) end end end |
#run ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/jets/commands/upgrade/v1.rb', line 9 def run puts "Upgrading to Jets v1..." environment_configs update_routes update_mode_setting puts "Upgrade complete." end |
#update_mode_setting ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/jets/commands/upgrade/v1.rb', line 51 def update_mode_setting application_file = "#{Jets.root}config/application.rb" lines = IO.readlines(application_file) deprecated_code = 'config.api_generator' return unless lines.detect { |l| l.include?(deprecated_code) } puts "Update: config/application.rb" lines.map! do |line| if line.include?(deprecated_code) mode = Jets.config.api_generator ? 'api' : 'html' %Q| config.mode = "#{mode}"\n| # assume 2 spaces for simplicity else line end end content = lines.join IO.write(application_file, content) end |
#update_routes ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/jets/commands/upgrade/v1.rb', line 30 def update_routes routes_file = "#{Jets.root}config/routes.rb" return unless File.exist?(routes_file) lines = IO.readlines(routes_file) deprecated_code = 'root "jets/welcome#index"' return unless lines.detect { |l| l.include?(deprecated_code) } puts "Update: config/routes.rb" lines.map! do |line| if line.include?(deprecated_code) %Q| root "jets/public#show"\n| # assume 2 spaces for simplicity else line end end content = lines.join IO.write(routes_file, content) end |