Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Rails3 compatibility #1

Open
wants to merge 5 commits into from

1 participant

This page is out of date. Refresh to see the latest.
Showing with 39 additions and 24 deletions.
  1. +9 −8 bin/garlic
  2. +30 −16 lib/garlic/target.rb
View
17 bin/garlic
@@ -1,7 +1,8 @@
#!/usr/bin/env ruby
+$LOAD_PATH.unshift File.join(File.dirname(__FILE__), "..", "lib")
+
require 'getoptlong'
-require 'rubygems'
require 'rake'
require 'garlic'
@@ -16,9 +17,9 @@ USAGE: garlic [options] [command]
COMMANDS:
#{Garlic::Session.commands_with_description.map{|method, desc| " %-17s %s" % [method, desc]}.join("\n")}
-
+
The default command is "default"
-
+
OPTIONS:
--help -h You're reading it
--verbose -v Show work
@@ -29,7 +30,7 @@ OPTIONS:
You can generate a sample garlic.rb with
garlic generate [TEMPLATE [PLUGIN_NAME]] (Available templates: #{available_templates.join(', ')})
-
+
end_doc
@verbose = false
@@ -60,19 +61,19 @@ begin
else
# run a garlic command
raise "Unknown command: #{ARGV.first}" unless ARGV.empty? || Garlic::Session.commands.include?(ARGV.first)
-
+
verbose(@verbose)
-
+
# configure the garlic runner
garlic(@config_file) # load up the garlic instance
garlic.verbose = @verbose
garlic.run_targets = @run_targets
-
+
# run the command
ARGV << 'default' if ARGV.empty?
garlic.send *ARGV
end
-
+
rescue Exception => e
STDERR << "\n#{USAGE}\n\nError: #{e.message}\n\n"
raise e if @backtrace
View
46 lib/garlic/target.rb
@@ -14,21 +14,21 @@ def initialize(garlic, options = {})
@prepare = options[:prepare]
@run = options[:run]
end
-
+
def prepare
puts "\nPreparing target #{name} (#{tree_ish})"
install_rails
runner.run(&@prepare) if @prepare
end
-
+
def run
runner.run(&@run) if @run
end
-
+
def rails_sha
read_sha('vendor/rails')
end
-
+
def shell
unless @shell
@shell = Shell.new
@@ -37,16 +37,16 @@ def shell
end
@shell
end
-
+
private
def runner
@runner ||= Target::Runner.new(self)
end
-
+
def read_sha(install_path)
File.read(File.join(path, install_path, '.git_sha')) rescue nil
end
-
+
def write_sha(install_path, sha)
File.open(File.join(path, install_path, '.git_sha'), 'w+') {|f| f << sha}
end
@@ -58,15 +58,29 @@ def install_rails
puts "Rails app for #{name} exists"
else
puts "Creating rails app for #{name}..."
- `ruby #{rails_repo.path}/railties/bin/rails #{path}`
+
+ if File.exists?(rails_bin = "#{rails_repo.path}/bin/rails")
+ `ruby #{rails_bin} new #{path}`
+
+ cd path do
+ `bundle install`
+ end
+ else
+ `ruby #{rails_repo.path}/railties/bin/rails #{path}`
+ end
+ end
+
+ install_dependency(rails_repo, 'vendor/rails') do
+ # remove secret token so that rails 3 installer doesn't freeze
+ `rm -rf config/initializers/secret_token.rb`
+ `rake rails:update`
end
- install_dependency(rails_repo, 'vendor/rails') { `rake rails:update` }
end
def install_dependency(repo, install_path = ".", options = {}, &block)
repo = garlic.repo(repo) unless repo.is_a?(Repo)
tree_ish = Repo.tree_ish(options)
-
+
if options[:clone]
if Repo.path?(install_path)
puts "#{install_path} exists, and is a repo"
@@ -76,10 +90,10 @@ def install_dependency(repo, install_path = ".", options = {}, &block)
repo.clone_to(File.join(path, install_path))
end
cd(install_path) { `git checkout #{tree_ish || repo.head_sha}` }
-
+
else
old_tree_ish = repo.head_sha
- repo.checkout(tree_ish) if tree_ish
+ repo.checkout(tree_ish) if tree_ish
if read_sha(install_path) == repo.head_sha
puts "#{install_path} is up to date at #{tree_ish || repo.head_sha[0..6]}"
else
@@ -91,21 +105,21 @@ def install_dependency(repo, install_path = ".", options = {}, &block)
repo.checkout(old_tree_ish) if tree_ish
end
end
-
-
+
+
class Runner
attr_reader :target
def initialize(target)
@target = target
end
-
+
def run(&block)
cd target.path do
instance_eval(&block)
end
end
-
+
def method_missing(method, *args, &block)
target.garlic.send(method, *args, &block)
end
Something went wrong with that request. Please try again.