Class: Xmvc::Update::Updater

Inherits:
Object
  • Object
show all
Defined in:
lib/xmvc/update.rb

Instance Method Summary collapse

Constructor Details

#initializeUpdater

Returns a new instance of Updater.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/xmvc/update.rb', line 10

def initialize
  [:build, :generate, :info, :setup, :stats].each do |script|
    self.send("ensure_#{script}")
  end

  # Updates from 0.6a1 to 0.6b1... this is a bit shit :(
  changes      = [
    {:old => 'ExtMVC.Model',          :new => 'ExtMVC.model'},
    {:old => 'ExtMVC.Controller',     :new => 'ExtMVC.controller.Controller'},
    {:old => 'ExtMVC.CrudController', :new => 'ExtMVC.controller.CrudController'},
    {:old => 'ExtMVC.Route',          :new => 'ExtMVC.router.Route'},
    {:old => 'ExtMVC.Router',         :new => 'ExtMVC.router.Router'}
  ]

  changes.each do |pair|
    system("find ./app/**/*.js | xargs perl -wi -pe 's/#{pair[:old]}/#{pair[:new]}/g'")
    system("find ./config/*js | xargs perl -wi -pe 's/#{pair[:old]}/#{pair[:new]}/g'")
  end
  # End updates from 0.6a1 to 0.6b... it's still shit
end

Instance Method Details

#delete_file(filename) ⇒ Object



55
56
57
58
# File 'lib/xmvc/update.rb', line 55

def delete_file filename
  File.delete()
rescue
end

#ensure_buildObject



31
32
33
# File 'lib/xmvc/update.rb', line 31

def ensure_build
  install_file('build', 'ExtMVC::Builder.dispatch')
end

#ensure_generateObject



35
36
37
# File 'lib/xmvc/update.rb', line 35

def ensure_generate
  install_file('generate', 'ExtMVC::Generator.dispatch')        
end

#ensure_infoObject



39
40
41
# File 'lib/xmvc/update.rb', line 39

def ensure_info
  install_file('info', 'ExtMVC.show_settings')
end

#ensure_setupObject



43
44
45
# File 'lib/xmvc/update.rb', line 43

def ensure_setup
  install_file('setup', 'ExtMVC.setup(ARGV.shift)')
end

#ensure_statsObject



47
48
49
# File 'lib/xmvc/update.rb', line 47

def ensure_stats
  install_file('stats', 'ExtMVC::Stats.dispatch')
end

#ensure_updateObject



51
52
53
# File 'lib/xmvc/update.rb', line 51

def ensure_update
  install_file('update', 'ExtMVC::Update.dispatch')
end

#install_file(filename, contents) ⇒ Object



60
61
62
63
64
65
66
67
68
# File 'lib/xmvc/update.rb', line 60

def install_file filename, contents
  filename = "script/#{filename}"

  delete_file filename
  str = "require 'vendor/mvc/scripts/scripts'\n\n" + contents

  FileUtils.touch(filename)
  File.open(filename, "w") {|f| f.puts str}
end