Module: SuprailsHelper

Included in:
Runner
Defined in:
lib/suprails_helper.rb

Instance Method Summary collapse

Instance Method Details

#debug(p = '') ⇒ Object



14
15
16
# File 'lib/suprails_helper.rb', line 14

def debug p = ''
  puts "debug: #{p}"
end

#delete(file_name) ⇒ Object



47
48
49
50
51
# File 'lib/suprails_helper.rb', line 47

def delete file_name
  file_name = "#{Runner.base}/#{file_name}"
  puts "Deleting: #{file_name}"
  File.delete file_name if File.exists?(file_name)
end

#file(source_file, destination, absolute = false) ⇒ Object



36
37
38
39
40
41
42
43
44
45
# File 'lib/suprails_helper.rb', line 36

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

#folder(folder_name) ⇒ Object



26
27
28
29
30
31
32
33
34
# File 'lib/suprails_helper.rb', line 26

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

#frozen_railsObject



10
11
12
# File 'lib/suprails_helper.rb', line 10

def frozen_rails
  shell "rails #{Runner.app_name} --freeze"
end

#generate(generator, *opts) ⇒ Object



22
23
24
# File 'lib/suprails_helper.rb', line 22

def generate generator, *opts
  runinside("script/generate #{generator} #{opts.join(' ')}")
end

#gitObject



76
77
78
# File 'lib/suprails_helper.rb', line 76

def git
  runinside('git init')
end

#gplObject



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/suprails_helper.rb', line 53

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

#new_file(filename, contents) ⇒ Object



92
93
94
95
96
97
# File 'lib/suprails_helper.rb', line 92

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

#plugin(plugin_location) ⇒ Object



18
19
20
# File 'lib/suprails_helper.rb', line 18

def plugin plugin_location
  runinside("script/plugin install #{plugin_location}")
end

#railsObject



6
7
8
# File 'lib/suprails_helper.rb', line 6

def rails
  shell "rails #{Runner.app_name}"
end

#rake(*opts) ⇒ Object



72
73
74
# File 'lib/suprails_helper.rb', line 72

def rake *opts
  runinside("rake #{opts.join(' ')}")
end

#runinside(*opts) ⇒ Object



84
85
86
# File 'lib/suprails_helper.rb', line 84

def runinside *opts
  shell "cd #{Runner.app_name}; #{opts.join(' ')}"
end

#saveObject



88
89
90
# File 'lib/suprails_helper.rb', line 88

def save
  file Runner.runfile, "doc/suprails.config", true
end

#svnObject



80
81
82
# File 'lib/suprails_helper.rb', line 80

def svn
  runinside('svnadmin create')
end