public
Description: Substitute for the "rails" command that can pre-install any gems, init a git db, and/or freeze rails, etc on top of a rails application
Homepage: http://suprails.org
Clone URL: git://github.com/listrophy/suprails.git
angelic (author)
Sat Dec 20 14:07:47 -0800 2008
listrophy (committer)
Wed Dec 31 12:21:05 -0800 2008
suprails / lib / suprails_helper.rb
100644 105 lines (87 sloc) 2.363 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
require File.dirname(__FILE__) + '/insertion_helper'
require File.dirname(__FILE__) + '/db'
require File.dirname(__FILE__) + '/gems'
 
module SuprailsHelper
  def rails
    shell "rails #{Runner.app_name}"
  end
  
  def frozen_rails
    shell "rails #{Runner.app_name} --freeze"
  end
 
  def debug p = ''
    puts "debug: #{p}"
  end
 
  def plugin plugin_location
    runinside("script/plugin install #{plugin_location}")
  end
 
  def generate generator, *opts
    runinside("script/generate #{generator} #{opts.join(' ')}")
  end
 
  def folder folder_name
    path = "#{Runner.base}/"
    puts "New folder: #{Runner.base}"
    paths = folder_name.split('/')
    paths.each do |p|
      path += "#{p}/"
      Dir.mkdir path if !File.exists? path
    end
  end
 
  def file source_file, destination, absolute = false
    require 'ftools'
    if absolute
      source = File.expand_path "#{source_file}"
    else
      source = File.expand_path "#{@sources}/#{source_file}"
    end
    dest = File.expand_path "./#{Runner.app_name}/#{destination}"
    File.copy(source, dest, true) if File.exists? source
  end
 
  def delete file_name
    file_name = "#{Runner.base}/#{file_name}"
    puts "Deleting: #{file_name}"
    File.delete file_name if File.exists?(file_name)
  end
 
  def gpl
    puts 'Installing the GPL into COPYING'
    require 'net/http'
    http = Net::HTTP.new('www.gnu.org')
    path = '/licenses/gpl-3.0.txt'
    begin
      resp = http.get(path)
      if resp.code == '200'
        File.open("#{Runner.base}/COPYING", 'w') do |f|
          f.puts(resp.body)
        end
      else
        puts "Error #{resp.code} while retrieving GPL text."
      end
    rescue SocketError
      puts 'SocketError: You might not be connected to the internet. GPL retrieval failed.'
    end
  end
 
  def rake *opts
    runinside("rake #{opts.join(' ')}")
  end
 
  def git
    runinside('git init')
  end
 
  def svn
    runinside('svnadmin create')
  end
  
  def runinside *opts
    shell "cd #{Runner.app_name}; #{opts.join(' ')}"
  end
  
  def save
    file Runner.runfile, "doc/suprails.config", true
  end
  
  def new_file filename, contents
    File.open(File.expand_path("./#{Runner.app_name}/#{filename}"), 'w') do |f|
      f.puts contents
    end
    puts "Generating file: #{filename}"
  end
  
  private
  
  def shell cmd
    puts `#{cmd}`
  end
end