rails-app-installer 0.1.5 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -5,21 +5,20 @@ This installer was originally part of Typo (http://typosphere.org).
5
5
 
6
6
  = Adding the installer to your Rails app
7
7
 
8
- To add the installer to your application, copy the `installer` file from the
9
- examples directory into your project's `bin` directory, and rename it to match
10
- your application name. For example, Typo's installer lives in `bin/typo`. Then
11
- modify your installer as needed, customizing the application name, support
12
- address, and required Rails version. Once this is complete, create an
13
- `installer` directory for your app and copy
14
- `examples/rails_installer_defaults.yml` into it. You can probably use it
15
- unchanged.
8
+ To add the installer to your application, cd to your application's directory
9
+ and run 'rails-app-installer-setup APPNAME'. This will create several files,
10
+ including 'bin/APPNAME' and 'lib/tasks/release.rake'. Edit these files to make
11
+ sure that they're appropriate for your application and then add them to your
12
+ revision control system.
16
13
 
17
14
  You should now be able to test the installer like this:
18
15
 
19
16
  $ ruby ./bin/my_installer install /tmp/foo cwd
20
17
 
21
18
  This will try to install your app in `/tmp/foo` using the current directory as
22
- a template. If you leave off the `cwd` option at the end, then the installer will look for the most recent Ruby GEM for your app, using the `application_name` line from the installer as the gem name.
19
+ a template. If you leave off the `cwd` option at the end, then the installer
20
+ will look for the most recent Ruby GEM for your app, using the
21
+ `application_name` line from the installer as the gem name.
23
22
 
24
23
  = Creating a Gem
25
24
 
@@ -0,0 +1,71 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'rails-installer'
5
+
6
+ def usage
7
+ STDERR.puts "Usage:"
8
+ STDERR.puts " rails-app-installer-setup APPNAME"
9
+ STDERR.puts ""
10
+ STDERR.puts " APPNAME is the name of your application; it should be"
11
+ STDERR.puts " both the .gem name and the name of your installer."
12
+ STDERR.puts ""
13
+ STDERR.puts " Please run this command form the root of your Rails project."
14
+ end
15
+
16
+
17
+ # $ rails-app-installer-setup APPNAME
18
+
19
+ appname = ARGV[0]
20
+
21
+ unless appname and appname =~ /^[a-z][-_a-z0-9]+$/
22
+ usage
23
+ exit(1)
24
+ end
25
+
26
+ installer = RailsInstaller.new('.')
27
+
28
+ # Check for Rails in cwd
29
+ unless installer.is_valid_rails_directory?
30
+ STDERR.puts "Please run this command from the root of a valid Rails project"
31
+ exit(1)
32
+ end
33
+
34
+ # Find GEM
35
+
36
+ gem_directory = installer.find_source_directory 'rails-app-installer'
37
+
38
+ # Copy files from GEM IFF they don't already exist.
39
+
40
+ files_to_copy = {
41
+ 'examples/installer' => "bin/#{appname}",
42
+ 'examples/rails_installer_defaults.yml' => 'installer/rails_installer_defaults.yml',
43
+ 'examples/apache13.conf.example.template' => 'installer/apache13.conf.example.template',
44
+ 'examples/apache20.conf.example.template' => 'installer/apache20.conf.example.template',
45
+ 'examples/lighttpd.conf.example.template' => 'installer/lighttpd.conf.example.template',
46
+ 'examples/release.rake' => 'lib/tasks/release.rake'
47
+ }
48
+
49
+ files_to_copy.each do |from, to|
50
+ next if File.exists? to
51
+ puts " creating #{to}"
52
+ FileUtils.mkdir_p File.dirname(to) rescue nil
53
+ contents = File.read File.join(gem_directory,from)
54
+
55
+ File.open(to,'w') do |out|
56
+ out.write contents.gsub(/\$APPNAME/,appname)
57
+ end
58
+
59
+ if to=~/^bin/
60
+ File.chmod(0755,to)
61
+ end
62
+ end
63
+
64
+ puts "Successfully created an installer for your application."
65
+ puts
66
+ puts "Your next steps:"
67
+ puts " 1. Verify bin/#{appname} and lib/tasks/release.rake to make sure that they're"
68
+ puts " correct. Remove all 'FIXME's."
69
+ puts " 2. Create db/schema.*.sql files by installing the schema_generator gem and"
70
+ puts " running './script/generate schema'"
71
+ puts " 3. Run 'rake repackage' and verify that the generated .gem is correct."
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'rails-installer'
5
+
6
+ installer = RailsInstaller.new('.')
7
+
8
+ unless installer.is_valid_rails_directory?
9
+ STDERR.puts "Please run this command from the root of a valid Rails project"
10
+ exit(1)
11
+ end
12
+
13
+ installer.backup_database
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'rails-installer'
5
+
6
+ installer = RailsInstaller.new('.')
7
+
8
+ unless installer.is_valid_rails_directory?
9
+ STDERR.puts "Please run this command from the root of a valid Rails project"
10
+ exit(1)
11
+ end
12
+
13
+ restore_file = ARGV[0]
14
+
15
+ unless restore_file and File.exists?(restore_file) and restore_file =~ /\.yml$/
16
+ puts "Usage:"
17
+ puts " rails-restore FILENAME"
18
+ puts ""
19
+ puts " Restores the database contents from FILENAME into the database defined"
20
+ puts " in 'config/database.yml'. FILENAME should be generated by the "
21
+ puts " 'rails-backup' command."
22
+ end
23
+
24
+ installer.restore_database restore_file
@@ -4,9 +4,8 @@ require 'rubygems'
4
4
  require 'rails-installer'
5
5
 
6
6
  class AppInstaller < RailsInstaller
7
- application_name 'my_shiny_metal_app'
8
- support_location 'our shiny website'
9
- rails_version '1.1.6'
7
+ application_name '$APPNAME'
8
+ support_location 'the $APPNAME website'
10
9
  end
11
10
 
12
11
  directory = ARGV[1]
@@ -0,0 +1,39 @@
1
+ require 'rake/gempackagetask'
2
+
3
+ PKG_VERSION = "1.0.0"
4
+ PKG_NAME = "$APPNAME"
5
+ PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
6
+
7
+ spec = Gem::Specification.new do |s|
8
+ s.name = PKG_NAME
9
+ s.version = PKG_VERSION
10
+ s.summary = "FIXME"
11
+ s.description = "FIXME"
12
+ s.has_rdoc = false
13
+
14
+ s.files = Dir.glob('**/*', File::FNM_DOTMATCH).reject do |f|
15
+ [ /\.$/, /config\/database.yml$/, /config\/database.yml-/,
16
+ /database\.sqlite/,
17
+ /\.log$/, /^pkg/, /\.svn/, /^vendor\/rails/, /\~$/,
18
+ /\/\._/, /\/#/ ].any? {|regex| f =~ regex }
19
+ end
20
+ s.require_path = '.'
21
+ s.author = "FIXME"
22
+ s.email = "FIXME@example.com"
23
+ s.homepage = "http://www.FIXME.com"
24
+ s.rubyforge_project = "FIXME"
25
+ s.platform = Gem::Platform::RUBY
26
+ s.executables = ['$APPNAME']
27
+
28
+ s.add_dependency("rails", "= 1.1.6")
29
+ s.add_dependency("mongrel", ">= 0.3.13.3")
30
+ s.add_dependency("mongrel_cluster", ">= 0.2.0")
31
+ s.add_dependency("sqlite3-ruby", ">= 1.1.0")
32
+ s.add_dependency("rails-app-installer", ">= 0.1.0")
33
+ end
34
+
35
+ Rake::GemPackageTask.new(spec) do |p|
36
+ p.gem_spec = spec
37
+ p.need_tar = false
38
+ p.need_zip = false
39
+ end
@@ -367,15 +367,32 @@ class RailsInstaller
367
367
  [added, changed, deleted, same]
368
368
  end
369
369
 
370
+ # Decide which Rails version to freeze
371
+ def rails_version_to_freeze
372
+ if @@rails_version
373
+ return "= #{@@rails_version}"
374
+ else
375
+ specs = Gem.source_index.find_name(app_name,["= #{@install_version}"])
376
+ unless specs.to_a.size > 0
377
+ raise InstallFailed, "Can't locate version #{@install_version.first}!"
378
+ end
379
+
380
+ rails_dep = specs.first.dependencies.detect {|a| a.name=='rails'}
381
+ version = rails_dep.version_requirements.to_s
382
+ return version
383
+ end
384
+ end
385
+
370
386
  # Freeze to a specific version of Rails gems.
371
387
  def freeze_rails
372
- return unless @@rails_version
388
+ new_version = rails_version_to_freeze
389
+
373
390
  version_file = File.join(install_directory,'vendor','rails-version')
374
391
  vendor_rails = File.join(install_directory,'vendor','rails')
375
392
 
376
393
  old_version = File.read(version_file).chomp rescue nil
377
394
 
378
- if @@rails_version == old_version
395
+ if new_version == old_version
379
396
  return
380
397
  elsif old_version != nil
381
398
  rm_rf(vendor_rails)
@@ -392,10 +409,10 @@ class RailsInstaller
392
409
  'activesupport' => File.join(vendor_rails,'activesupport'),
393
410
  }
394
411
 
395
- specs = Gem.source_index.find_name('rails',["= #{@@rails_version}"])
412
+ specs = Gem.source_index.find_name('rails',[new_version])
396
413
 
397
414
  unless specs.to_a.size > 0
398
- raise InstallFailed, "Can't locate Rails #{@@rails_version}!"
415
+ raise InstallFailed, "Can't locate Rails #{new_version}!"
399
416
  end
400
417
 
401
418
  copy_gem(specs.first, package_map[specs.first.name])
@@ -566,7 +583,7 @@ class RailsInstaller
566
583
  end
567
584
 
568
585
  # Locate the source directory for a specific Version
569
- def find_source_directory(gem_name, version)
586
+ def find_source_directory(gem_name, version=nil)
570
587
  if version == 'cwd'
571
588
  return Dir.pwd
572
589
  elsif version
@@ -580,6 +597,9 @@ class RailsInstaller
580
597
  raise InstallFailed, "Can't locate version #{version}!"
581
598
  end
582
599
 
600
+ @install_version = specs.last.version
601
+ message "Installing #{app_name} #{@install_version}"
602
+
583
603
  specs.last.full_gem_path
584
604
  end
585
605
 
@@ -644,6 +664,19 @@ class RailsInstaller
644
664
  STDERR.puts " #{help}"
645
665
  end
646
666
  end
667
+
668
+ def is_valid_rails_directory?
669
+ valid = false
670
+ in_directory install_directory do
671
+ valid = File.exists?('config/database.yml') and
672
+ File.directory?('app') and
673
+ File.directory?('app/models') and
674
+ File.directory?('vendor')
675
+ end
676
+
677
+ valid
678
+ end
679
+
647
680
  end
648
681
 
649
682
  # Run a block inside of a specific directory. Chdir into the directory
@@ -15,8 +15,10 @@ class RailsInstaller
15
15
  database_yml = File.read File.join(installer.install_directory, 'config', 'database.yml') rescue nil
16
16
  database_yml ||= yml(installer)
17
17
 
18
+ environment = ENV['RAILS_ENV'] || 'development' # Mirror Rails' default.
19
+
18
20
  ActiveRecord::Base.establish_connection(
19
- YAML.load(database_yml)['production'])
21
+ YAML.load(database_yml)[environment])
20
22
  begin
21
23
  tables = ActiveRecord::Base.connection.tables
22
24
  if tables.size > 0
metadata CHANGED
@@ -1,84 +1,93 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.8.10
2
+ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: rails-app-installer
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.1.5
7
- date: 2006-08-12
6
+ version: 0.2.0
7
+ date: 2006-08-15 00:00:00 -07:00
8
8
  summary: An installer for Rails apps
9
9
  require_paths:
10
- - lib
10
+ - lib
11
11
  email: scott@sigkill.org
12
12
  homepage: http://scottstuff.net
13
13
  rubyforge_project:
14
- description: ''
14
+ description: ""
15
15
  autorequire: rails-installer
16
16
  default_executable:
17
17
  bindir: bin
18
18
  has_rdoc: true
19
19
  required_ruby_version: !ruby/object:Gem::Version::Requirement
20
20
  requirements:
21
- -
22
- - ">"
23
- - !ruby/object:Gem::Version
24
- version: 0.0.0
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
25
24
  version:
26
25
  platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ post_install_message:
27
29
  authors:
28
- - Scott Laird
30
+ - Scott Laird
29
31
  files:
30
- - lib/apache13.conf.example.template
31
- - lib/apache20.conf.example.template
32
- - lib/lighttpd.conf.example.template
33
- - lib/rails-installer
34
- - lib/rails-installer.rb
35
- - examples/installer
36
- - examples/rails_installer_defaults.yml
37
- - examples/typo
38
- - README
39
- - lib/rails-installer/commands.rb
40
- - lib/rails-installer/databases.rb
41
- - lib/rails-installer/web-servers.rb
32
+ - bin/rails-app-installer-setup
33
+ - bin/rails-backup
34
+ - bin/rails-restore
35
+ - lib/rails-installer
36
+ - lib/rails-installer.rb
37
+ - examples/apache13.conf.example.template
38
+ - examples/apache20.conf.example.template
39
+ - examples/installer
40
+ - examples/lighttpd.conf.example.template
41
+ - examples/rails_installer_defaults.yml
42
+ - examples/release.rake
43
+ - examples/typo
44
+ - README
45
+ - lib/rails-installer/commands.rb
46
+ - lib/rails-installer/databases.rb
47
+ - lib/rails-installer/web-servers.rb
42
48
  test_files: []
49
+
43
50
  rdoc_options:
44
- - "--main"
45
- - RailsInstaller
51
+ - --main
52
+ - RailsInstaller
46
53
  extra_rdoc_files:
47
- - README
48
- - lib/rails-installer/commands.rb
49
- - lib/rails-installer/databases.rb
50
- - lib/rails-installer/web-servers.rb
51
- executables: []
54
+ - README
55
+ - lib/rails-installer/commands.rb
56
+ - lib/rails-installer/databases.rb
57
+ - lib/rails-installer/web-servers.rb
58
+ executables:
59
+ - rails-app-installer-setup
60
+ - rails-backup
61
+ - rails-restore
52
62
  extensions: []
63
+
53
64
  requirements: []
65
+
54
66
  dependencies:
55
- - !ruby/object:Gem::Dependency
56
- name: mongrel
57
- version_requirement:
58
- version_requirements: !ruby/object:Gem::Version::Requirement
59
- requirements:
60
- -
61
- - ">="
62
- - !ruby/object:Gem::Version
63
- version: 0.3.13.3
64
- version:
65
- - !ruby/object:Gem::Dependency
66
- name: mongrel_cluster
67
- version_requirement:
68
- version_requirements: !ruby/object:Gem::Version::Requirement
69
- requirements:
70
- -
71
- - ">="
72
- - !ruby/object:Gem::Version
73
- version: 0.2.0
74
- version:
75
- - !ruby/object:Gem::Dependency
76
- name: sqlite3-ruby
77
- version_requirement:
78
- version_requirements: !ruby/object:Gem::Version::Requirement
79
- requirements:
80
- -
81
- - ">="
82
- - !ruby/object:Gem::Version
83
- version: 1.1.0
84
- version:
67
+ - !ruby/object:Gem::Dependency
68
+ name: mongrel
69
+ version_requirement:
70
+ version_requirements: !ruby/object:Gem::Version::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: 0.3.13.3
75
+ version:
76
+ - !ruby/object:Gem::Dependency
77
+ name: mongrel_cluster
78
+ version_requirement:
79
+ version_requirements: !ruby/object:Gem::Version::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: 0.2.0
84
+ version:
85
+ - !ruby/object:Gem::Dependency
86
+ name: sqlite3-ruby
87
+ version_requirement:
88
+ version_requirements: !ruby/object:Gem::Version::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: 1.1.0
93
+ version: